in reply to If statement issue from a Noob

Hi, in plain human language you are saying "free batteries only with orders worth $55 or more for non-electric items".

So say that in Perl:

use strict; use warnings; ... open my $OUT, '>', $filename or die $!; print $OUT "free_batteries" if $price >= 55 and $title !~ /electric/; print $OUT "\n"; # in all cases

Update: Changed to use postfix conditional to avoid any debate over brackets, braces or indentation ;-)


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: If statement issue from a Noob
by holli (Abbot) on Oct 04, 2017 at 18:59 UTC
    And who needs batteries for a non-electric item? I think the OP wants something different. Free batteries for > $55 electric items.


    holli

    You can lead your users to water, but alas, you cannot drown them.

      I'm pretty sure the OP said:

      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.


      The way forward always starts with a minimal test.
        I know. I can read. Still makes no ... Oh, "electric" means cable driven here. I was thinking like "pencil vs vibrator" instead of "tablet vs tv".


        holli

        You can lead your users to water, but alas, you cannot drown them.