Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Quote and Quote-like Operators

by Anonymous Monk
on Dec 15, 2011 at 11:51 UTC ( [id://943706]=note: print w/replies, xml ) Need Help??


in reply to Quote and Quote-like Operators

FWIW, heredocs aren't ugly :) if text is more than one line, heredocs are my first choice, of the form

my $html = <<'__HTML__'; __HTML__ my $xml = <<'__XML__'; __XML__ my $foo = <<'__EOF__'; __EOF__

I've often pasted multiline text and had to adjust the delimiters, ditching '' and "" and {} for q~~. With heredocs this is very rare. I've had HERE or EOF show up a few times, but virtually never __EOF__, which I also like for its similarity to __DATA__ and __END__

Its part of my template, I even have a hotkey in my editor for heredocs

I also prefer  qw' l i s t ' or  qw/ l i s t/ because no shift key is involved, and its all pinky action (on QWERTY keyboard),  use CGI 3.55 qw/ param /;  use Data::Dump qw' dd ';

for oneliner portability, i prefer qq// and q//, much easier to move between shells , only have to change leading/trailing "" into '' and vice versa

For match/substitution, i prefer  s/// and then to avoid leaning toothpick syndrome i switch to one of  s;;;  s=== depending on the regex, similarly because shift isn't required, and its all pinky action :)

for larger regex I always use balanced  s{}{}ex; or

s{ }{ }ex;

though the options are ridiculous :D

perl -MO=Deparse -e " s///g " perl -MO=Deparse -e " s\\\g " perl -MO=Deparse -e " s[][]g " perl -MO=Deparse -e " s()()g " perl -MO=Deparse -e " s{}{}g " perl -MO=Deparse -e " s!!!g " perl -MO=Deparse -e " s###g " perl -MO=Deparse -e " s vvvg " perl -MO=Deparse -e " s ___g " perl -MO=Deparse -e " s {}//g " perl -MO=Deparse -e " s {}\\g " perl -MO=Deparse -e " s {}vvg " perl -MO=Deparse -e " s {}()g " perl -MO=Deparse -e " s {}[]g " perl -MO=Deparse -e " s {}<>g " perl -MO=Deparse -e " s<><>g "

you're correct, you definitely want to avoid alphanumeric for delimiters, esp fancy unicode

Replies are listed 'Best First'.
Re^2: Quote and Quote-like Operators
by jmcnamara (Monsignor) on Dec 15, 2011 at 17:31 UTC
    FWIW, heredocs aren't ugly :)

    Not on their own perhaps but they do add ugliness to indented code.

    --
    John.

      One can include spaces in the terminating string:
      sub foo { xsh <<' end ;' open 1.xml ; delete //@id ; save :b ; end ; }
      :-)

        Yes, but in that case printing the contents of the heredoc will print the indentation as well.

        A better solution would be if perl removed whatever leading whitepsace came before the heredoc (or the end token) from the text of the heredoc. Then the heredoc could be indented to match the surrounding code. In that case I would use it more often.

        I'm not saying that heredocs aren't useful. Just that they break indentation.

        --
        John.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found