Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: 'perl -e' and '__DATA__' What's wrong?

by shmem (Chancellor)
on Dec 07, 2007 at 08:05 UTC ( [id://655602]=note: print w/replies, xml ) Need Help??


in reply to 'perl -e' and '__DATA__' What's wrong?

The -e switch tells perl to treat the next argument on the command line as a script.

The __DATA__ token causes perl to re-open $0, seek to the position of the __DATA__ and leave the filehandle DATA open pointing to the contents after that line.

$ perl -le 'print $0' -e
I'm not surprised a file handle cannot be associated with text passed into perl as a command line argument. -e is no file proper.

Maybe you could use

$ perl -e 'print <<EOT; example data EOT '

instead.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: 'perl -e' and '__DATA__' What's wrong?
by Skeeve (Parson) on Dec 07, 2007 at 09:57 UTC

    Unfortunately <<'EOT' has the same limitations as using <<<, meaning: STDIN is already used for the script and so I can't pipe other content in.

    My current solution is, that I use a variable like this:

    my $DATAvar = <<'EOT'; example data here EOT

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      STDIN is already used for the script and so I can't pipe other content in

      I'm probably misunderstanding something but

      $ cat cccc zzz 999 $ cat cccc | perl -e ' > print <<'EOT'; > abc > 123 > EOT > print while <>;' abc 123 zzz 999 $

      I can read from STDIN here. Have I got the wrong end of the stick?

      Cheers,

      JohnGG

        That's exactly what I needed with additional __DATA__. Now replace -e with <<< or with the <<'EOT' proposed and you'll see what I meant.

        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-24 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found