in reply to Code Review Needed!

If I understand what your attempting in main.cgi this snippet:

# Load the keywords used my ($terms, @terms); if ($s->{terms}) { @terms = @{$s->{terms}}; for (@terms) { $terms .= "$_ " } chomp($terms); # for some reason chomp wasn't working here }

might be rewritten:

# Load the keywords used my $terms; if ($s->{terms}) { $terms = join ' ', @{$s->{terms}}; }

but more important is what the code should do if if $s->{terms}is false? Currently strict should throw an error when $terms is used later.


HTH,
Charles K. Clarkson

Replies are listed 'Best First'.
Re: Re: Code Review Needed!
by redsquirrel (Hermit) on Jul 02, 2001 at 15:23 UTC
    Charles,

    Thanks for the tip on using join. Tad McClellan on comp.lang.perl.misc suggested the same thing.

    Regarding the issue with if ($s->{terms}), I'm not getting any errors. my $terms is declared outside of the if statement block so I think that is keeping strict happy.

    Thank you for taking the time to look at my code.

    --
    Dave Hoover
    "Twice blessed is help unlooked for." --Tolkien
    http://www.redsquirreldesign.com/dave

      Your not getting any errors because $s->{terms} always tests true. What if one day it tests false? That is why your testing it.

      If it does test false one day, $terms will be undef and strict will throw an 'unitialized' error here:

      # Assign the inserted values $s->{insert} = { all => [ "%All%", $all ], any => [ "%Any%", $any ], terms => [ "%Terms%", $terms ], . . .

      HTH,
      Charles K. Clarkson

      Biologists have a word for something that doesn’t change: dead.
        What is the best way to keep these 'uninitialized' errors from appearing? When I declare my $terms, should I set it to empty quotes or is there a better way?

        Thanks for the help,

        Dave Hoover
        "Twice blessed is help unlooked for." --Tolkien
        http://www.redsquirreldesign.com/dave