Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: parsing data in a file

by talexb (Canon)
on Nov 02, 2010 at 16:46 UTC ( #869042=note: print w/ replies, xml ) Need Help??


in reply to parsing data in a file

You should be programming defensively here:

my ($fname,$lname) = split(" ",$name);

Instead of that, I'd recommend

# If there are two names separated by a space .. my ($fname,$lname); if ( $name =~ /\w+\s\w+/ ) { # Separate them into first and last names. ($fname,$lname) = split(" ",$name); } else { # Otherwise, decide what to do with just a single name. # Use the name as a last name? Die? Ignore? }
Don't assume that your input's always going to be clean.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


Comment on Re: parsing data in a file
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-07-02 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls