Friday, February 4, 2011

PERL : For Loops

pico forloop1.pl
#!/usr/bin/perl -w
$min=2
$max=5
for($i=$min;$i<=$max;$i++)
{
print "$i\n";
}
for($min..$max) {print "$i\n";}
#END
perl -w forloop1.pl > file.txt
perl -w forloop1.pl | wc -l -> return the number of lines

#!/usr/bin/perl -w
@array1 = ("Mark","Linux","Script","Debian","RedHat");
foreach (@array1)
{
print "$_ \n"; #prints each elem of the array
}
$#array1+=1;
print "elem array = $#array1\n"
#END

No comments:

Post a Comment