Well, no, I meant what I said. $. while reading a file is different from the zero-based array index. Here is your code now reading from __DATA__:
And the output is (hey - use strict found an error):#! /usr/bin/perl -w use strict; my @letters = qw(a b c d e); #'a'..'e' also works, #but I didn't want to add #a red herring ;-) print ' $_ | $r | $.'."\n"; for (@letters) { if(my $r = /a/../e/) { printf "%4s |%4s |%4s\n", $_, $r, $.; } $.++; # ok, this is silly # but I'm making a point ;-) } print "\n", ' $_ | $r | $.'."\n"; while (<DATA>) { chomp; if(my $r = /a/../e/) { printf "%4s |%4s |%4s\n", $_, $r, $.; } } __DATA__ a b c d e
$_ | $r | $. Use of uninitialized value in printf at ./r2.pl line 12. a | 1 | b | 2 | 1 c | 3 | 2 d | 4 | 3 e | 5E0 | 4 $_ | $r | $. a | 1 | 1 b | 2 | 2 c | 3 | 3 d | 4 | 4 e | 5E0 | 5
In reply to Re^3: State information for flipflop .. operator.
by pbeckingham
in thread State information for flipflop .. operator.
by rinceWind
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |