haukex++'s solution is good, and asks an important question, since your specs were not internally consistent regarding exactly 55. However, in case you were curious about your logic specifically:

Your version doesn't compile for me as-is: you have an unmatched curly bracket. Clean up the formatting to only do one thing per line, and you should see it:

if ($tempdesc >= 55) { if ($tempdesc2 =~ /electric/) { print FH_OUTFILE "\n"; } else { print FH_OUTFILE "free_batteries\n"; } } else { print FH_OUTFILE "\n"; } }

After removing that final } (shown in the SSCCE below): it seems to me to do what you want (assuming that "greater than 55" means "greater than or equal to 55", to match your >=).

use warnings; + # ALWAYS!!! use strict; + # ALWAYS!!! open FH_OUTFILE, '>&', \*STDOUT or die "err dup STDOUT = $!"; + # added for SSCCE foreach my $hashref( + # added for SSCCE {price => 55, title => 'i am expensive electric, and want a blank' + }, # added for SSCCE {price => 55, title => 'i am expensive gasoline, and want to print + something else'}, # added for SSCCE {price => 54, title => 'i am cheap electric, and want a blank' }, + # added for SSCCE {price => 54, title => 'i am cheap gasoline, and want a blank' }, + # added for SSCCE ) { + # added for SSCCE my $tempdesc = $hashref->{price}; my $tempdesc2 = $hashref->{title}; print FH_OUTFILE "-"x40, " START\n", "TITLE = '$tempdesc2' \@ PRIC +E = '$tempdesc'\n"; # added for SSCCE if ($tempdesc >= 55) { if ($tempdesc2 =~ /electric/) { print FH_OUTFILE "\n"; } else { print FH_OUTFILE "free_batteries\n"; } } else { print FH_OUTFILE "\n"; } print FH_OUTFILE '.'x40, " END\n"; + # added for SSCCE } + # added for SSCCE __END__ ---------------------------------------- START TITLE = 'i am expensive electric, and want a blank' @ PRICE = '55' ........................................ END ---------------------------------------- START TITLE = 'i am expensive gasoline, and want to print something else' @ +PRICE = '55' free_batteries ........................................ END ---------------------------------------- START TITLE = 'i am cheap electric, and want a blank' @ PRICE = '54' ........................................ END ---------------------------------------- START TITLE = 'i am cheap gasoline, and want a blank' @ PRICE = '54' ........................................ END

If our outputs are not your desired output, you'll need to clarify.


In reply to Re: If statement issue from a Noob by pryrt
in thread If statement issue from a Noob by tomdee27

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.