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. };

In reply to Re^3: Tk with map - Perl newbie by Marshall
in thread Tk with map - Perl newbie by stickleback

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.