Reverse Two Consecutive Lines

Posted by thebourneid on Stack Overflow See other posts from Stack Overflow or by thebourneid
Published on 2010-05-21T02:45:50Z Indexed on 2010/05/21 2:50 UTC
Read the original article Hit count: 269

Filed under:

I have this part of a code for editing cue sheets and I don't know how to reverse two consecutive lines if found:

/^TITLE.*?"$/  
/^PERFORMER.*?"$/

to reverse to

/^PERFORMER.*?"$/  
/^TITLE.*?"$/  

What would it be the solution in my case?

use strict; 
use warnings; 
use File::Find; 
use Tie::File;


my $dir_target = 'test';

find(\&c, $dir_target);        
sub c {  
   /\.cue$/ or return;

   my $fn = $File::Find::name;

   tie my @lines, 'Tie::File', $fn or die "could not tie file: $!"; 
        for (my $i = 0;  $i < @lines; $i++) {
             if ($lines[$i] =~ /^REM (DATE|GENRE|REPLAYGAIN).*?$/) {
                  splice(@lines, $i, 3);
             }
     if ($lines[$i] =~ /^\s+REPLAYGAIN.*?$/) {
                  splice(@lines, $i, 1);
             }
        }

   untie @lines; 
}

© Stack Overflow or respective owner

Related posts about perl