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 9122461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:06:36+00:00 2026-06-17T06:06:36+00:00

I’m running a Perl script that someone else wrote for me, and I’ve noticed

  • 0

I’m running a Perl script that someone else wrote for me, and I’ve noticed that the following regex doesn’t seem to match my files which are named "Film CD 1.avi", "Film2 CD 1.avi", etc.:

$name = (split (/[ ]*CD[ ]*1/i, $in_avi))[0];

Does anyone know what I need to do to correct it?

The full code is this:

#!/usr/bin/perl

use strict;

########################################################################
#                                                Configuration Details                                          #
########################################################################

# Array of movies to convert
my @MOVIES_TO_CONVERT; # = ('The Figher', 'The Fifth Element');

# Directory where the split AVI files are stored
my $MOVIE_IN_PATH = 'D:\split';

# Directory where the combined AVI files will be stored
my $MOVIE_OUT_PATH = 'D:\combined';

# Full path to the avidemux executable
my $AVIDEMUX = 'C:\Program Files (x86)\Avidemux\avidemux.exe';

########################################################################
#                                                          Functions                                                      #
########################################################################

# Return an array of all the AVI files in the specified directory.
sub get_avis_in_directory
{
        my $dh; # Directory handle
        my $dir; # Current directory
        my @avis; # Array of file names to return

        opendir ($dh, $dir = shift) or die "Failed to open directory $dir: $!\n";
        while (readdir $dh)
        {
                next if (/^\.{1,2}/);
                $_ = $dir . "\\" . $_;
                push (@avis, $_) if (-f $_ and /.*\.avi$/i);
        }
        closedir $dh;

        return (@avis);
}

########################################################################
#                                                         Entry Point                                                    #
########################################################################

die "Input directory $MOVIE_IN_PATH does not exist!\n" unless (-d $MOVIE_IN_PATH);
die "Output directory $MOVIE_OUT_PATH does not exist!\n" unless (-d $MOVIE_OUT_PATH);

# This variable represents the actual names and paths of movies to be converted.
# It will either be built from the files specified in @MOVIES_TO_CONVERT manually, or
# built dynamically based on the files in the source and destination paths.
my @movies_formatted; # Array of hashes of movies to convert

if ($#MOVIES_TO_CONVERT == -1)
{
        my @in_avis; # Array of AVI files in the input directory
        my @out_avis; # Array of AVI files in the ouput directory

        @in_avis = get_avis_in_directory ($MOVIE_IN_PATH);
        @out_avis = get_avis_in_directory ($MOVIE_OUT_PATH);

        for my $in_avi (@in_avis)
        {
                if ($in_avi =~ /.*[ ]*CD[ ]*1\.avi$/i)
                {
                        my $rec; # Temporary hash variable
                        my $name; # Name of the move we are processing
                        $name = (split (/[ ]*CD[ ]*1/i, $in_avi))[0];
                        $name = (split (/$MOVIE_IN_PATH[\\\/]{1}/i, $name))[1];

                        for my $in_avi_2 (@in_avis)
                        {
                                if ($in_avi_2 =~ /^$MOVIE_IN_PATH\\$name[ ]*CD[ ]*2\.avi$/i)
                                {
                                        $rec->{'part2'} = $in_avi_2;
                                        last;
                                }
                        }

                        if (defined $rec->{'part2'})
                        {
                                for my $out_avi (@out_avis)
                                {
                                        if ($out_avi =~ /$name\.avi$/i)
                                        {
                                                $rec->{'output'} = $out_avi;
                                                last;
                                        }
                                }

                                unless (defined $rec->{'output'})
                                {
                                        $rec->{'part1'} = $in_avi;
                                        $rec->{'output'} = "$MOVIE_OUT_PATH\\$name.avi";
                                        push (@movies_formatted, $rec);
                                }
                        }
                }
        }
}
else
{
        my $rec; # Temporary hash variable

        for my $name (@MOVIES_TO_CONVERT)
        {
                $rec = {};
                $rec->{'part1'} = "$MOVIE_IN_PATH\\$name CD 1.avi";
                $rec->{'part2'} = "$MOVIE_IN_PATH\\$name CD 2.avi";
                $rec->{'output'} = "$MOVIE_OUT_PATH\\$name.avi";
                push (@movies_formatted, $rec);
        }
}

for my $movie (@movies_formatted)
{
        my $convert_cmd = "\"$AVIDEMUX\" --load \"" . $movie->{'part1'} . "\" --append \"" . $movie->{'part2'} . "\" --force-smart --save \"" . $movie->{'output'} . "\" --quit";
        print "$convert_cmd\n";
        die "Unable to convert $movie->{'output'}!\n" if (system "$convert_cmd");
}

The script is from http://www.neowin.net/forum/topic/1128384-batch-file-to-run-command-on-joining-video-files by xorangekiller.

  • 1 1 Answer
  • 0 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-06-17T06:06:37+00:00Added an answer on June 17, 2026 at 6:06 am

    The backslash in $MOVIE_IN_PATH is being removed by interpolating it into the regular expression. Change both the split commands to

    $name = (split(/\Q$MOVIE_IN_PATH\E[\\\/]{1}/i, $name))[1];
    

    i.e. add the \Q … \E to escape any regex metacharacters.

    Your friend doesn’t appear to be a particularly good Perl programmer. You may want to try this code instead.

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    use File::Basename;
    use File::Spec;
    
    # Configuration Details
    #######################
    
    # Array of movies to convert
    my @MOVIES_TO_CONVERT;    # = ('The Fighter', 'The Fifth Element');
    
    # Directory where the split AVI files are stored
    my $MOVIE_IN_PATH = 'D:\split';
    
    # Directory where the combined AVI files will be stored
    my $MOVIE_OUT_PATH = 'D:\combined';
    
    # Full path to the avidemux executable
    my $AVIDEMUX = 'C:\Program Files (x86)\Avidemux\avidemux.exe';
    
    sub get_avis_in_directory {
      opendir my $dh, $MOVIE_IN_PATH or die $!;
      return grep {
        /\.avi$/ and -f File::Spec->catfile($MOVIE_IN_PATH, $_)
      } readdir $dh;
    }
    
    -d $MOVIE_IN_PATH or die qq(Input directory "$MOVIE_IN_PATH" does not exist!\n);
    -d $MOVIE_OUT_PATH or die qq(Output directory "$MOVIE_OUT_PATH" does not exist!\n);
    
    my @movies_formatted;    # Array of hashes of movies to convert
    
    if (@MOVIES_TO_CONVERT) {
    
      for my $name (@MOVIES_TO_CONVERT) {
        my $rec = {};
        $rec->{part1}  = File::Spec->catfile($MOVIE_IN_PATH, "$name CD 1.avi");
        $rec->{part2}  = File::Spec->catfile($MOVIE_IN_PATH, "$name CD 2.avi");
        $rec->{output} = File::Spec->catfile($MOVIE_OUT_PATH, "$name.avi");
        push @movies_formatted, $rec;
      }
    }
    else {
    
      my @in_avis  = get_avis_in_directory($MOVIE_IN_PATH);
    
      for my $in_avi (@in_avis) {
    
        next unless $in_avi =~ /^(.+?)\s*CD\s*1\.avi$/i;
    
        my $name = $1;
    
        my $rec = {};
        $rec->{part1} = $in_avi;
        ($rec->{part2}) = grep /^\Q$name\E\s*CD\s*2\.avi$/i, @in_avis;
    
        if ($rec->{part2}) {
          $rec->{$_} = File::Spec->catfile($MOVIE_IN_PATH, $rec->{$_}) for qw/ part1 part2 /;
          $rec->{output} = File::Spec->catfile($MOVIE_OUT_PATH, "$name.avi");
          push @movies_formatted, $rec;
        }
    
      }
    }
    
    for my $movie (@movies_formatted) {
    
      my $convert_cmd = sprintf '"%s" --load "%s" --append "%s" --force-smart --save "%s" --quit',
          $AVIDEMUX, @{$movie}{qw/ part1 part2 output /};
      print "$convert_cmd\n";
    
      die "Unable to convert $movie->{'output'}!\n" if (system $convert_cmd);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have an autohotkey script which looks up a word in a bilingual dictionary

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.