#!usr/bin/perl use warnings; use strict; my @text; { local @ARGV = ( './contents' ); while ( <> ) { push @text, grep /important/, $_; } } print @text, "\n"; print @ARGV, "\n"; #### #!usr/bin/perl use warnings; use strict; sub contents { local @ARGV = @_; return my @t = <>; } my $text; $text = contents 'contents2'; print $text . "\n"; my @text = grep /important/, contents 'contents2'; print @text, "\n"; print @ARGV, "\n"; #### #!usr/bin/perl use warnings; use strict; sub contents { local @ARGV = @_; <>; } my $text; $text = contents 'contents3'; print $text . "\n"; my @text = grep /important/, contents 'contents3'; print @text, "\n"; print @ARGV, "\n"; #### #!usr/bin/perl use warnings; use strict; my @text; while ( <> ) { push @text, grep /important/, $_; } print @text, "\n"; print @ARGV, "\n"; #### #!usr/bin/perl use warnings; use strict; unless ( defined $ARGV[0] ) { die "Usage: contents4 \n"; } my @text; { local @ARGV = ( $ARGV[0] ); push @text, grep /important/, <>; } print @text, "\n"; print @ARGV, "\n"; #### #!usr/bin/perl use warnings; use strict; sub grepfile { local @ARGV = ( $_[1] ); return grep /$_[0]/, <>; } my @text = grepfile 'important', './grepfile'; print @text, "\n"; print @ARGV, "\n";