----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 15, 2003 08:33
Subject: Questions
> Hello, this is my first post to activeperl. I'm getting familiar with
Perl,
> but two things puzzle me and perhaps someone has the answers:
>
> 1) How would you add to a hash, similar to how you can "push" onto the end
> of an array? This is useful when reading through a list and adding to an
> array, but I can't find anything about doing it with a hash.
>
> 2) I prefer to use "use strict", which means all variables have to be
> preceded by "my," but what do you do when you need a "my" variable to be
> global so that another block of code can use it?
>
A simple way to add a key/value to a hash is as follows:
my %Hash = ();
my $Key = 'a';
$Hash{$Key} = 1;
Or even simpler using the hash and key defined above:
$Hash{$Key}++;
The above statement will simply add the key if it does not exist an assign a
value of 1 to the value, if the key already exists, the value will be
incremented by 1.
For the 'my' question, simply declare your 'my' statements prior to any
references to them by your code, i.e. at the very beginning of the program.
There are many issues with scope of variables that I will leave for others
to explain or for you to learn.
Dirk Bremer - Systems Programmer II - ESS/AMS - NISC St. Peters
636-922-9158 ext. 8652 fax 636-447-4471
[EMAIL PROTECTED]
www.nisc.cc
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs