I might write your code this way (but note I haven't tested it).

use strict; use warnings; my $param_file = 'Params.txt'; open my $param_fh, '<', $param_file or die "Can't read '$param_file': $!"; my (@params, @charam); while (<$param_fh>) { my ($name,$value) = split /:/; push @params, $name; push @charam, $value; } my @actual = @charam; close $param_fh or die "Close failed: $!";

Some differences from your version:

The data you're reading would probably be best represented as a hash rather than a pair of arrays, but I say that without really knowing what you're going to do with it. If I were sticking all this in a hash, the code would look like this:

# same preamble my %value_of; while (<$param_fh>) { my ($name,$value) = split /:/; $value_of{$name} = $value; } # etc

Then you could get the stuff you have in @params and @charam using keys and values, but they'd be out of order.

If you're not familiar with hashes, I'd suggest you look into it. They are very useful.

I hope this helps.


In reply to Re: array print outside loop by kyle
in thread array print outside loop by shivakumar.balur

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.