Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Please fix my writing style

by juster (Friar)
on Nov 22, 2008 at 19:48 UTC ( [id://725351]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Please fix my writing style
in thread Please fix my writing style

You may want to use dragonchild's solution because it is easier to understand.

You will need to read up on "do" to understand it better. do is not a loop, using next will only exit the block. Let me try to avoid using do.

"Slurping" a file means reading all its data into a string. There alot of ways to do that, search for file slurping on Super Search to understand it better.

Once you have the file data the regexp is easier to understand:

my $teamdata; for my $line (<DATA>) { $teamdata .= $line; } # If you assign a global match to a list, it stores # everything that matched in parenthesis to that list. # A hash can be created using a list eg: (key, val, key, val) my %teams = $teamdata =~ /^([A-Z ]+): *(.+)$/mg;

The problem with the code I supplied is \s matches whitespace, including a newline. If you replace \s with just a space character, it will skip the bad lines.

The important thing to learn is how the global match /<regexp>/g can return a list of results, or the number of matches depending on what you assign it to. See perlretut (ie Extracting matches), perlre, search here, etc.

Replies are listed 'Best First'.
Re^4: Please fix my writing style
by convenientstore (Pilgrim) on Nov 23, 2008 at 03:53 UTC
    i definitely need to read more but your solution works well for me
    thank you

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found