Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: 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 17:59 UTC ( #473516=note: print w/ replies, xml ) Need Help??


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

That would print a comma at the end of the output string, so you would need a way to prevent it, let's say, like this:

for (@matches) { print "$_,"; } print "\b ";

(Sorry about replacing foreach with for - someone mentioned to me earlier that it's faster and works the same way anyways)

Personally, I prefer Transient's way of doing things... although I don't quite understand why it parses split first and then map...

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


Comment on Re^3: How do i extract 3 variables from each line in a file, and print them to a new file
Download Code
Re^4: How do i extract 3 variables from each line in a file, and print them to a new file
by Transient (Hermit) on Jul 08, 2005 at 18:12 UTC
    good question.. hope I'm not overstepping my bounds by responding..(and I hope I'm right!)

    map { $_ =~ s/\D//g; $_ } split(':',(split(' ',$_))[-1]);
    is equivalent to
    my @split_results = split(':',(split(' ',$_))[-1]); map { $_ =~ s/\D//g; $_ } @split_results;
    because map BLOCK LIST has to run the BLOCK for each LIST element (setting each LIST value to $_), it must know what is in that LIST. Hence, the execution of the split(s) before the execution of the BLOCK (and therefore the map).
      Oh, I see. I guess it's the space between map{} and split that threw me off as i'm not used to using map yet :)

      Thanks for nice explanation as well. (I'll ++ you later as I've used up my votes for today already ;)

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

Re^4: How do i extract 3 variables from each line in a file, and print them to a new file
by pbeckingham (Parson) on Jul 08, 2005 at 19:26 UTC

    for is faster to type than foreach, and makes your program 3 bytes smaller, but apart from that, it has no effect.



    pbeckingham - typist, perishable vertebrate.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-12-21 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls