This is my first reply, so if something isn't formatted just right, I will apologize in advance. But maybe the meaning will show through in any event :)

I am by no means a monk, but being a full time Perl programmer, I know a lot of shortcuts. (Correct short cuts, that is, not hacks.) So, I kinda ramble over most of the code, I don't mean to step on toes or say the way you have it isn't right.. it's just a shorter way of doing the same thing. Like your argument code:

my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 2) { die ("\n You haven't entered enough parameters !!\n\n"); }
I would write it like this:
die "\nYou haven't entered enough parameters !!\n\n" unless $ARGV[1];
Does the same thing, just easier to type. Next, you have:
open (INFILE, $ARGV[0]) or die "unable to open file"; open (OUTFILE, ">$ARGV[1]");
If this is for end-users, you are right in not being very descriptive with your error messages. However, especially during debugging, I would be a lot more loud and graphic with your errors, something like:
open (INFILE, $ARGV[0]) or die "unable to open file $ARGV[0]: $!\n"; open (OUTFILE, ">$ARGV[1]") or warn "unable to open file $ARGV[1]: $!\ +n";
should work fine. Again, if it's for end-user use, turn off the errors once it's working if you need to. Next you have:
-snip- @array = (); @array = split (/\s+/, $line); -snip- # if i print $self here it prints out all of the results from that cat +ergory
I think the post above me covered this, and probably already answered your main question. The reason that $self is is valid here is because the array is still valid. Each time you run the loop you are clearing the array, thus the one entry that you are displaying is probably the last entry in the file you read in, because the array isn't cleared at the end. Next you have:
$choice = <STDIN>; # remove the newline character from the chosen option. chomp $choice; if ($choice eq 1)
Again, what you have works just fine, but since you are only reading in one character, why not just use 'getc'? Something like this:
if (getc(STDIN) eq "1")
Since getc only gets one character, no need for a chomp, and you save yourself a variable use. So, I hope that I got across the help I wanted to give without seeming to pick nits. Your code worked just fine (excepting the reason for the post of course), it's just that personally, I am always looking for a better way to do things, and in this case, I saw a few that I thought I would share.

In reply to Re: why won't is print every value??? by erasei
in thread why won't is print every value??? by Anonymous Monk

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.