Advertisement
Guest User

Untitled

a guest
Nov 1st, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use v5.18;
  4.  
  5. my @file_array;
  6. my $current_line = undef;
  7. my $prev_line = undef;
  8. open (my $fh, "<", 'input.txt');
  9. while(readline($fh)){
  10.     $current_line = $_;
  11.     if ($current_line =~ /^msgstr/ and $prev_line =~ /^msgid/){
  12.         #print $prev_line;
  13.         $prev_line =~ /^msgid\ \"(.+)+\"/;
  14.         my $prev_var = $1;
  15.         #print $current_line;
  16.         $current_line =~ /^msgid\ \"(.+)+\"/;
  17.         my $cur_var = $1;
  18.         if ($cur_var eq $prev_var){
  19.             $current_line =~ s/$cur_var//;
  20.         }
  21.         push @file_array, $current_line;
  22.     }
  23.     else {
  24.         push @file_array, $current_line;
  25.     }
  26.     $prev_line = $current_line;
  27. }
  28. close $fh;
  29. my $file_text = join "", @file_array;
  30. print $file_text;
  31.  
  32. open (my $fh_out, ">", 'output.txt');
  33. print $fh_out $file_text;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement