--- Shawn <[EMAIL PROTECTED]> wrote:
>
> > #!/usr/bin/perl -w
> > use strict;
> > my %test_hash = (
> > one => 'no problem',
> > two => 'still no problem'
> > );
> > print $test_hash{ one }; # prints 'no problem' (without quotes)
>
> #!/usr/bin/perl -w
> use strict;
> my %test_hash = (
> my one => 'no problem',
> your two => 'still no problem'
> );
> print $test_hash{ my one }; # prints 'no problem' (without quotes)
>
> ^^^^^^^^^
> Incorrect
Your "Incorrect" statement is puzzling. Sure, that code is incorrect, but it's not
what I posted.
> #!/usr/bin/perl -w
> use strict;
> my %test_hash = (
> 'my one' => 'no problem',
> 'your two' => 'still no problem'
> );
> print $test_hash{ 'my one' }; # prints 'no problem' (without quotes)
>
> ^^^^^^^
> Correct
Shawn,
If you're going to quote me out of context, allow me to point out two things:
1. It's still not a 'strict' issue as you claimed (the following is edited for
brevity).
$ perl -Mstrict -e 'my %test_hash;$test_hash{my one}=3'
No such class one at -e line 1, near "{my one"
$ perl -e 'my %test_hash;$test_hash{my one}=3'
No such class one at -e line 1, near "{my one"
2. You left out the *critical* portion of my email (emphasis added):
With the '=>' (a.k.a. 'fat comma'), the left side of the operator
does no (sic) need to be quoted IF IT DOES NOT CONTAIN WHITESPACE.
> My hashes are generally a bit more descriptive than 'one'...
That's fine. I was presenting a simplified test case to show the code in question.
Now here's
some real, live production code from me:
my %dispatch = (
Add => {
Product => {
page => 'ps-main-products-add.tmpl',
function => \&add_product
},
Currency => {
page => 'ps-main-currency-add.tmpl',
function => \&add_currency
},
},
Delete => {
Product => {
page => 'ps-main-products-delete.tmpl',
function => \&delete_product
},
Currency => {
page => 'ps-main-currency-delete.tmpl',
function => \&delete_currency
}
}
);
So, when I need to call the "$dispatch{ Add }{ Product }{ function }" (which is set to
\&add_product), I think that's pretty darned descriptive, despite not having any
whitespace in the
keys. I've created, in this case, some pretty self-documenting code. Would *anyone*
have trouble
figuring out this:
my $result = $dispatch{ Add }{ Product }{ function }->( $foo, $bar );
Okay, if they're not familiar with references, this may be confusing, but that would
be a
limitation in the programmer's knowledge, not in my coding style.
Shawn, I mean no offense by any of this. These could merely be matters of programming
style, but
the => operator was specifically set up to allow this sort of functionality. My hash
is very
clean and easy to read. If you prefer a different style, *shrug*.
Cheers,
Curtis "Ovid" Poe
=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A
__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]