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

Re: Using the DATA file handle for ARGV

by Grimy (Pilgrim)
on Jun 01, 2013 at 02:21 UTC ( [id://1036366]=note: print w/replies, xml ) Need Help??


in reply to Using the DATA file handle for ARGV

This snippet is really interesting and could prove useful later, thanks for sharing (:

There's something I find strange. Typeglob aliasing usually transfers all magic. Try this:

*a = *\; $a = 42; print; # prints 42

However, in this case, it looks like @ARGV and $ARGV are stripped of all magic by the manipulation (@DATA and $DATA ain't getting any magic neither). Can somebody explain what's happening there?

Replies are listed 'Best First'.
Re^2: Using the DATA file handle for ARGV
by ikegami (Patriarch) on Nov 13, 2013 at 18:22 UTC

    it looks like @ARGV and $ARGV are stripped of all magic by the manipulation

    No, they were never magical in the first place.

    >perl -MDevel::Peek -e"Dump($ARGV,1);" 2>&1 | find "MAGIC" >perl -MDevel::Peek -e"Dump(\@ARGV,1);" 2>&1 | find "MAGIC" >perl -MDevel::Peek -e"Dump(\%ENV,1);" 2>&1 | find "MAGIC" MAGIC = 0x4c7ed8 MG_TYPE = PERL_MAGIC_env(E)

    They are simply set by reading from the magical file handle ARGV, which is no longer being read from.

Re^2: Using the DATA file handle for ARGV
by Anonymous Monk on Jun 01, 2013 at 06:54 UTC

    However, in this case, it looks like @ARGV and $ARGV are stripped of all magic by the manipulation (@DATA and $DATA ain't getting any magic neither). Can somebody explain what's happening there?

    Why would there be "magic", and what would this "magic" do?

      @ARGV = 'echo 42 |'; print <>; # prints 42 print $ARGV; # prints echo 42|

      Unless I'm mistaken, this illustrates that both @ARGV and $ARGV are usually magic.

      But I thing I got it. There's isn't actually any magic in @ARGV and $ARGV. It's just the magic *ARGV{IO} that pops @ARGV and writes $ARGV. Once the magic *ARGV{IO} is gone, those variables are nothing special. Or am I still completely mistaken?

        Once the magic *ARGV{IO} is gone, those variables are nothing special. Or am I still completely mistaken?

        I think you're right. I think the magic belongs to readline ARGV , not readline *DATA, and when you do *ARGV = *DATA it makes *ARGV an alias for *DATA, doesn't make *DATA an alias for *ARGV, so *DATA has no magic

        $ echo |perl -e " *ARGV = *DATA; print while <DATA> " $ echo |perl -e " *DATA = *ARGV; print while <DATA> " ECHO is on.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found