Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Today in the Chatterbox, maddfisherman had some questions about the heredoc quoting mechanism, and OeufMayo and i started answering him, and brought up some things that tinman didn't know, and that brought up stuff none of us knew, so we ran some test scripts and found some interesting things.

first, some things i did know:

#!/usr/bin/perl -w use strict; my $foo = 'date'; print <<'SINGLE'; $foo SINGLE print <<"DOUBLE"; $foo DOUBLE print <<`BACK`; $foo BACK print <<IMPLIED; $foo IMPLIED
as the experienced heredoc user should know, this prints something like
$foo date Wed Jun 20 15:33:51 PDT 2001 date
Note that with no quotes, double quote interpolation is implied. (note, too, that your date probaby differs from mine.)

but what if you want to use other quoting mechaisms? i wanted to put a big long list into a qw(), and i tried

my @list = <<qw(HERE); Foo Bar Baz HERE
but it can't find string terminator qw.
my @list = qw <<HERE;
can't find string terminator >.
my @list = qw(<< HERE); Foo Bar Baz HERE
did better, but only because i consider the runtime error Can't locate object method "Baz" via package "HERE" at everywhere.pl line 23. to be better than not compiling. next step? well, this won't work:
my $bar = <<HERE; Foo Bar Baz HERE my @list = qw($bar);
because the $bar in qw() is not interpolated. this brings up the interesting point of how qw works. further tests seem to indicate that all the quoting functions (q, qq, qr, qw, and qx currently, and i think we get more in perl6) are hard to use with heredocs. in fact, aside from trivial cases, they seem to be hard to use, until you realize that they are operators and not functions. which brings up more questions, like "can we get at the underlying functions?" and "if so, how?" things along those lines.

so, uh, perhaps a heredoc tutorial and a quoters tutorial would be in order.

.

thanks to maddfisherman, OeufMayo, myocom, and others in the chatterbox for their assistance.

update: fixed some links. and no, CheeseLord i can't think of any specific reason to do it with qw//, but with some of the forthcoming quoting operators, maybe.

update 2: fixed IMPLIED as implied by Particle. bad copying on my part.

.

In reply to Here, doccy doccy. nice doccy. heredoc, treat. by Vynce

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-28 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found