tomdee27 has asked for the wisdom of the Perl Monks concerning the following question:
Hi: I am fairly new to PERL so I apologize for the simplicity of my issue. I'm trying to create an If/Else statement that will look at the contents of two variables from a data extraction ($hashref.) I need to print a blank in a file if the price field is less than 55. I also need the output to be blank if the price field is greater than 55 but the title field contains the word "electric." If the item is greater than 55 without the word electric in the title, I need the phrase "free_batteries" to be output. I've almost got it working. If the item is less than 55, it works, but if the item is greater than 55 with the word "electric" in the field, it's adding "free_batteries" to the record. I'm lost as to what I'm doing wrong. I'm sure this is a simple fix for someone who knows PERL. Any help you can lend is greatly appreciated. - Tom
$tempdesc = $hashref->{price}; $tempdesc2 = $hashref->{title}; if ($tempdesc >= 55) { if ($tempdesc2 =~ /electric/) {print FH_OUTFILE "\n";} else {print FH_OUTFILE "free_batteries\n";}} else {print FH_OUTFILE "\n";} }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: If statement issue from a Noob
by haukex (Archbishop) on Oct 04, 2017 at 15:50 UTC | |
Re: If statement issue from a Noob
by pryrt (Abbot) on Oct 04, 2017 at 16:18 UTC | |
Re: If statement issue from a Noob
by 1nickt (Canon) on Oct 04, 2017 at 16:50 UTC | |
by holli (Abbot) on Oct 04, 2017 at 18:59 UTC | |
by 1nickt (Canon) on Oct 04, 2017 at 20:01 UTC | |
by holli (Abbot) on Oct 04, 2017 at 20:36 UTC | |
Re: If statement issue from a Noob
by Laurent_R (Canon) on Oct 04, 2017 at 17:50 UTC | |
Re: If statement issue from a Noob
by holli (Abbot) on Oct 04, 2017 at 19:05 UTC | |
by tomdee27 (Initiate) on Oct 04, 2017 at 19:16 UTC | |
by haukex (Archbishop) on Oct 04, 2017 at 19:33 UTC | |
by Laurent_R (Canon) on Oct 04, 2017 at 20:37 UTC |