in reply to No output to screen or output file

Single quotes prevent variable interpolation. Change:
if('$hash{$filter[$c]->[4]}' eq '$filter')

to:

if($hash{$filter[$c]->[4]} eq $filter)

This is detected by perlcritic

Replies are listed 'Best First'.
Re^2: No output to screen or output file
by dkhalfe (Acolyte) on Jul 24, 2012 at 17:23 UTC

    Dont I have to format my code with those single quotations when comparing string values? For that reason, I have the program check and differentiate between strings and numerical values (string or num) - I posted a question earlier and the solution to my problem was to include these single quotations. I believe I kept getting an error when trying to run the program without them.

      Here's the quick explanation. What does this piece of code mean?

      my $result = something;

      Is something a function call? Is it a string literal?

      You have to make your intent clear to Perl and to human readers. Make it unambiguously a function call with:

      my $result = something();

      ... or a string with:

      my $result = 'something';

      Where it's not obvious what you mean, make it obvious. That's what strict was complaining about.


      Improve your skills with Modern Perl: the free book.

Re^2: No output to screen or output file
by dkhalfe (Acolyte) on Jul 24, 2012 at 17:26 UTC

    Use of uninitialized value in string eq at trial1.pl line 128, <IN> line 1767.

    I removed the single quotations and get the following error. When I put the quotes back in, the program succesfully runs but no output is printed to my output file.

      Sounds like your input file is 1766 lines long and you are trying to read in the next line after you've already reached the end. Can you show the code where you read in your file?

        Here is my code for reading in the input file

        open (FILTER,"$filter_file"); my @filter; <FILTER>; # read one line from the file [HEADERS] while (<FILTER>) { # read other lines chomp; # remove "\n" from the end of the line push @filter,[(split /\t/,$_)]; # create an array of the line +by s$ } @filter = sort { $a->[5] <=> $b->[5] } @filter; # sort the array #--------------------------------------------------------------------- +----$ #PRINTS REFERENCES TO ARRAY FROM LEAST TO GREATEST REGARDING 'ORDER' C +OLUMN print Dumper \@filter; #### For Debugging Purposes