in reply to Re^4: magic-diamond <> behavior -- WHAT?! (docs)
in thread magic-diamond <> behavior -- WHAT?!
Here's how it works: the first time <> is evaluated, the @ARGV array is checked, and if it is null, $ARGV[0] is set to "-", which when opened gives you standard input. The @ARGV array is then processed as a list of filenames. The loop:If you then switch to pages 191-194, it discusses the open function, including the effects of leading and trailing pipes in the filenames.is equivalent to the following Perl-like pseudocode:while (<>) { ... # code for each line }except that it isn't so cumbersome to say, and will actually work. It really does shift @ARGV and put the current filename into variable $ARGV. It also uses filehandle ARGV internally -- <> is just a synonym for <ARGV>, which is magical. (The pseudocode doesn't work because it treats <ARGV> as non-magical.)@ARGV = ('-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV) or warn "Can't open $ARGV: $!\n"; while (<ARGV>) { ... # code for each line } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: magic-diamond <> behavior -- WHAT?! (dock)
by tye (Sage) on Oct 30, 2008 at 17:39 UTC | |
by Fletch (Bishop) on Oct 31, 2008 at 17:32 UTC | |
by tye (Sage) on Oct 31, 2008 at 17:50 UTC | |
by JavaFan (Canon) on Oct 31, 2008 at 18:41 UTC | |
by Fletch (Bishop) on Oct 31, 2008 at 21:58 UTC | |
| |
by tye (Sage) on Oct 31, 2008 at 19:30 UTC | |
by mr_mischief (Monsignor) on Nov 05, 2008 at 16:56 UTC | |
by Fletch (Bishop) on Nov 05, 2008 at 18:25 UTC | |
by mr_mischief (Monsignor) on Nov 05, 2008 at 18:55 UTC | |
|