does any other language even have this feature?

Discussion in 'Perl Misc' started by valued customer, Apr 23, 2004.

  1. my $variable = 'fill in blanks';
    my $question = q^
    One of the very useful features of perl is the quotelike
    operator, because it makes it very easy to create a
    "subdocument within a document" ... which brings up
    a question, does any other programming language have
    anything even close to this functionality?

    Python has the triple-quote feature, which is nice, but
    still creates minor hassles if you want to want to output
    a triple-quote inside your 'subdocument' (use-versus-mention).

    XML has CDATA sections, which suck, and suffer from
    (use-versus-mention) as well.

    Moreover, none of them make it easy to ^.$variable.q^ with
    variables.

    Is there any other programming environment that has this
    feature? Can anyone name even one??

    Why doesn't every programming environment have a similar
    feature? Adding 'escape sequences' to strings is
    error-prone, less readable, and annoying!
    ^;

    print $question;
     
    valued customer, Apr 23, 2004
    #1
    1. Advertising

  2. valued customer wrote:

    > Is there any other programming environment that has this
    > feature? Can anyone name even one??


    Perl borrowed the "here document" idea from UNIX shells like Bash, CSH, etc.
    I think it would be a bit of a stretch to refer to that as a "programming
    environment," though. ;-)

    I think Python and Ruby support the idea too.

    > Why doesn't every programming environment have a similar
    > feature?


    It's arguably less useful than one might think at first. When you're dealing
    with really large output strings - such as the one in your message - it
    often makes more sense to use a template-oriented approach, with the
    strings in an external file.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Apr 23, 2004
    #2
    1. Advertising

  3. valued customer <> wrote:


    > One of the very useful features of perl is the quotelike
    > operator,



    It's more usual name is "here document".


    > Is there any other programming environment that has this
    > feature? Can anyone name even one??



    Most (all?) of the *nix shells.


    > Why doesn't every programming environment have a similar
    > feature? Adding 'escape sequences' to strings is
    > error-prone, less readable, and annoying!



    Because non-Perl languages suck. (heh)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 24, 2004
    #3
  4. valued customer

    Ala Qumsieh Guest

    Sherm Pendley wrote:
    > valued customer wrote:
    >
    >
    >>Is there any other programming environment that has this
    >>feature? Can anyone name even one??

    >
    >
    > Perl borrowed the "here document" idea from UNIX shells like Bash, CSH, etc.
    > I think it would be a bit of a stretch to refer to that as a "programming
    > environment," though. ;-)


    I don't think the OP was talking about heredocs. He mentioned
    "quote-like operators" which, to me at least, refers to q// and qq//
    which are different from heredocs. His remark seems to refer to the fact
    that Perl gives you the option to use your favourite delimiter which is
    very useful. I don't know of any other languages that offers this.

    That's not to say heredocs aren't useful. They are very useful, but
    different from q// and qq//.

    --Ala
     
    Ala Qumsieh, Apr 24, 2004
    #4
  5. Ala Qumsieh wrote:

    > Sherm Pendley wrote:
    >
    >> valued customer wrote:
    >>
    >>
    >>> Is there any other programming environment that has this
    >>> feature? Can anyone name even one??

    >>
    >>
    >>
    >> Perl borrowed the "here document" idea from UNIX shells like Bash,
    >> CSH, etc.
    >> I think it would be a bit of a stretch to refer to that as a "programming
    >> environment," though. ;-)

    >
    >
    > I don't think the OP was talking about heredocs. He mentioned
    > "quote-like operators" which, to me at least, refers to q// and qq//
    > which are different from heredocs. His remark seems to refer to the fact
    > that Perl gives you the option to use your favourite delimiter which is
    > very useful. I don't know of any other languages that offers this.


    Ruby has %q(abc) equal to 'abc' (and %q(a(b)c) equal to 'a(b)c'),
    %Q(abc\n) equal to "abc\n" (and %Q(a(b)c\n) equal to "a(b)c\n"),
    and %/abc\n/ equal to "abc\n".

    --
    John W. Kennedy
    Read the remains of Shakespeare's lost play, now annotated!
    http://pws.prserv.net/jwkennedy/Double Falshood.html
     
    John W. Kennedy, Apr 24, 2004
    #5
  6. In article <>, Tad McClellan wrote:
    > valued customer <> wrote:
    >
    >
    >> One of the very useful features of perl is the quotelike
    >> operator,

    >
    >
    > It's more usual name is "here document".


    First, the OP seems to be talking about q{} and friends, rather than
    here docs.

    Second, here docs weren't even in perlop at all, much less under Quote
    and Quote-like Operators until fairly recently, which makes it even less
    likely that that's what was meant.

    Finally, "It's"?? Oh, Tad, I know you know better than that... :)

    dha

    --
    David H. Adler - <> - http://www.panix.com/~dha/
    Linguists don't know much, but they do know that nobody can succeed in
    telling people at large how to speak. - Larry Wall
     
    David H. Adler, Apr 25, 2004
    #6
  7. valued customer

    Juha Laiho Guest

    Ala Qumsieh <> said:
    >I don't think the OP was talking about heredocs. He mentioned
    >"quote-like operators" which, to me at least, refers to q// and qq//
    >which are different from heredocs. His remark seems to refer to the fact
    >that Perl gives you the option to use your favourite delimiter which is
    >very useful. I don't know of any other languages that offers this.


    I guess that the freedom to use your delimiter of choice comes from
    'sed', the regex-based stream editor in Unix environments. Even
    though sed regexes are commonly written with / as the delimiter,
    any delimiter can be used (f.ex. ':' is a good choice when the
    patterns contain Unix directory paths -- as long as you can be
    certain that the paths never contain ':').

    s:/usr/bin:/usr/local/bin:g is so much easier to read than
    s/\/usr\/bin/\/usr\/local\/bin/g -- esp. if you have a need to
    have the above in a context where backslashes must be escaped,
    leaving you with
    s/\\/usr\\/bin/\\/usr\\/local\\/bin/g .
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Apr 25, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxwell2006
    Replies:
    2
    Views:
    952
    Maxwell2006
    Mar 22, 2006
  2. Stan Goodman

    Even older fart, even newer newbie

    Stan Goodman, Jul 3, 2003, in forum: Java
    Replies:
    11
    Views:
    701
    Stan Goodman
    Jul 4, 2003
  3. thinktwice
    Replies:
    3
    Views:
    338
    Daniel T.
    Feb 10, 2006
  4. Replies:
    19
    Views:
    229
    Nobody
    Feb 26, 2013
  5. Andrew Robinson
    Replies:
    0
    Views:
    74
    Andrew Robinson
    Feb 25, 2013
Loading...

Share This Page