Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl Regex Filename Not Matching
    primarykey
    data
    text
    <p>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:</p> <pre><code>$name = (split (/[ ]*CD[ ]*1/i, $in_avi))[0]; </code></pre> <p>Anyone know what I need to do to correct it?</p> <p>/Edit: The full code is this:</p> <pre><code>#!/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-&gt;{'part2'} = $in_avi_2; last; } } if (defined $rec-&gt;{'part2'}) { for my $out_avi (@out_avis) { if ($out_avi =~ /$name\.avi$/i) { $rec-&gt;{'output'} = $out_avi; last; } } unless (defined $rec-&gt;{'output'}) { $rec-&gt;{'part1'} = $in_avi; $rec-&gt;{'output'} = "$MOVIE_OUT_PATH\\$name.avi"; push (@movies_formatted, $rec); } } } } } else { my $rec; # Temporary hash variable for my $name (@MOVIES_TO_CONVERT) { $rec = {}; $rec-&gt;{'part1'} = "$MOVIE_IN_PATH\\$name CD 1.avi"; $rec-&gt;{'part2'} = "$MOVIE_IN_PATH\\$name CD 2.avi"; $rec-&gt;{'output'} = "$MOVIE_OUT_PATH\\$name.avi"; push (@movies_formatted, $rec); } } for my $movie (@movies_formatted) { my $convert_cmd = "\"$AVIDEMUX\" --load \"" . $movie-&gt;{'part1'} . "\" --append \"" . $movie-&gt;{'part2'} . "\" --force-smart --save \"" . $movie-&gt;{'output'} . "\" --quit"; print "$convert_cmd\n"; die "Unable to convert $movie-&gt;{'output'}!\n" if (system "$convert_cmd"); } </code></pre> <p>Script from <a href="http://www.neowin.net/forum/topic/1128384-batch-file-to-run-command-on-joining-video-files" rel="nofollow">http://www.neowin.net/forum/topic/1128384-batch-file-to-run-command-on-joining-video-files</a> by xorangekiller.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload