Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: removing x from a list

by tadman (Prior)
on Apr 20, 2001 at 08:56 UTC ( [id://74086]=note: print w/replies, xml ) Need Help??


in reply to Re: (zdog) Re: removing x from a list
in thread removing x from a list

It might be a lot easier if you just got what you wanted out of the readdir call first:
opendir (SONGS, $song_dir); @songs = sort grep { !/^\.\.?$/ } readdir(SONGS); closedir (SONGS);
So in one line you get the sorted, filtered, directory listing. In this case, grep will only allow those array elements that are not '.' and '..' to pass through.

Perl commands can be stacked, and the output of one flows right into the other, in a right to left manner. This means that your two statements:
@songs = readdir(SONGS); @songs = sort @songs;
Can actually be combined into a single equivalent one:     @songs = sort readdir(SONGS); Just as:
$x = $y; $x = $z + $x;
Can be converted to:    $x = $z + $y;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://74086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found