Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. $pattern = @ARGV[0];
  2. $file= @ARGV[1];
  3.  
  4. open($fp,$file);
  5.  
  6. @arr = <$fp>;
  7.  
  8. @lines = grep $pattern, @arr;
  9.  
  10. close($fp);
  11. print @lines;
  12.  
  13. $pattern = @ARGV[0];
  14. $file= @ARGV[1];
  15.  
  16. @lines = grep $pattern, @arr;
  17.  
  18. @lines = grep /$pattern/, @arr;
  19.  
  20. grep EXPR,LIST
  21.  
  22. use strict;
  23. use warnings;
  24.  
  25. open my $fh, '<', $file or die "unable to open '$file' for reading : $!";
  26.  
  27. #!/usr/bin/perl
  28.  
  29. use strict;
  30. use warnings;
  31.  
  32. my $pattern = $ARGV[0];
  33. my $file = $ARGV[1];
  34.  
  35. open $fh, '<', $file or die "unable to open file '$file' for reading : $!";
  36. my @arr = <$fh>;
  37. close $fh; # close as soon as possible
  38.  
  39. my @lines = grep /$pattern/, @arr;
  40.  
  41. print @lines;
  42.  
  43. #!/usr/bin/perl
  44. use strict;
  45. use warnings;
  46.  
  47. my $pattern = qr/$ARGV[0]/;
  48. my $file= $ARGV[1];
  49. print "pattern=$patternn";
  50.  
  51. my @lines;
  52. open my $fh, '<', $file or die "unable to open file '$file' for reading : $!";
  53. while(my $line=<$fh>) {
  54. push @lines, $line if ($line =~ $pattern);
  55. }
  56. close($fh);
  57. print @lines;
  58.  
  59. perl -wnle '/foo/ and print' null.txt # normal grep
  60. perl -wnle '/foo/ and print "$ARGV: $_"' null.txt # grep -H
  61. perl -wnle '/foo/ and print $ARGV and close ARGV' null_1.txt null_2.txt # grep -l
  62.  
  63. $ perl -00 -wnl -e '/bBRIBEb/i and print;' SenQ.testimony
  64. I knew I'd be in trouble if
  65. I ACCEPTED THE BRIBE!
  66. So I did not.
  67.  
  68. My minimum bribe is $100k, and she only offered me $50k,
  69. so to preserve my pricing power, I refused it.
  70.  
  71. $ perl -00 -wnl -e '/bBRIBEb/i and close ARGV;' SenQ.testimony
  72. I knew I would be in trouble if
  73. I ACCEPTED THE BRIBE!
  74. So I did not.
  75.  
  76. perl -ne 'print if /PATTERN/' FILE1 FILE2 ...
  77.  
  78. use strict;
  79. use warnings;
  80.  
  81. my $pattern = shift;
  82.  
  83. while (my $line = <>){
  84. print $ARGV, ':', $line if $line =~ $pattern;
  85. }
  86.  
  87. $string =~ /pattern/;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement