Saturday, February 5, 2011

PERL : References

#!/usr/bin/perl -w
# 3 data types : scalars, arrays(lists), hashes(key value Pairs)
@uscities = ("boston","charlote","new york","san francisco");
$USC=\@uscities;#first rule for creating references
print "@{$USC}\n";
#OR
foreach(@{$USC})
{
print "$_\n";
}
#end


#!/usr/bin/perl -w
$USC = ["boston","charlote","new york","san francisco"];
foreach (@{$USC})
{
print $_;
}
%contacts = ("firstname","Mark","lastname","Sloan");#rule 1
$contacts = \%contacts;
print ${$contacts}{'firsname'};#value of a key;#rule 1
$contacts = { fistname => "Mark", lastname => "Sloan" };#rule 2
print $contacts->{'firstname'};#rule 2
#end

No comments:

Post a Comment