Thanks for your help
if I understand well
$Stock->{$NumP} = ( $Num => { Code => $parc->{Code} .... ) is scalar context, and generate a error
$Stock->{$NumP} = { $Num => { Code => $parc->{Code} .... } is correct.
I will add "use diagnostics;" in my code
thanks
Hugues
Le 22/04/2014 17:18, Maxwell Carey a écrit :
On 04/22/2014 08:21 AM, Hugues wrote:
$Stock->{$NumP} = ( $Num => { Code => $parc->{Code},
NumP => $parc->{NumP},
NumS => $parc->{NumS},
NumC => $parc->{NumC}
} );
Not related to Dancer, just plain Perl. You're assigning a list to a scalar, which is probably not what you intend. What you're doing is the same as:
my $foo = ( "foo", "bar" );
which sets the value of $foo to "bar". If you turn on diagnostics with `use diagnostics;`, you can get a nice explanation of the warning:
Another common error is to use ordinary parentheses to construct a list
reference when you should be using square or curly brackets, for
example, if you say
$array = (1,2);
when you should have said
$array = [1,2];
The square brackets explicitly turn a list value into a scalar value,
while parentheses do not. So when a parenthesized list is evaluated in
a scalar context, the comma is treated like C's comma operator, which
throws away the left argument, which is not what you want. See
perlref for more on this.
To fix, change the parentheses to curly braces to create an anonymous hash:
$Stock->{$NumP} = { $Num => { Code => $parc->{Code},
NumP => $parc->{NumP},
NumS => $parc->{NumS},
NumC => $parc->{NumC}
} };
Or simply remove the additional level of hash nesting (which is essentially what is happening in your current program):
$Stock->{$NumP} = { Code => $parc->{Code},
NumP => $parc->{NumP},
NumS => $parc->{NumS},
NumC => $parc->{NumC}
};
_______________________________________________
dancer-users mailing list
dancer-users@dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________
dancer-users mailing list
dancer-users@dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users