does any other language even have this feature?

V

valued customer

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;
 
S

Sherm Pendley

valued said:
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--
 
T

Tad McClellan

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)
 
A

Ala Qumsieh

Sherm said:
valued customer wrote:




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
 
J

John W. Kennedy

Ala 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.

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".
 
D

David H. Adler

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
 
J

Juha Laiho

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 .
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top