[plug] A question for perl hackers
Trevor Phillips
T.Phillips at murdoch.edu.au
Fri Aug 30 09:45:38 WST 2002
I'm a bit late to this thread, but here's my $0.02...
On Thursday 22 August 2002 09:01, Anthony J. Breeds-Taurima wrote:
>
> Just to show you anonther way:
>
> while (<>) {
> chop; # get rid of the \n
> $_ =~ s/^\s*//; # Remove leading whitespace
> # Now split the line on 1 or more whitespace chars
> # and place each part into a var.
> my ($size, $month, $day, $time, $name) = split(/\s+/);
>
> print "File : $name is $size bytes and ".
> "was last touched at $time on $day/$month\n";
> }
I too would split on \s+ in this case. It nicely divides up the properties
into an array.
> I a regex, you can wrap an expression in ()'s and it will remember and
> assign them to $1 -> $9 eg:
> /^(.)(.)(.)(.)(.)/
Or if you specifically want the first 5 characters as $1, you can use:
/^(.{5})/
Similarly, the first five digits OR spaces:
/^([\d\s]{5})/
--
. Trevor Phillips - http://jurai.murdoch.edu.au/ .
: Web Technical Administrator - T.Phillips at murdoch.edu.au :
| IT Services - Murdoch University |
>--------------------------------------------------------------------<
| On nights such as this, evil deeds are done. And good deeds, of /
| course. But mostly evil, on the whole. /
\ -- (Terry Pratchett, Wyrd Sisters) /
More information about the plug
mailing list