in reply to split efficiency needed

Split is quite efficient on short and simple strings. The following is what I normally do, with a one-liner, not necessarily better, but less typing.
my $var = '-rwxr-xr-x 1 svcn-3 ymn-3 7618486 Jan 20 21:42 20040120- +299-x49.exe'; printf "Update at %s %s at %s hours\n", (split /\s+/, $var)[5,6,7];

Here's another method I can think of that might improve the efficiency a bit if the string is long and has plenty of spaces. This approach only remembers the required fields and throws away the rest.
printf "Update at %s %s at %s hours\n", ($var =~ /^(?:\S+\s+){5}(\S+)\s+(\S+)\s+(\S+)/);

Replies are listed 'Best First'.
Re: Re: split efficiency needed
by Anonymous Monk on Jan 21, 2004 at 15:18 UTC
    thanks