|
|
| Learning Perl (ISBN: 0596001320) |
 |
List Price:
Our Price:
Used Price: $17.00
Release Date: 27 July, 2001
Manufacturer: O'Reilly UK (Paperback)
Sales Rank: 1,013
Author: Randal L. Schwartz, Tom Phoenix
|
More Info
|
|
|
Associative Array
|
2002-09-14 00:31:56
|
| |
perl
|
|
|
|
|
Category: source:perl:general
|
|
Description: Associative array's can be very useful in organizing your data. This example will show you how to make use of them.
|
|
Platform: all
|
|
Author: detour
|
|
Viewed: 3180
|
|
Rating: 3.9/5 (9 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
#!/usr/bin/perl
#
# ass_array.pl written by detour@metalshell.com
#
# Associative array's can be very useful in organizing
# your data. This example will show how to make use
# of them.
#
# http://www.metalshell.com/
#
use strict;
# You can define multiple keys with values when
# you declare your associative array.
my $key;
my %assoc = ("PX", "Philadelphia Experiment",
"1WG", "One World Governmnet",
"NWO", "New World Order",
"MIB", "Men In Black");
# You can access a value for a key by doing the following.
print "PX stands for " . $assoc{"PX"} . ".\n\n";
# You can add or modify values at any time
$assoc{"CIA"} = "Central Intelligence Agency";
# Cycle through every key and print the values.
foreach $key (keys %assoc) {
print "$key stands for " . $assoc{$key} . ".\n";
}
print "\n";
# Delete the unwanted values.
delete $assoc{"NWO"};
delete $assoc{"1WG"};
foreach $key (keys %assoc) {
print "$key stands for " . $assoc{$key} . ".\n";
}
|
|
|