in reply to Warning is right or not ?
The function get_IATA() defined in the OP returns either a two element list if the condition $data eq $airline is ever true, or the pre-post-incremented value of $countfalse otherwise. (BTW: Is the latter behavior really intended?) The effects of assigning a multi-element list in scalar versus list context are shown in the code example below. Is the behavior in the scalar assignment below similar to the unspecified failure mentioned in the OP? If so, the proper cure is to return only a single scalar (perhaps the hash value with a concatenated newline) and assign in scalar context, i.e., to $hash{'AirIATA'} and not to a slice.
>perl -wMstrict -MData::Dump -le "my %hash; ;; $hash{'AirIATA'} = get_IATA(); dd \%hash; ;; @hash{'AirIATA'} = get_IATA(); dd \%hash; ;; sub get_IATA { return 'useful', 'unexpected'; } " Scalar value @hash{'AirIATA'} better written as $hash{'AirIATA'} at .. +. { AirIATA => "unexpected" } { AirIATA => "useful" }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Warning is right or not ?
by Anonymous Monk on Dec 21, 2012 at 07:43 UTC | |
by AnomalousMonk (Archbishop) on Dec 21, 2012 at 22:07 UTC | |
by Anonymous Monk on Dec 23, 2012 at 19:13 UTC |
In Section
Seekers of Perl Wisdom