Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (11)
    As of 2014-07-30 20:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (240 votes), past polls