Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Log File Parsing using "split"

by TedPride (Priest)
on May 19, 2006 at 22:13 UTC ( [id://550598]=note: print w/replies, xml ) Need Help??


in reply to Log File Parsing using "split"

On a hopefully related note, you can assign your fields to variables all at once using a format like the following:
($name, $city, $state, $zip) = (split / /, $_)[4,5,6,8];

Replies are listed 'Best First'.
Re^2: Log File Parsing using "split"
by nobull (Friar) on May 20, 2006 at 12:02 UTC
    ($name, $city, $state, $zip) = (split / /, $_)[4,5,6,8];

    I think the OP is probably with the default behavioiur of split() - nothing to be gained by spelling it out.

    It would be very unusal in real code that in an assignement statement such as the one above you would really want to overwrite the values of four existing variables. It would be far more common that this is the point in the code at which these four variables would be introduced.

    Newcommers to Perl often have problems with variable declaration. When presenting issolated code fragments all assignment statements should have a my() if is more likely than not that they would need one in any well-written real code.

    my ($name, $city, $state, $zip) = (split)[4,5,6,8];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found