Embperl Examples - Loop Metacommands


This is a example of using the while metacommand in embperl to show the environment

[$ while ($k, $v) = each (%ENV) $] [+ $k +] = [+ $v +]
[$ endwhile $]

This is a example of using the while metacommand to show the loaded modules, with using an index

[- $i = 0; @k = keys %INC -] [$ while ($i < $#k) $] [+ $k[$i] +] = [+ $INC{$k[$i]} +]
[- $i++ -] [$ endwhile $]

This is a example of using the do .. until metacommand to show the array @arr = (3,5,7)

[- @arr = (3, 5, 7); $i = 0 -] [$ do $] [+ $arr[ $i++ ] +] [$ until $i > $#arr $]

This is a example of using the foreach metacommand to show the list (1..10)

[$ foreach $v (1..10) $] [+ $v +] [$ endforeach $] [$ if $ENV{MOD_PERL} $]

This is a example of using the while metacommand in embperl to show the http headers send from the browser

[- %hdr = $req_rec -> headers_in ; -] [$ while ($k, $v) = each (%hdr) $] [+ $k +] = [+ $v +]
[$ endwhile $] [$endif$]


HTML::Embperl (c) 1997-1998 G.Richter