You might have seen a hash slice. If you have an array of names that look like:
my @fields = qw( name state age );
then you could assign all the corresponding fields in the %identity hash with the following assignment:
@identity{ @fields } = qw( billy colorado 21 );
Even without the array, it's still a nice technique for making things line up:
@identity{ qw/ name state age / } = qw/ billy colorado 21 /;
I only use that sort of construct if I'm modifying the existing keys of a hash. When creating a hash, I'd probably make a list with the fat comma:
my %identity = ( name => 'billy', state => 'colorado', age => 21, );
The trailing comma in the list is fine. This is a syntactic nicety that helps you add and remove list pairs in the code without have to worry about getting the last line right (which is probably the most frequent error I make when composing SQL statements).
Note that the fat comma list is not necessary, as shown by davido. Nonetheless, I would be inclined to use whitespace to help the eye line up the pairs.
my %identity = qw/ name billy state colorado age 21 /;
update: corrected the hash slice syntax to use curly braces instead of parentheses. /me slaps head.
In reply to Re: Multiple variables & values in one line
by grinder
in thread Multiple variables & values in one line
by einerwitzen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |