[plug] A question for perl hackers

Lyndon Kroker ljkroker at netvigator.com
Wed Aug 21 23:00:00 WST 2002


I am trying to grab the filesize in bytes from a listing like:

   310272 Aug 21 22:18 inbox
  5193576 Jul  7 09:45 lyndon
        0 Aug 12 09:58 mailing lists
    32720 Jun 10 20:10 mchoice
    46513 Aug 16 16:18 netvigator
        0 Aug 21 20:04 outbox
 10069208 Aug 21 20:04 sent-mail
  2377093 Aug 21 19:33 trash

As I step through an array with foreach I would like to assign the filesize 
in bytes (the first number) to a variable.  I need to match:

(1) zero or any number of spaces occuring at the beginning of the string: 
^  *  (a guess)

(2) any number of continuous digits:
[0-9*]  (even bigger guess)

(3) followed by a single space

Putting that all together I get:
/^ *[0-9*] ./  (probably wrong!)

The problem is that I don't want to just match a pattern, I want to assign 
the match to a variable and this is what has me a bit lost.  In case it is 
not blindingly obvious, I am just learning perl.  I have written a few cgi 
scripts before but that's about it.

I am guessing that it would take me about 2 to 4 hours to figure this out on 
my own whereas an experienced perl hacker would take about 2 to 4 seconds.  
So, in the interest of efficency, I humbly ask for assistance.

Many thanks,

Lyndon
Debian 3.0 (2.4.18)



More information about the plug mailing list