Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Push a tab-delimited line into an array by davido
in thread Push a tab-delimited line into an array by koolgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2022-10-05 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (23 votes). Check out past polls.

    Notices?