[plug] A question for perl hackers
Mark Rattigan
rattigan at borg.apana.org.au
Wed Aug 21 23:37:59 WST 2002
> 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)
I think you're right. /^ */.
> (2) any number of continuous digits:
> [0-9*] (even bigger guess)
AFAIK, should be /[0-9]*/
> (3) followed by a single space
/ /
> Putting that all together I get:
> /^ *[0-9*] / (probably wrong!)
/^ *[0-9]* /
should be right, as far as I know.. I only started learning perl last week
at uni, so I may be slightly wrong too..
> 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.
$theline = " 3402138 aslkfj;dj;jksjfda blahblahblah......";
$theline =~ /^ *[0-9]* /;
$thematch = $&;
$thematch should then hold " 3402138 "
I'm hoping that's correct. I'm not absolutely sure.
Mark
More information about the plug
mailing list