In perl.git, the branch rgs/nomagicopen has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/0d36b5a5c2536f7ed29e6e66ee888d076f93f012?hp=0a74b59263105fcf4542726e6a82b8cb58b73cf8>

- Log -----------------------------------------------------------------
commit 0d36b5a5c2536f7ed29e6e66ee888d076f93f012
Author: Rafael Garcia-Suarez <[email protected]>
Date:   Tue Sep 30 00:25:27 2014 +0200

    Clarify the documentation for <<>>

M       pod/perlop.pod

commit 1fb2c054e826fdefa844490c422c33d5691e9a4e
Author: Rafael Garcia-Suarez <[email protected]>
Date:   Tue Sep 30 00:24:21 2014 +0200

    Add tests for $ARGV
    
    There weren't apparently any. This also tests that $ARGV behaves
    correctly both with <> and <<>>.

M       t/io/argv.t
-----------------------------------------------------------------------

Summary of changes:
 pod/perlop.pod |  6 ++++--
 t/io/argv.t    | 38 +++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/pod/perlop.pod b/pod/perlop.pod
index 8e279fe..07bcaf9 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -2853,7 +2853,7 @@ mean C</^/m>.
 
 =head2 I/O Operators
 X<operator, i/o> X<operator, io> X<io> X<while> X<filehandle>
-X<< <> >> X<@ARGV>
+X<< <> >> X<< <<>> >> X<@ARGV>
 
 There are several I/O operators you should know about.
 
@@ -2987,7 +2987,9 @@ can use the module C<ARGV::readonly> from CPAN, or use 
the double bracket:
 
 Using double angle brackets inside of a while causes the open to use the
 three argument form (with the second argument being C<< < >>), so all
-arguments in ARGV are treated as literal filenames.
+arguments in ARGV are treated as literal filenames (including "-").
+(Note that for convenience, if you use C<< <<>> >> and if @ARGV is
+empty, it will still read from the standard input.)
 
 You can modify @ARGV before the first <> as long as the array ends up
 containing the list of filenames you really want.  Line numbers (C<$.>)
diff --git a/t/io/argv.t b/t/io/argv.t
index 70c5289..944abd2 100644
--- a/t/io/argv.t
+++ b/t/io/argv.t
@@ -7,7 +7,7 @@ BEGIN {
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 28);
+plan(tests => 32);
 
 my ($devnull, $no_devnull);
 
@@ -21,6 +21,9 @@ if (is_miniperl()) {
 open(TRY, '>Io_argv1.tmp') || (die "Can't open temp file: $!");
 print TRY "a line\n";
 close TRY or die "Could not close: $!";
+open(TRY, '>Io_argv2.tmp') || (die "Can't open temp file: $!");
+print TRY "another line\n";
+close TRY or die "Could not close: $!";
 
 $x = runperl(
     prog       => 'while (<>) { print $., $_; }',
@@ -41,6 +44,25 @@ is($x, "1a line\n2a line\n", '<> from two files');
        stdin   => "foo\n",
     );
     is($x, "foo\n", '<> from just STDIN');
+
+    $x = runperl(
+       prog    => 'while (<>) { print $ARGV.q/,/.$_ }',
+       args    => [ 'Io_argv1.tmp', 'Io_argv2.tmp' ],
+    );
+    is($x, "Io_argv1.tmp,a line\nIo_argv2.tmp,another line\n", '$ARGV is the 
file name');
+
+    $x = runperl(
+       prog    => 'print $ARGV while <>',
+       stdin   => "foo\nbar\n",
+        args           => [ '-' ],
+    );
+    is($x, "--", '$ARGV is - for explicit STDIN');
+
+    $x = runperl(
+       prog    => 'print $ARGV while <>',
+       stdin   => "foo\nbar\n",
+    );
+    is($x, "--", '$ARGV is - for implicit STDIN');
 }
 
 {
@@ -69,7 +91,7 @@ close TRY or die "Could not close: $!";
 @ARGV = ('Io_argv1.tmp', 'Io_argv2.tmp');
 $^I = '_bak';   # not .bak which confuses VMS
 $/ = undef;
-my $i = 7;
+my $i = 10;
 while (<>) {
     s/^/ok $i\n/;
     ++$i;
@@ -94,7 +116,7 @@ open STDIN, 'Io_argv1.tmp' or die $!;
 @ARGV = ();
 ok( !eof(),     'STDIN has something' );
 
-is( <>, "ok 7\n" );
+is( <>, "ok 10\n" );
 
 SKIP: {
     skip_if_miniperl($no_devnull, 4);
@@ -137,10 +159,10 @@ print TRY "one\ntwo\n";
 close TRY or die "Could not close: $!";
 
 $x = runperl(
-    prog       => 'print while <<>>',
+    prog       => 'print $..$ARGV.$_ while <<>>',
     args       => [ 'Io_argv1.tmp' ],
 );
-is($x, "one\ntwo\n", '<<>>');
+is($x, "1Io_argv1.tmpone\n2Io_argv1.tmptwo\n", '<<>>');
 
 $x = runperl(
     prog       => 'while (<<>>) { print }',
@@ -149,6 +171,12 @@ $x = runperl(
 is($x, "foo\n", '<<>> from just STDIN (no argument)');
 
 $x = runperl(
+    prog       => 'print $ARGV.q/,/ for <<>>',
+    stdin      => "foo\nbar\n",
+);
+is($x, "-,-,", '$ARGV is - for STDIN with <<>>');
+
+$x = runperl(
     prog       => 'while (<<>>) { print $_; }',
     stdin      => "foo\n",
     stderr     => 1,

--
Perl5 Master Repository

Reply via email to