How do i use the for loop in perl?
-
Link: http://perldoc.perl.org/perlsyn.html#Compound-Statements
As in bash and other programming. The is a way of looping through a list, using, while, for, & foreach. for and foreach is the same thing.
#!/usr/bin/perl @stars = qw( hillary eva jennifer ); foreach $star (@stars) { $star = "\t$star"; $star .= "\n"; } print "The stars are:\n", @stars;
The qw provides a elements to the array @stars
Run the script.
$ ./myperl5 The stars are: hillary eva jennifer
© Lightnetics 2024