rawatabhishek23 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am reading a tab seperated txt file into hash %table. When i use the following loop to print out specific content,
while ($i<=$#case) { if ($case[$i] eq "A"){ $pntname = "$table{name}_$case[$i]"; print $pntname;}}
The output is:

440_FI_301B

_A

My requirement is 440_FI_301B_A. I cannot understand why suffix '_A' goes to new line.

Replies are listed 'Best First'.
Re: suffix and hash string
by Anonymous Monk on Nov 07, 2010 at 05:17 UTC
    Its because $table{name} contains a newline. $table{name} contains a newline because you did not chomp.

    This is a frequent pitfall.

    In the future you should post a self contained program which demonstrates your problem, its easier to help that way. More tips like that can be found at How (Not) To Ask A Question

      Thanks!! I will check the FAQ.
Re: suffix and hash string
by choroba (Cardinal) on Nov 07, 2010 at 08:04 UTC
    Using grep might make your code more perlish:
    print $_,"_",$table{$_},"\n" for grep { $table{$_} eq "A" } keys %tabl +e;
      That's great Thanks!! I have started Perl 4days back and I am loving it.