in reply to Re^3: State information for flipflop .. operator.
in thread State information for flipflop .. operator.
The error is from using warnings not strict ;)
I'm still a little confused about what you mean. Are you just saying that the first line of a file is "line 1" rather than "line 0" as someone might expect because there are 0 based arrays? Yeah totally, that is correct. Your use of a special variable confused me :) The rest of this node is just a digression and can be ignored if you want :D
I don't think it's really fair to say $. has anything to do with the return value of the .. operator. As I understand it $. contains data from a memory location associated with the last read file handle, and is incremented every time you use <>. Since $. is not just a copy of the line number, but actually is the data stored you can create things like the following ugliness:
my $output='$std | dot |$data| dot '."\n"; while(<>) { my $std = $_; my $std_dot = $.; my $data = <DATA>; my $data_dot = $.++; chomp $std; chomp $data; last if $std eq '.'; $output.=sprintf "%4s |%4s |%4s |%4s\n", $std, $std_dot, $data, $data_dot; } print $output; __DATA__ a b c d e
And this has the following input/output:
a b c d e . $std | dot |$data| dot a | 1 | a | 1 b | 2 | b | 3 c | 3 | c | 5 d | 4 | d | 7 e | 5 | e | 9
I highly doubt that would be useful, but it's interesting to point out how $. is saved. Now, to incorperate the .. operator:
my $output='$std | dot | $r1 |$data| dot | $r2 '."\n"; while(<>) { my $std = $_; my $std_dot = $.; my $data = <DATA>; my $data_dot = $.++; chomp $std; chomp $data; my ($r1, $r2); if( ($r1 = $data =~ /a/ .. $data =~ /e/) && ($r2 = $std =~ /a/ .. $std =~ /e/) ) { $output.=sprintf "%4s |%4s |%4s |%4s |%4s |%4s \n", $std, $std_dot, $r1, $data, $data_dot, $r2; } else { last; } } print $output; __DATA__ a b c d e
This takes/yields the following:
a b c d e f $std | dot | $r1 |$data| dot | $r2 a | 1 | 1 | a | 1 | 1 b | 2 | 2 | b | 3 | 2 c | 3 | 3 | c | 5 | 3 d | 4 | 4 | d | 7 | 4 e | 5 | 5E0 | e | 9 | 5E0
It seems pretty clear that the .. operator uses some kind of internal counter. I know, I'm totally abusing the $. variable in these examples. My question is where does the value of $. go if you use it without the <> operator.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: flipflop .. operator. More about $. var
by pbeckingham (Parson) on Aug 17, 2004 at 14:01 UTC |