I think you can simplify this with a loop:
for($i = 0;$i < @animals;$i++){
$hash{$animals[$i]} = $mammals[$i];
}
-----Original Message-----
From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 27, 2002 2:33 PM
To: Timothy Johnson
Subject: Re: Newbie Question.
Hi,
Another question:
If I have a hash with entries like these:
my %hash = ($animals [0]=> [$mammals[0]], $animals[1] => [$mammals[1]]);
But if the list has like 50 entries in both the $animals & $mammals the can
I do
this?
my %hash = ($animals [0..49]=> [$mammals[0..49]]);
What I want to avoid is the number of time I have to type in the %hash
entries.
It did not seem to work well.
Thanks.
Timothy Johnson wrote:
> By the way, you have your phone number attached to your messages. You
might
> want to be careful with that.
>
> -----Original Message-----
> From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 10:19 AM
> To: Timothy Johnson
> Subject: Re: Newbie Question.
>
> Thanks....got you.
>
> Timothy Johnson wrote:
>
> > That's easy enough. Try something like this:
> >
> > open(INFILE,"zoo.txt");
> > @animals = <INFILE>;
> >
> > Perl will automatically dump the entire contents of the file into the
> array,
> > with each line as an element. But beware! If you try to do this with
> > extremely large files, you can really bog down your program. In many
> cases
> > it's better to loop through the file line by line using the
> > "while(<INFILE>){" syntax.
> >
> > Note: If you don't want the "\n" character at the end of each line to
> show
> > up in your variables, you should also do a "chomp(@array)".
> >
> > -----Original Message-----
> > From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, August 27, 2002 10:09 AM
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Subject: Newbie Question.
> >
> > Hello,
> >
> > This might be a very simple question, but being a newbie I have to ask.
> > :)
> >
> > How can I copy the line by line contents of a file to a array?
> >
> > For eg: @animals should look like
> > @animals = ('tiger','lion','elephant');
> >
> > And the text file would have entries for the same in this order (i.e.
> > one after the other):
> >
> > tiger
> > lion
> > elephant
> >
> > Thanks in advance.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]