On Mon, Oct 13, 2014 at 1:04 AM, Boylan, Ross <ross.boy...@ucsf.edu> wrote:
> perl -c adduser gives its first error as
> "my" variable $new_uid masks earlier declaration in same scope at adduser 
> line 283.
> First, it doesn't seem to me I'm declaring the variable at all at 283.  I 
> suppose it could be an implicit declaration if there wasn't a previous 
> declaration, but there is at 103.
> Second, I don't see any earlier declarations in any scope except the outer 
> one.
> Third, the variiable was declared, with "our $new_uid;" much earlier in the 
> file.
>
> Could anyone explain to me what's going on?  A couple other questions appear 
> after the code.
>     32  use warnings;
>     33  use strict;
>     34  use Debian::AdduserCommon;
>     35  use Getopt::Long;
>     36  use File::Spec::Functions;
>     37  use File::Touch;
> ...
>    103  our $new_uid = undef;
> ....
>    160  # Parse options, sanity checks
>    161  unless ( GetOptions ("quiet|q" => sub { $verbose = 0 },
> ...
>    173              "uid=i" => \$new_uid,  # still in arguments to GetOptions
> Lines 103 and 173 are the only places $new_uid occurs in the text before line 
> 283.
>
>    272  if ($use_template = &use_template) {
>    273      # we are using templates
>    274      if (check_template( $conf_dir, \%template)) {
>    275          merge_template( \%template, \%system)
>    276      }
>    277      # rewrite request as needed
>    278      if defined($new_name) {
>    279          # trying to create a new user
>    280          if (my @old = $$($template{uname}){$new_name}) {
>    281              # requested user is in the template
>    282              my $olduid = $$old[2];
> **283              dief( gtx("Specified UID %d for %s does not match template 
> UID of %d.\n"), $new_uid,
>    284                        $new_name, $olduid) if defined($new_uid) && 
> $new_uid != $olduid;
>    285              $new_uid = $olduid;
>    286              my $oldgid = $$old[3];
>
> Bonus question #1: Where does the relevant scope start?  I think  it's 280, 
> but if none of the if's create scopes it could be the start of  the file.
>
> Bonus question #2: If I change 280 to  to   "if (my $old = ...." I get the 
> error
> "my" variable $old masks earlier declaration in same statement at adduser 
> line 282.
> Why?  I mean, there's only declaration in the statement, and it seems to be 
> on the first line even if the "statement" is everything up to the end of the 
> if .. else .. block.
>
> The archives indicate that syntax errors sometimes produce seemingly 
> unrelated "masks earlier declaration" errors, but even if this is a syntax 
> error (it seems more like a semantic problem to me) the error seems odd.


LIne 280 alone will generate  a syntax error:

$ perl -we 'if (my @old = $$($template{uname}){$new_
name}) {}'
         syntax error at -e line 1, near "$$("


Perhaps you meant somethng like:

   if (my @old = ( ${$template{uname}{$new_name}} ) ) { .... }


But that's really bizarre too.  Did you really intend to declare and
populate an array and throw in a conditional all in a one-liner?

Do you know for instance that my @foo = $some_scalar is the equivalent
of just saying:  my @foo = ($some_scalar).

So, just a few thoughts... some more explanation of what that code is
intended to do would help.

-- 
Charles DeRykus

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to