Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Words and Numbers to hash

by hippo (Deacon)
on Jan 08, 2014 at 23:42 UTC ( #1069883=note: print w/ replies, xml ) Need Help??


in reply to Words and Numbers to hash

No, it won't as I think will be obvious if you examine it. At the very least you should have keys with spaces in them which your regex won't cope with. Nor will it return the keys and values as separate fields.

This appears to work fine for your sample input:

my %stats = $content =~ /\s*([\w\s\/]+)\s+([\d.]+)/g;


Comment on Re: Words and Numbers to hash
Download Code
Re^2: Words and Numbers to hash
by mrras25 (Acolyte) on Jan 09, 2014 at 00:08 UTC

    this worked for the most part however, the first value I am getting is:

    $VAR1 = 'Opp Avg Score Margin'; $VAR2 = '10.8'; ...

    Instead of all the stuff leading up to it:

    Points/Game 80.5 Opp Points/Game 69.7 Avg Score Margin 10.8

    Why would you think that would be?

      ... the first value I am getting ...

      You may be expecting the hash to preserve the order of the fields extracted from the string. It won't. The only 'order' in a hash is the key/value paring of each hash element. You must somehow impose your own order on top of this inherent order. Perhaps see Tie::IxHash.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-07-23 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (139 votes), past polls