Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
see Markup in the Monastery before putting code
the problem is that the data in the final array(result array) is getting over written and not appended. please help me out.... :(
what you mean by final array here?
one more hint, every time inside the forloop you are using so may intermediate variables and it will get overwritten.
try printing those values inside the for loop and ensure that it prints properly, rather than seeing the values after the for loop.
according to your code the variables $err_loan_id1,@err_loan_id2,$reqd_1,@err_loan_id3,$reqd_2,@err_loan_id will have the values that belong to the last file in the array @cad_err_list if you print the values at the end of for loop
if you need only the final array then just have a hash declared at a global scope and maintain the intermediate variables like this.
inside forloop @err_loan_id = split(/>/,$reqd_2); $err_loan_id{$file} = [@err_loan_id];
now for every file the final array is saved, you can print at the end of for loop, try printing using Data::Dumper::Dumper you will recognize the output clearly now
similarly if you want to save all the intermediate values do like this inside your for loop.
$err_loan_id{$file} = [ $err_loan_id1,[ @err_loan_id2],$reqd_1,[@err_l +oan_id3],$reqd_2,[@err_loan_id]];
I think I have answered your question..

but you will end up in using more memory if you have so many files in @cad_err_list and because of that if the values in the intermediate variables are huge, then plainly using the methods shown by me is prone to problems, take care.


Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

In reply to Re^3: appending multiple values in an array by targetsmart
in thread appending multiple values in an array by raghu_shekar

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 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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found