Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Words and Numbers to hash

by hippo (Abbot)
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;

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069883]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-27 08:29 GMT
Find Nodes?
    Voting Booth?