example script demonstrating how to use perl arrays and hashes and showing how they
authorChris Koeritz <fred@gruntose.com>
Wed, 10 Jul 2013 18:33:10 +0000 (14:33 -0400)
committerChris Koeritz <fred@gruntose.com>
Wed, 10 Jul 2013 18:33:10 +0000 (14:33 -0400)
are different.

examples/perlisms/example_perl_array_and_hash.pl [new file with mode: 0644]

diff --git a/examples/perlisms/example_perl_array_and_hash.pl b/examples/perlisms/example_perl_array_and_hash.pl
new file mode 100644 (file)
index 0000000..5c75760
--- /dev/null
@@ -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";