in reply to How to correct code

this is a perl place...so don't ask for a javascript answer. when perl is in strict mode it requires that all variable declerations either have explicit package names added OR they be prefixed with "my" keyword. Hence, adding "my " in front of all the first instances of those variable names will fix it.

Replies are listed 'Best First'.
Re^2: How to correct code
by davido (Cardinal) on Sep 30, 2004 at 14:10 UTC

    You can't just add my to each first occurrence of each variable in a script and expect the script to work properly after that. What if the script has something like this?

    foreach $thingy ( @lots_of_thingies ) { $all_of_them .= $thingy; } print "$all_of_them\n";

    In that example, if $all_of_them is declared with my in the lexical scope bounded by the foreach loop's code block, you won't be able to print it after the loop runs out.

    strict enforces not just the use of variable declaraction, but it requires that additional thought be paid to design of lexical scopes. The OP would be wise to read perlintro, perlsub, perlsyn and my for starters. Sometimes a script is just beyond converting to compliance with strictures unless one is willing to take the time for a major rewrite.


    Dave

Re^2: How to correct code
by Anonymous Monk on Sep 30, 2004 at 14:12 UTC
    could you show exact sample wherer should be added "my"?
      Here is a simple brief example, but like dragonchild says, to get the complete picture you should really get a Perl book. Personally I would recommend you borrow, steal or buy the "Camel" book from O'Reilly. It will fill you in on all the stuff necessary to get you going.
      use strict; #declare the variable $foo before using my $foo; $foo = 'hello world'; print $foo;
      my @lots_of_thingies; [...] my $all_of_them; foreach my $thingy ( @lots_of_thingies ) { $all_of_them .= $thingy; } print "$all_of_them\n";

      By side, this code cries for join...