From: Chris Koeritz Date: Wed, 10 Jul 2013 18:33:10 +0000 (-0400) Subject: example script demonstrating how to use perl arrays and hashes and showing how they X-Git-Tag: 2.140.90~965 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=5a051713c8c14dbd27792d6775162a0dd2a46f8d;p=feisty_meow.git example script demonstrating how to use perl arrays and hashes and showing how they are different. --- diff --git a/examples/perlisms/example_perl_array_and_hash.pl b/examples/perlisms/example_perl_array_and_hash.pl new file mode 100644 index 00000000..5c75760a --- /dev/null +++ b/examples/perlisms/example_perl_array_and_hash.pl @@ -0,0 +1,21 @@ + +# define an array. +@fred = ('x', 'y', 'z'); + +# define a hash. +%fred = (x => 'farfle', q => 'nuggy', r => 'bunko'); + +# show the array. +print "\@fred is: @fred\n"; +# show the first element of the array. +print "\$fred[0] is $fred[0]\n"; + +# show the details of the hash. +@fredkeys = keys(%fred); +print "\%fred keys are: @fredkeys\n"; +@fredvals = values(%fred); +print "\%fred values are: @fredvals\n"; +# show the value for the first key we defined in the hash (although that's incidental; +# we don't expect to access things in the hash by their order of addition or even by +# numerical indexes at all. +print "\$fred['x'] is $fred{'x'}\n";