while (<$fh>) {
next if 1 .. 1;
print "$_\n";
}
means
while (<$fh>) {
next if $.==1 .. $.==1;
print "$_\n";
}
so to do the same with a loop which counts over something other than $., you have specify it explicitly.
for (1,2,3,4,5) {
next if $_==1 .. $_==1;
print "$_\n";
}
what do they mean by "constant expression?"
Short: Anything that Perl converts to a constant at compile-time.
>perl -MO=Concise -e"print( 4 + 1 * 2 )"
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
5 <@> print vK ->6
3 <0> pushmark s ->4
4 <$> const[IV 6] s ->5 <--- 4+1*2
-e syntax OK
>perl -MO=Concise -e"print( 4 + $x * 2 )"
a <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
9 <@> print vK ->a
3 <0> pushmark s ->4
8 <2> add[t3] sK/2 ->9 \
4 <$> const[IV 4] s ->5 |
7 <2> multiply[t2] sK/2 ->8 | <--- 4+$x*2
- <1> ex-rv2sv sK/1 ->6 |
5 <#> gvsv[*x] s ->6 |
6 <$> const[IV 2] s ->7 /
Long: A constant expression is known to Perl to always return the same result. It includes constants (including those created by constant), most operators operating on constants, some builtin functions, and functions with the () prototype whose body consist entirely of a constant expression (as per Constant Functions in perlsub).
Given
sub PI() { 4 * atan2(1, 1) }
use constant SOMENUM => rand(4);
Example of constant expressions:
4
5+6*7
4 * atan2(1, 1)
PI
SOMENUM
|