Perl - Hash and the => operator -
so im learning perl , got chapter hashes. understand '=>' operator alias comma operator. when try make value undef warning
use of uninitialized value $last_name{"dino"} in concatenation (.) or string @ ./learning.pl line 18.
use warnings; use strict;  %last_name = (     fred   => 'flintston',     dino   =>  undef,     barney => 'rubble',     betty  => 'rubble', );  $key; $value;  if(%last_name) {     foreach $key (sort keys %last_name) {         print("$key => $last_name{$key}\n");     } }   but when change hash line to:
my %last_name = (     fred   => 'flintston',     dino   =>  undef =>     barney => 'rubble',     betty  => 'rubble', );   it works fine , returns value undef. did replace comma operator separating key/value '=>' operator.
why later work not former if 2 operators supposed same?
they not same. "fat comma" 1 more thing: quotes left hand side operand when it's bareword. therefore,
undef, 1   is equivalent to
undef(), 1   while
undef => 1   is equivalent
'undef', 1   see perlop:
the => operator synonym comma except causes word on left interpreted string if begins letter or underscore , composed of letters, digits , underscores.
Comments
Post a Comment