I have these types of lines that repeat :
$content = "Points/Game 80.5 Opp Points/Game 69.7 Avg Score Margin +
+10.8 Opp Avg Score Margin -10.8 Assists/Game 16.5 Opp Assists/Game
+ 12.2 Total Rebounds/Gm 39.3 Opp Total Rebounds/Gm 36.7 Assists/FG
+M 0.557 Opp Assists/FGM 0.472 Assists/Turnover 1.259 Opp Assists/T
+urnover 0.712";
$content .= "Effective FG 51.0 Opp Effective FG 47.5 FTA/FGA 0.409
+ Opp FTA/FGA 0.348 Free Throw 65.4 Opp Free Throw 64.6 Three Po
+int 29.2 Opp Three Point 30.4 Two Point 53.6 Opp Two Point 48.
+2 Shooting 47.3 Opp Shooting 43.5 Shooting Efficiency 1.080 Opp
+ Shooting Efficiency 1.007 FGM/Game 29.5 Opp FGM/Game 25.8 FGA/Gam
+e 62.5 Opp FGA/Game 59.3 3PM/Game 4.7 Opp 3PM/Game 4.8 3PA/Game 1
+6.1 Opp 3PA/Game 15.9 FTM/Game 16.7 Opp FTM/Game 13.3 FTA/Game 25
+.5 Opp FTA/Game 20.6
1st Half Pts/Gm 39.8 Opp 1st Half Pts/Gm 33.6 2nd Half Pts/Gm 40.6
+Opp 2nd Half Pts/Gm 36.1 OT Pts/Gm -- Opp OT Pts/Gm -- ";
$content .= "Off Rebounds/Gm 12.1 Opp Off Rebounds/Gm 10.8 Def Rebou
+nds/Gm 23.2 Opp Def Rebounds/Gm 21.2 Off Rebound 36.3 Opp Off Reb
+ound 31.7 Def Rebound 68.3 Opp Def Rebound 63.7
Blocks/Game 5.4 Opp Blocks/Game 4.7 Block 9.1 Opp Block 7.5
Steals/Game 10.1 Opp Steals/Game 7.7 Steals/Play 11.7 Opp Steals/Pl
+ay 8.8
Turnovers/Game 13.1 Opp Turnovers/Game 17.1 Turnovers/Play 14.9 Opp
+ Turnovers/Play 19.8";
$content .= "Personal Fouls/Gm 18.5 Opp Personal Fouls/Gm 20.8 Perso
+nal Fouls/Play 21.4 Opp Personal Fouls/Play 23.7";
And I would like to extract each one to be a word/Number key/value in a hash. Example:
Points/Game => 80.5,
Opp Points/Game => 69.7,
Avg Score Margin => +10.8
I have tried the following and it doesn't give me the desired output:
my %stats = $content =~ /(\w+\s+\d+)/;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|