develooper Front page | perl.beginners | Postings from September 2009

Re: push and split

Thread Previous | Thread Next
From:
Chas. Owens
Date:
September 17, 2009 11:21
Subject:
Re: push and split
Message ID:
58ce48dc0909171120q6e9d1312n37002802f6756fd3@mail.gmail.com
On Thu, Sep 17, 2009 at 14:13, Steve Bertrand <steve@ibctech.ca> wrote:
> Noah Garrett Wallach wrote:
>> Hi there,
>>
>> I am attempting to read a text file in to two array variables.
>>
>> --- text file ---
>> hostname1 ip1
>> hostname2 ip2
>>
>> --- text file ---
>>
>>
>> so basically I would like to have the items in column become an the
>> elements of an array @routers
>>
>> and then the items in column two in an array variable of @ips
>>
>> I suppose I could use split and push to do that but how?
>
> What have you tried?
>
> After you've read the following, post back here with what you've tried,
> and with any further questions:
>
> perldoc -f split
> perldoc -f push
>
> Also, if you are trying to do what I think you are doing, you may want
> to look at using a hash instead:
>
> $router_hash{ hostname1 } = 'ip_addr';
>
> Steve
>

But be careful, this will only work if you don't have the same router
more than once (hashes impose uniqueness on their keys) and you don't
care about the ordering of the routers (hashes are unordered).

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About