Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: tieing STDIN & STDOUT using IO::Scalar for use inside an eval

by water (Deacon)
on Sep 11, 2004 at 21:45 UTC ( #390321=note: print w/replies, xml ) Need Help??


in reply to tieing STDIN & STDOUT using IO::Scalar for use inside an eval

upon further examination, the issue hinges on  while(<>), which doesn't work in this context, versus while(<STDIN>), which does.

So, problem solved.

But, as I'm curious, can anyone explain why the magic <> doesn't work here?

Happy Happy Happy water

Replies are listed 'Best First'.
Re^2: tieing STDIN & STDOUT using IO::Scalar for use inside an eval
by dave_the_m (Monsignor) on Sep 11, 2004 at 21:55 UTC
    But, as I'm curious, can anyone explain why the magic <> doesn't work here?
    Because <> is a synonym for <ARGV>, and ARGV is a magic filehandle that sometimes reads from STDIN, but sometimes reads from files etc.

    Dave.

      That's right... specifically, it depends on what is currently in @ARGV (if there's anything in @ARGV, the contents are treated as file names, and the files are magically opened and read from... if @ARGV is empty, it'll read from STDIN).

      If the intent is to read from STDIN, then do so, explicitly, by <STDIN>. If the intent is to process files, generically, either named files or files piped through, then use <>. In the case of the original post, which seems to be (maybe) testing some external code and trying to sandbox it, somewhat, it might just be a good idea to localize @ARGV (that is, to extend the sandbox beyond just STDIN and STDOUT (why isn't he also tieing STDERR, then, though?) to include the command line).

      ------------ :Wq Not an editor command: Wq

        That's right... specifically, it depends on what is currently in @ARGV (if there's anything in @ARGV, the contents are treated as file names, and the files are magically opened and read from... if @ARGV is empty, it'll read from STDIN).

        As long as we're getting specific, we might as well get it exactly right: The contents of @ARGV are always "treated as file names, and the files are magically opened and read from." If @ARGV is empty, then "$ARGV[0] is set to "-", which when opened gives you standard input." - perlop

        So it really never reads from the filehandle named STDIN, but it might read standard input by opening the file named "-".

        --
        edan

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2020-09-25 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (141 votes). Check out past polls.

    Notices?