[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Perl tips



On Mon, Nov 25, 2002 at 03:58:15PM +0000, Alex Hudson wrote:
> Or, you can just write a function:
> 
> sub file2num {
> 	my ($file) = @_;
> 	return if ($file !~ /-(\d\d)-(\d\d)-(\d{4})$/);
> 	return "$2$3$4";
> }
> 
> my  [at] list = sort { file2num($a) <=> file2num($b) } sort  [at] files;
> 
> Depending on how long the list is, a function is usually a better idea,
> since you could conceivably have a very long list :o)

Except of course that the function will be called NlogN times, which
may then make it rather slow.

> BTW, I think you want the ufo operator in your example, like mine?

Either will work in this example.


(PS - I don't think you really meant $2$3$4 :-)
(PPS - my Perl's bigger than your Perl ;-)


-- 
"There's something wrong with our bloody ships today, Chatfield."
Admiral Beatty at the Battle of Jutland, 31st May 1916.
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.