Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by shmem (Chancellor)
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 '



_($_=" "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 (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

      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?



        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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655602]
and a soft breeze sighs...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2018-05-28 00:18 GMT
Find Nodes?
    Voting Booth?