in reply to Error msg "requires explicit package name"

This exact program compiles and runs for me:
#!/usr/bin/perl -w use strict; my @filenames = @ARGV; my $counter = 0; # add link text to each filename foreach my $name (@filenames) { if ($counter % 2){ #odd rows $name = qq{<tr><td><img align="center" valign="center" src="TN/tn_ +$name" width="75" height="42"> &nbsp;&nbsp;<a href="$name">$name</a></td>\n}; }else{ #even rows $name = qq{<td><img align="center" valign="center" src="TN/tn_$nam +e" width="75" height="42"> &nbsp;&nbsp;<a href="$name">$name</a></td></tr>\n}; } $counter++; }
Does it for you?

Replies are listed 'Best First'.
Re: Re: Error msg "requires explicit package name"
by Theo (Priest) on Jun 17, 2003 at 04:19 UTC
    I can't try it till tomorrow when I get to work, sgifford, but if it does, I'm going to be mightily embarrassed. :-(

    I notice that you did not use 'my' for all instances of $counter. I thought that was part of the requirements for using 'my'. At least I think that's the way I've seen it used. (I think - now I'm not sure of anything)

    One other thing I see now is that the comments '#odd rows' and '#even rows' should have said columns, not rows.

      No, my is a variable declaration and should only be used the first time a lexical variable is referenced. Using two my's in the same scope creates two variables, and with -w will give this warning:
      "my" variable $i masks earlier declaration in same scope
      
      The reason you may see it more than once on the same variable is because the variable is being created new every time. For example:
      for(my $i=0;$i<10;$i++) { print $i,"\n"} for(my $i=9;$i>=0;$i--) { print $i,"\n"}
      uses two completely different $i variables that happen to have the same name, because the scope of $i is only inside the loop.

      Maybe that just confused you more, but hope it's helpful! :-)