Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
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
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: (10)
As of 2015-07-30 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls