ARGV-OrDATA

 view release on metacpan or  search on metacpan

lib/ARGV/OrDATA.pm  view on Meta::CPAN

    @ARGV = 'file2.txt';  # Works.

    my $from_file2 = <>;

Calling C<import> after C<unimport> would restore the DATA handle, but
B<wouldn't rewind it>, i.e. it would continue from where you stopped
(see t/04-unimport.t).

=head2 Why?

I use this technique when solving programming contests. The sample
input is usually small and I don't want to waste time by saving it
into a file.

=head1 EXPORT

Nothing. There are 2 subroutines you can call via their fully qualified names,
though:

=over 4

t/pipe.pl  view on Meta::CPAN

#!/usr/bin/perl
use warnings;
use strict;

use Test::More tests => 3;

use ARGV::OrDATA;

while (<>) {
    is $_, "pipe $.\n", "read line $. from stdin";
}
ok eof *STDIN, 'end of stdin';

__DATA__
data 1



( run in 1.886 second using v1.01-cache-2.11-cpan-5a3173703d6 )