Regarding the question: what does
{$playlist{$_} = 1 do: In a
while(<PLAYLIST>) loop like yours,
$_ contains the current record, so the statement you are wondering about sets a value of 1 in the hash for the current record.
One reason I can see why this would fail is if you have trailing spaces in your input file, because e.g.
'cool_song.mp3 ' is not the same as
'cool_song.mp3', which is what you will get from readdir. So this is how I would code the loop to avoid this:
while (<PLAYLIST>) {
s/#.*//g; #delete comments
s/(^\s*|\s*$)//g; #delete leading and trailing spaces
$playlist{$_} = 1 if /\.mp3$/;
}
To tell exactly what failed, of course, I would have to see also the input file.
Don't be discouraged, be cautious - we all deleted precious files some time or other.
pike
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.