Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:15:37+00:00 2026-05-14T23:15:37+00:00

I have this part of a code for editing cue sheets and I don’t

  • 0

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; 
}
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:15:38+00:00Added an answer on May 14, 2026 at 11:15 pm

    Well, since you’re tying into an array, I’d just check $lines[$i] and $lines[$i+1] (as long as the +1 address exists, that is), and if the former matches TITLE and the latter PERFORMER, swap them. Unless perhaps you need to transpose these even if they’re not consecutive??

    Here’s an option (this snippet would go inside your for loop, perhaps above the REM-checking line) if you know they’ll be consecutive:

    if ($i < $#lines and $lines[$i] =~ /^TITLE.*?"$/
                     and $lines[$i+1] =~ /^PERFORMER.*?$/) {
        my $tmp = $lines[$i];
        $lines[$i] = $lines[$i+1];
        $lines[$i+1] = $tmp;
    }
    

    Another option (which would work regardless of consecutiveness, and is arguably more elegant) would be to

    use List::MoreUtils qw(first_index);
    

    (up at the top, with your other use statements) and then do (inside &c, but outside the for loop):

    my $title_idx = first_index { /^TITLE.*?"$/ } @lines;
    my $performer_idx = first_index { /^PERFORMER.*?"$/ } @lines;
    
    if($title_idx >= 0 and $performer_idx >= 0 and $title_idx < $performer_idx)
    {
        # swap these lines:
        ($lines[$title_idx],$lines[$performer_idx]) =
            ($lines[$performer_idx],$lines[$title_idx]);
    }
    

    Is that what you’re after?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this part of code: ->filter('username', 'Security::xss_clean') ->filter('url', 'Security::xss_clean') ->filter('text', 'Security::xss_clean') but it
I have been working on this for the greater part of the day and
I have a property called IsSecureConnection that is part of my object's interface. This
I ask this question in anticipation as part of a project. I have experience
I have this code in jQuery, that I want to reimplement with the prototype
I have this dicT in my code that contain some positions. position = ['712,352',
I have this variable on the beginning of the code: enterActive = False and
I have this code somewhere in my plugin: $('tr', $this).hover(function(){ var cur_color = null;
i have code like this public class People { public string name { get;
I have found this example on StackOverflow: var people = new List<Person> { new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.