Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: appending multiple values in an array

by kyle (Abbot)
on Mar 18, 2009 at 15:02 UTC ( [id://751473]=note: print w/replies, xml ) Need Help??


in reply to Re: appending multiple values in an array
in thread appending multiple values in an array

Run through Perl::Tidy and given <code> tags:

foreach $file (@cad_err_list) { chomp($file); $err_loan_id1 = `grep 'DataDictionary' $file`; @err_loan_id2 = split( /<pciOFACViolation>/, $err_loan_id1 ); $reqd_1 = $err_loan_id2[0]; @err_loan_id3 = split( /\s/, $reqd_1 ); $reqd_2 = $err_loan_id32; @err_loan_id = split( />/, $reqd_2 ); }

If that's actually your code, I don't really see how it relates to your question. There isn't a push anywhere in here. There isn't anywhere that you're "adding" to an array. All your array operations are assignments, so naturally they're not appended.

Usually to add to an array, we use push. In rare circumstances, unshift or splice.

What do you expect this to do that it's not doing? Did you Use strict and warnings?

Replies are listed 'Best First'.
Re^3: appending multiple values in an array
by raghu_shekar (Novice) on Mar 18, 2009 at 15:07 UTC
    im very new to perl, so if i store split( />/, $reqd_2 ) into a $variable and then give push ($variable, @array) inside the for loop, it should work??

      If you store the result of split into a scalar variable like $variable, it will be the number of fields that would have been returned if you'd used an array instead. As such, you probably want to set "@variable = split />/, $reqd_2" instead.

      The documentation for push has a better explanation for how to use it than I could supply. For your simple example, I'd write "push @array, $variable".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found