Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Tk with map - Perl newbie

by vkon (Curate)
on Mar 31, 2011 at 13:40 UTC ( [id://896628]=note: print w/replies, xml ) Need Help??


in reply to Tk with map - Perl newbie

by adding unneeded complexity you've lost what is happening

why you wrote this way:

my ($dfHost, $dfPort, $dfUser,$dfPassword) = map {$fRight->Entry( -textvariable=>$_ )->pack(-side=>'top',- +pady=>3)} qw/\$user \$password/;
you assign 2-element list to 4 variables, so last two are undefined.

But more to the point, if you'll write

$fRight->Entry( -textvariable=>\$user )->pack(-side=>'top',-pady=>3 +); $fRight->Entry( -textvariable=>\$password )->pack(-side=>'top',-pad +y=>3);
your code works as expected.
I can not explain it, but I know it
:)

(addition) qw/\$user .../ does not do what you want

Replies are listed 'Best First'.
Re^2: Tk with map - Perl newbie
by stickleback (Novice) on Mar 31, 2011 at 13:56 UTC
    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.
      (update) deleted wrong content,
      sorry
      :-|
      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. };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://896628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-26 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found