Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to learn to write more compact code. I currently have a bit of a script that builds a hash of all the AVI files in my movies directory (see below). It works just fine, but it seems like I could tighten this up eliminating my initial regex and/or the loop over the @temp array.
In case it's not obvious, the values of the hash are a string with the season and episode (if it exists) of each AVI
Any suggestions on clever ways to make this code more compact?
our $dir = `dir $movies\\*.avi /s`; our %inventory my @temp=$dir =~ /,\d{3} ((.*?)\.avi)/gi; for $temp (@temp) { if (($temp=~/(.+?)(\d{1,2}x\d{1,2})/i) or ($temp=~/(.*?)s\d{1,2}e\d{1,2})/i) ) { $inventory{$1}=$2; } }
If it matters, I am running this script on Windows 7 x64 and Strawberry Perl ver 5.12.1.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing compact conditional regex's
by moritz (Cardinal) on Feb 06, 2011 at 12:20 UTC | |
|
Re: Writing compact conditional regex's
by ambrus (Abbot) on Feb 06, 2011 at 14:40 UTC | |
|
Re: Writing compact conditional regex's
by furry_marmot (Pilgrim) on Feb 06, 2011 at 20:29 UTC | |
|
Re: Writing compact conditional regex's
by Anonymous Monk on Feb 07, 2011 at 03:03 UTC |