http://qs1969.pair.com?node_id=928353


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