Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Push a tab-delimited line into an array

by davido (Cardinal)
on Sep 28, 2011 at 15:26 UTC ( [id://928353]=note: print w/replies, xml ) Need Help??


in reply to Push a tab-delimited line into an array

push @array, $line will not "auto-split" the line into individual elements, so @array would receive just one element. If you use push( @array, split( /]s*,\s*/, $line ) ) you would be splitting $line into its own temporary array and then pushing all the elements onto @array. That would work if the none of the legitimate elements could somehow have a comma embedded in them. More robust CSV parsing is available from modules on CPAN.

Regarding the update: subroutine( $foo, $bar ) is just about the same as @array = ( $foo, $bar ); subroutine( @array ); The difference is that in the first case, @_ would be aliased to $foo and $bar, where in the second case it would be aliased to @array. So if you were to modify $_[0] in the first example, you would be modifying the contents of $foo, whereas in the second example you would be modifying the contents of $array[0]. Don't use the & unless you are either wielding sub references, or understand that it has a subtle effect on how @_ is passed. In other words, you probably don't need to use it.

Have fun!


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found