Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I would format it slightly, and then just read from the bottum up. Yes map and grep can be scary, but normaly reading them isn't hard (just figuring out how/when to use them is.
So now start at the bottom of the statment and read up. readdir $dir takes all the files in the directory $self->{update_dir} and pipes them into the grep above it. grep { /^\d+$/ && $_ <= $id } is a filter that only lets files that look like a number and are less than $id through. sort { $a <=> $b } sorts the files using a numeric sort (instead of cmp that would do an alphanumeric). map { "$self->{update_dir}/$_" } takes that list and adds the actual directory to the front of each element. The map in this case is kinda pointless because you then return only the last element, however the map means that you don't have to check if there was indeed a last element in the list to return. If you replaced the last return with return $self->{update_dir} || '/' || $files[-1]; then you would wrongly return the directory itself when there where no matching files. ___________ Eric Hodges In reply to Re: How do I un-map this code?
by eric256
|
|