Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Parsing a table with variable columns on each line

by bichonfrise74 (Vicar)
on Oct 23, 2009 at 19:28 UTC ( [id://802958]=note: print w/replies, xml ) Need Help??


in reply to Parsing a table with variable columns on each line

Here's another way to solve your problem.
#!/usr/bin/perl use strict; while( <DATA> ) { chomp; my ($name, $val1, $val2, @val3) = split ( "\t" ); print join( "\t", ($name, $val1, $val2, $val3[$_]) ) , "\n" for (0 .. $#val3); } __DATA__ Apples 0.5 -10 Emma:17:15:14:18 Peter:2:7:4:1(Newline) Pears 0.7 -12 Alex:101:144:110:111(Newline) Oranges__0.8 -14 Shan:12:14:9:57 Heena:65:17:15:24 Rachel +:1:5:18:54(Newline)

Replies are listed 'Best First'.
Re^2: Parsing a table with variable columns on each line
by kikuchiyo (Hermit) on Oct 23, 2009 at 19:56 UTC
    Now available with more punctuation variables:

    #!/usr/bin/perl -l use strict; while( <> ) { chomp; local $, = "\t"; my ($name, $val1, $val2, @val3) = split ( "\t" ); print $name, $val1, $val2, $_ for @val3; }

    Update: Edited because I apparently didn't understand the original question. The point of setting $, instead of using join remains.
      Thank you. Job is done now.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found