http://www.perlmonks.org?node_id=1036388


in reply to Re: Using the DATA file handle for ARGV
in thread Using the DATA file handle for ARGV

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?

  • Comment on Re^2: Using the DATA file handle for ARGV

Replies are listed 'Best First'.
Re^3: Using the DATA file handle for ARGV
by Grimy (Pilgrim) on Jun 01, 2013 at 21:30 UTC
    @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.