Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by shmem (Canon)
on Dec 07, 2007 at 08:05 UTC ( #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}


Comment on Re: 'perl -e' and '__DATA__' What's wrong?
Select or Download Code
Re^2: 'perl -e' and '__DATA__' What's wrong?
by Skeeve (Vicar) 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
Node Status?
node history
Node Type: note [id://655602]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-09-16 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (46 votes), past polls