Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: regexp's

by Cybercosis (Monk)
on Oct 03, 2000 at 10:37 UTC ( #35068=note: print w/replies, xml ) Need Help??


in reply to regexp's

Well, if it's in a file, I'd do this:
@ARGV = filename.txt; while(<>) { /^(\d)\s+time\s+\d{2}\:\d{2}\:\d{2}\s+(\d+)/; $hash{$1} = $2; }
-------------------update-------------- as per merlyn's advice: (godz it's hard not to try to make spaceballs jokes...)
while(<>) { if(/^(\d)\s+time\s+\d{2}\:\d{2}\:\d{2}\s+(\d+)/) { $hash{$1} = $2; } }
or didn't i read something about this possibly being acceptable:
while(<>) { { /^(\d)\s+time\s+\d{2}\:\d{2}\:\d{2}\s+(\d+)/; $hash{$1} = $2; } }
since the enclosing {} puts it in a seperate block? i fully expect to be waaaay off on this.

Replies are listed 'Best First'.
RE: Re: regexp's
by merlyn (Sage) on Oct 03, 2000 at 18:14 UTC
    Do not use $1 except after you've verified that the match was successful, else you will get the previous $1. That would not have been fatal here, but if you'd been accumulating rather than setting, you'd get some odd stuff.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://35068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-08-08 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?