Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do i extract 3 variables from each line in a file, and print them to a new file

by bofh_of_oz (Hermit)
on Jul 08, 2005 at 16:14 UTC ( #473468=note: print w/ replies, xml ) Need Help??


in reply to How do i extract 3 variables from each line in a file, and print them to a new file

I believe this line should do it:

$_ =~ /(\d+)ms/g; print "$1,$2,$3\n";

UPDATE: I agree with comments since I've got the same result... Here's what worked:

$_ = "3434 34456... 321ms:543ms:45ms"; ($d, $e, $f) = ($_ =~ /(\d+)ms/g); print "$d,$e,$f\n";

--------------------------------
An idea is not responsible for the people who believe in it...


Comment on Re: How do i extract 3 variables from each line in a file, and print them to a new file
Select or Download Code
Re^2: How do i extract 3 variables from each line in a file, and print them to a new file
by davidrw (Prior) on Jul 08, 2005 at 16:22 UTC
    perl -le '$_="123ms456ms789ms"; $_ =~ /(\d+)ms/g; print "$1,$2,$3\n"; +'
    prints just 123,,
Re^2: How do i extract 3 variables from each line in a file, and print them to a new file
by fishbot_v2 (Chaplain) on Jul 08, 2005 at 16:30 UTC

    Capturing doesn't work like that. You are overwriting $1 for each match.

    Try something like

    my @nums = $_ =~ /(\d+)ms/g;
    if you want to capture all matches from a /g.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-09-22 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (189 votes), past polls