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

Re: What would be the easier way

by CountZero (Bishop)
on Mar 04, 2013 at 02:17 UTC ( #1021564=note: print w/ replies, xml ) Need Help??


in reply to What would be the easier way

I would do it this way:

use Modern::Perl; use Data::Dump qw/dump/; my %heights; while (<DATA>) { push @{$heights{$1}}, $3 if /set\s+height\s+"([^"]+)"\s*("([^"]+)" +)?/; } say dump(%heights); __DATA__ set height "house" set height "house" "5 meter" set height "house" "10 yards" set height "table" "80 cm" set height "table" "30 inch"
Output:
( "house", [undef, "5 meter", "10 yards"], "table", ["80 cm", "30 inch"], )

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: What would be the easier way
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-12-20 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (94 votes), past polls