Hi, I am passing two arrays to a subroutine and getting some wierd results. Here is my code snippet
@MLR_file = <MLR>; # read in file 1 data $MLR_file[2] =$MLR_file[1] = $MLR_file[0]; # modify it @MLR_file2 = <MLR2>; #read in set2 data $MLR_file2[2] =$MLR_file2[1] = $MLR_file2[0]; # modify it &printFile (@MLR_file, @MLR_file2); sub printFile { #print the contents of each array to the correct ouput file my @file = $_[0]; my @file2 = $_[1]; foreach $line(@file) { print OUT "$line"; } foreach $line(@file2) { print OUT2 "$line"; }
Basically I'm reading files into an array, modifying them, and writing the new output to a new file. The trouble is that my new output file(s) only has one line in it (there should be 96 lines of output).

I tried passing the arguments as references, without really know why. When I more my ouput file(s) looked like this

ARRAY(0xd3a2c) ARRAY(0xd3a98)
Any explaination on this would be appreciated. Thank you.

In reply to passing arrays to subroutines by indapa

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.