Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Is a here-doc a good way to retrieve data file contents for testing? (updated)

by LanX (Saint)
on Jan 17, 2021 at 02:04 UTC ( [id://11127017]=note: print w/replies, xml ) Need Help??


in reply to Re: Is a here-doc a good way to retrieve data file contents for testing?
in thread Is a here-doc a good way to retrieve data file contents for testing?

tybalt89, you are one of the most unorthodox Perl hackers I've seen so far and I mean it as a compliment. :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

UPDATE

WOW, this even allows interpolating variables from the function scope in the "outside" HERE-DOC ...

use strict; use warnings; print "-------\n"; print json_here(42,666); print "-------\n"; sub chompit { my $str = shift; chomp $str; return $str; } sub json_here { my $x=shift; chompit << "__JSON__" } "Type": 0, "Width": 504, "X": $x, "Y": $_[0] } ] } __JSON__

C:/Perl_524/bin\perl.exe -w d:/tmp/pm/chomp_here.pl ------- "Type": 0, "Width": 504, "X": 42, "Y": 666 } ] }-------

Replies are listed 'Best First'.
Re^3: Is a here-doc a good way to retrieve data file contents for testing? (updated)
by tybalt89 (Monsignor) on Jan 17, 2021 at 02:56 UTC

    Because it's a lexer thing. To the parser it's just a string *inside* the body of the sub.

      I know.

      But that's still not a guarantee, I doubt this was intended.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Why should that be unintended?

        See perlop on Quote-like operators, where here-documents are equivalent to nomal double-quoted strings, and that certainly holds true for the scope where they are evaluated in. This scope is determined by the place where the <<"FOO" occurs, not where the end of string marker sits, since here-docs are a line-oriented quoting mechanism.

        I'm pretty sure that this behaviour is intentional and has been a long time in Perl and will stay.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found