thezip has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Would someone please explain to me why the following two hash initializations react differently?
Specifically, the QUOTEDSALES assignment is parenthesized in the second, but not in the first.
The indication that I'm seeing is that the last four keys are missing (using the first init) after subsequent processing...
I had drawn the erroneous conclusion that it doesn't matter if parentheses are included or omitted. Would someone please explain the rule that should be applied here?
my $item = { JOBN => $record->[0], CUSTOMERN => $record->[1], JOBDESCRIPTION => $record->[2], QUANTITY => $record->[3], QUOTEDSALES => sprintf "%0.2f", $record->[4] * 0.04, DUEDATE => $record->[5], PRODPLANNER => '5', PRODUCTCODE => '900', SALESMANN => '48', };
my $item = { JOBN => $record->[0], CUSTOMERN => $record->[1], JOBDESCRIPTION => $record->[2], QUANTITY => $record->[3], QUOTEDSALES => sprintf("%0.2f", $record->[4] * 0.04), # <-- NOT +E parens DUEDATE => $record->[5], PRODPLANNER => '5', PRODUCTCODE => '900', SALESMANN => '48', };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd behavior in hash initialization due to missing parens
by GrandFather (Saint) on Oct 08, 2007 at 23:02 UTC | |
by thezip (Vicar) on Oct 08, 2007 at 23:04 UTC | |
|
Re: Odd behavior in hash initialization due to missing parens
by ysth (Canon) on Oct 09, 2007 at 05:56 UTC | |
|
Re: Odd behavior in hash initialization due to missing parens
by naikonta (Curate) on Oct 09, 2007 at 10:21 UTC | |
|
Re: Odd behavior in hash initialization due to missing parens
by FunkyMonk (Bishop) on Oct 08, 2007 at 22:55 UTC |