davidfilmer has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Masters. I am often annoyed that this code:
produces this result:#!/usr/bin/perl print "Line [ ", __LINE__, " ] looks very nice\n"; print "Line [ __LINE__ ] is taken as a string-literal\n"; #print "Line [ @{[__LINE__}] is a syntax error\n";
The syntax of Line 2 works OK, but it is a lot of fanning-about that often makes me reluctant to include this useful bit of debugging information. I would much prefer the syntax of Line 3, or some convenient token such as $LINE (or $__LINE__ or whatever I can just embed in double-quotes). Line 4 is still a lot of fanning-about, but it doesn't even compile, even though this screwball syntax: print "The Time Is: [ @{[scalar(localtime)]} ] right now\n\n"; works just fine, without dropping out of the double-quotes: The Time Is: [ Sun Mar 7 00:14:15 2021 ] right now Is there a better way to include the __LINE__ information without all this fanning-about? Thanks for reading. I appreciate any help to beautify my ugly code. - DavidLine [ 2 ] looks very nice. Line [ __LINE__ ] is taken as a string-literal.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is there a better way to use the line number in a quoted string than __LINE__?
by haukex (Archbishop) on Mar 07, 2021 at 08:43 UTC | |
Re: Is there a better way to use the line number in a quoted string than __LINE__?
by AnomalousMonk (Archbishop) on Mar 07, 2021 at 08:43 UTC | |
Re: Is there a better way to use the line number in a quoted string than __LINE__?
by LanX (Saint) on Mar 07, 2021 at 08:48 UTC | |
Re: Is there a better way to use the line number in a quoted string than __LINE__?
by stevieb (Canon) on Mar 07, 2021 at 18:44 UTC | |
by LanX (Saint) on Mar 07, 2021 at 20:55 UTC | |
Re: Is there a better way to use the line number in a quoted string than __LINE__?
by Fletch (Bishop) on Mar 08, 2021 at 04:22 UTC |
Back to
Seekers of Perl Wisdom