in reply to Auto Fill

Hello Monks,
After stepping back from the script I finally figured it out on my own...sometimes you just have to step back and re think what it is you are doing...fixed code below:

print "==============\n\n"; print "| COMMODITY: |\n\n"; print "==============\n\n"; my $cmmdty = <STDIN>; $cmmdty = <STDIN> until defined $cmmdty; chomp $cmmdty; if ($cmmdty) { if ($cmmdty eq "NONE") { chomp(my $lore = "E"); } else { chomp(my $lore = "L"); cls();

It does exactly as I expect it to do.

Replies are listed 'Best First'.
Re^2: Auto Fill - FIXED
by kcott (Archbishop) on May 16, 2015 at 05:36 UTC
    "It does exactly as I expect it to do."

    What did you expect this code to do?

    if ($cmmdty eq "NONE") { chomp(my $lore = "E"); } ...

    Here's what it does:

    • creates a new lexical variable called $lore
    • assigns the string 'E' to $lore
    • calls chomp which does absolutely nothing
    • allows $lore to go out of scope so that it cannot be accessed by any other part of your code

    In short, create a variable, assign a value, perform a pointless operation and then throw it all away.

    You possibly have the same problem with 'chomp(my $lore = "L");' but that part of the code is incomplete so I can't tell.

    -- Ken

Re^2: Auto Fill - FIXED
by NetWallah (Canon) on May 16, 2015 at 00:44 UTC
    It does exactly as I expect it to do.
    Are you sure ?

    How will you access the value of $lore , after this part of your script completes ?

    And, you are missing a closing brace.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

      The closing brackets (2) have been added and the value of $lore gets printed to a flatfile database for later retrieval.