[Chicago-talk] What does dollar sign followed by a period represent?

Richard Reina richard at rushlogistics.com
Tue Dec 26 05:31:42 PST 2023


	


Thank you for the tip.
 



On Sun, 24 Dec 2023 21:02:26 -0800, Adriano Ferreira <a.r.ferreira at gmail.com> wrote:
 
 
"perldoc" has the answer, just like mentioned by Andy and David. And "perldoc" has a special trick when you want to look up a special variable.

 

    perldoc -v PerlVar

 

In the case of $.:

 

% perldoc -v '$.'
    HANDLE->input_line_number( EXPR )
    $INPUT_LINE_NUMBER
    $NR
    $.      Current line number for the last filehandle accessed.

            Each filehandle in Perl counts the number of lines that have
            been read from it. (Depending on the value of $/, Perl's idea of
            what constitutes a line may not match yours.) When a line is
            read from a filehandle (via "readline()" or "<>"), or when
            "tell()" or "seek()" is called on it, $. becomes an alias to the
            line counter for that filehandle.

            You can adjust the counter by assigning to $., but this will not
            actually move the seek pointer. *Localizing $. will not localize
            the filehandle's line count*. Instead, it will localize perl's
            notion of which filehandle $. is currently aliased to.

            $. is reset when the filehandle is closed, but not when an open
            filehandle is reopened without an intervening "close()". For
            more details, see "I/O Operators" in perlop. Because "<>" never
            does an explicit close, line numbers increase across "ARGV"
            files (but see examples in "eof" in perlfunc).

            You can also use "HANDLE->input_line_number(EXPR)" to access the
            line counter for a given filehandle without having to worry
            about which handle you last accessed.

            Mnemonic: many programs use "." to mean the current line number.

 

 


On Sat, Dec 23, 2023 at 9:47 PM David Mertens <dcmertens.perl at gmail.com> wrote:


When in doubt,
 

perldoc perlvar

 

Might give you a faster answer than asking the list. Ymmv. :-)

 


On Sat, Dec 23, 2023, 5:02 PM Richard Reina <richard at rushlogistics.com> wrote:

Ahh thank you so very much Andy!

 



On Sat, 23 Dec 2023 16:59:24 -0600, Andy Lester <andy at petdance.com> wrote:

It’s the current line number. See “perldoc perlvar”

> On Dec 23, 2023, at 4:57 PM, Richard Reina wrote:
>
> 
> A few years ago I hastily wrote some code that I did not comment very well. In it I found:
>
> $switch = $. if m!^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$!; # match date
>
> Can anyone tell me what $. means?
>
> Thanks for any help.
>
> Richard
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> https://mail.pm.org/mailman/listinfo/chicago-talk

_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk
 
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk

_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk

_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20231226/d8ddcc68/attachment.html>


More information about the Chicago-talk mailing list