Dear Monks,
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.