Does Perl support for i in list syntax -


i can following using bash:

for in 1 2 3 4     # operations on $i     print $i done 

can similar in perl without storing values in array?

you got lot of answers. perl best practices says not use $_ or foreach, , put { on same line for:

use strict; use warnings; use features qw(say);  $i (1, 2, 3, 4) {     "$i"; } 

however, same thing cleaner:

for $i ( qw(1 2 3 4) ) {     $i; } 

here i'm using qw produces list of words in parentheses. don't need commas or quotes:

for $i ( qw(apple baker charlie delta) ) {     $i; } 

as others pointed out, in particular example, have used:

for $i (1..4) {     "$i"; } 

but then, have done in bash or kornshell too:

for in {1..4}     echo $i   #in bash have use "echo". "print" kornshellism done 

Comments