in reply to Re: Tk with map - Perl newbie
in thread Tk with map - Perl newbie

Thanks for the quick reply.

The 2 element list to 4 variables was a mistake in extracting the dialog from the larger program. Apologies for that.

I your suggested broken out code works fine. The following also works ...

$dfUser->configure( -textvariable=>\$user); $dfPassword->configure( -textvariable=>\$password);
I can get my code to work and the dialog to display correctly but I wanted to understand why the original code does not work. I am trying to learn Perl along the way.

Replies are listed 'Best First'.
Re^3: Tk with map - Perl newbie
by vkon (Curate) on Mar 31, 2011 at 19:20 UTC
    (update) deleted wrong content,
    sorry
    :-|
Re^3: Tk with map - Perl newbie
by Marshall (Canon) on Apr 02, 2011 at 19:22 UTC
    The quoting operator as in qw/\$user \$password/ doesn't work because what is getting translated in to the $_ variable is the TEXT '\$user', not a reference to $user!

    I show this below with a simple example. Using parens and comma for a normal list allows the \$user to be translated into a value that is the reference. The code will expect to deference the hash value and that will work if what is stored is really a reference to something else rather some text. So in this case, the qw// is not doing what (..,...) does.

    #!/usr/bin/perl -w use strict; use Data::Dumper; my ($user,$password); my $a=0; my %hash1 = map{$a++=>$_}qw/\$user \$password/; #just text my %hash2 = map{$a++=>$_}(\$user, \$password); #real reference print Dumper \%hash1, \%hash2; $user = 234; $password = 'xyz'; print Dumper \%hash1, \%hash2; __END__ $VAR1 = { '1' => '\\$password', '0' => '\\$user' }; $VAR2 = { '3' => \undef, #ref to an undefined val '2' => \undef }; ################# $VAR1 = { '1' => '\\$password', '0' => '\\$user' }; $VAR2 = { '3' => \'xyz', #see changing $user or $password '2' => \234 #did update the hash #because these are real references. };