P
Peng Yu
Hi,
It seems that if strings are keys, the single quote can be omitted. I
don't see why on perl hash tutorial webpage such as
http://www.cs.mcgill.ca/~abatko/com...rl/howto/hash/#add_a_key_value_pair_to_a_hash
Can somebody give me a brief explanation why the single quote can be
omitted if the strings are used as the keys of a hash?
Thanks,
Peng
#!/usr/bin/perl
use strict;
use warnings;
my %hash = (
Fred => 'Flintstone',
Barney => 'Rubble'
);
# I can use the following code as well.
#my %hash = (
# 'Fred' => 'Flintstone',
# 'Barney' => 'Rubble'
#);
#The strings does not have single quotes as well.
print "$hash{Fred}\n";
print "$hash{Barney}\n";
print "$hash{'Fred'}\n";
print "$hash{'Barney'}\n";
It seems that if strings are keys, the single quote can be omitted. I
don't see why on perl hash tutorial webpage such as
http://www.cs.mcgill.ca/~abatko/com...rl/howto/hash/#add_a_key_value_pair_to_a_hash
Can somebody give me a brief explanation why the single quote can be
omitted if the strings are used as the keys of a hash?
Thanks,
Peng
#!/usr/bin/perl
use strict;
use warnings;
my %hash = (
Fred => 'Flintstone',
Barney => 'Rubble'
);
# I can use the following code as well.
#my %hash = (
# 'Fred' => 'Flintstone',
# 'Barney' => 'Rubble'
#);
#The strings does not have single quotes as well.
print "$hash{Fred}\n";
print "$hash{Barney}\n";
print "$hash{'Fred'}\n";
print "$hash{'Barney'}\n";