Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 ( [id://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...

Replies are listed 'Best First'.
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.

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,,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found