Advertisement
Guest User

Untitled

a guest
Jan 10th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4.  
  5. # get command line
  6. my $usage = "substitute.pl <infile> <outfile>\n";
  7. my $infile = shift or die $usage;
  8. my $outfile = shift or die $usage;
  9.  
  10. open my $in, "<", "$infile" or die "Cannot open $infile: $!\n";
  11. open my $out, ">", "$outfile" or die "Cannot open $outfile: $!\n";
  12.  
  13. while ( <$in> ) {
  14. chomp;
  15. print $out "$_\n";
  16. if ($_ =~ m/Anna/) {
  17. # set $tmp to equal $_ so we can substitute
  18. my $tmp = $_;
  19. $tmp =~ s/Anna/Joanna/;
  20. print $out "$tmp\n";
  21. }
  22. }
  23.  
  24. close $in;
  25. close $out;
  26. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement