Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $pattern = @ARGV[0];
- $file= @ARGV[1];
- open($fp,$file);
- @arr = <$fp>;
- @lines = grep $pattern, @arr;
- close($fp);
- print @lines;
- $pattern = @ARGV[0];
- $file= @ARGV[1];
- @lines = grep $pattern, @arr;
- @lines = grep /$pattern/, @arr;
- grep EXPR,LIST
- use strict;
- use warnings;
- open my $fh, '<', $file or die "unable to open '$file' for reading : $!";
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $pattern = $ARGV[0];
- my $file = $ARGV[1];
- open $fh, '<', $file or die "unable to open file '$file' for reading : $!";
- my @arr = <$fh>;
- close $fh; # close as soon as possible
- my @lines = grep /$pattern/, @arr;
- print @lines;
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $pattern = qr/$ARGV[0]/;
- my $file= $ARGV[1];
- print "pattern=$patternn";
- my @lines;
- open my $fh, '<', $file or die "unable to open file '$file' for reading : $!";
- while(my $line=<$fh>) {
- push @lines, $line if ($line =~ $pattern);
- }
- close($fh);
- print @lines;
- perl -wnle '/foo/ and print' null.txt # normal grep
- perl -wnle '/foo/ and print "$ARGV: $_"' null.txt # grep -H
- perl -wnle '/foo/ and print $ARGV and close ARGV' null_1.txt null_2.txt # grep -l
- $ perl -00 -wnl -e '/bBRIBEb/i and print;' SenQ.testimony
- I knew I'd be in trouble if
- I ACCEPTED THE BRIBE!
- So I did not.
- My minimum bribe is $100k, and she only offered me $50k,
- so to preserve my pricing power, I refused it.
- $ perl -00 -wnl -e '/bBRIBEb/i and close ARGV;' SenQ.testimony
- I knew I would be in trouble if
- I ACCEPTED THE BRIBE!
- So I did not.
- perl -ne 'print if /PATTERN/' FILE1 FILE2 ...
- use strict;
- use warnings;
- my $pattern = shift;
- while (my $line = <>){
- print $ARGV, ':', $line if $line =~ $pattern;
- }
- $string =~ /pattern/;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement