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.


In reply to Re^4: flipflop .. operator. More about $. var by Fiftyvolts
in thread State information for flipflop .. operator. by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.