![]() |
Pring array into a text file
Hi,
I am veeeery new to perl.. i have a script where i am outputting the Environment variable to a HASH. either i want to output hash values into a text file, Or get hash into an array and then print the array into the text file../ thanks avashisht |
Re: Pring array into a text file
ashish.vashisht@target.com (avashisht) wrote in message news:<4026c388.0402161230.3bcaed1c@posting.google. com>...
> Hi, > I am veeeery new to perl.. > i have a script where i am outputting the Environment variable to a HASH. > either i want to output hash values into a text file, > Or > get hash into an array and then print the array into the text file../ > thanks > avashisht Hi. Try this: my %hash = ( key1 => 'value1', key2 => 'value2', key3 => 'value3', key4 => 'value4'); open OUT," > file.txt" or die "$!\n"; while (my ($key, $value) = each %hash) { print OUT "Key: $key , Value: $value\n"; } close OUT; Enough ? |
Re: Pring array into a text file
how could yOu read them from file.txt and store in memory again?
is there a binary format for hash? > my %hash = ( key1 => 'value1', > key2 => 'value2', > key3 => 'value3', > key4 => 'value4'); > > open OUT," > file.txt" or die "$!\n"; > > while (my ($key, $value) = each %hash) { > print OUT "Key: $key , Value: $value\n"; > } > close OUT; > Enough ? -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 5:06pm up 2 days 19:00 load average: 1.00 1.08 1.05 |
Re: Pring array into a text file
toylet <toylet@mail.hongkong.com> top-posts:
[ don't top-post, it is rude ] > > my %hash = ( key1 => 'value1', > > key2 => 'value2', > > key3 => 'value3', > > key4 => 'value4'); > > > > open OUT," > file.txt" or die "$!\n"; > > > > while (my ($key, $value) = each %hash) { > > print OUT "Key: $key , Value: $value\n"; > > } > > close OUT; > how could yOu read them from file.txt and store in memory again? > is there a binary format for hash? There are several modules on CPAN for serializing arbritrary data structures. One of them is Storable. Another is Data::Dumper. This newsgroup does not exist (see FAQ). Please do not follow-up here without pointing this out. |
Re: Pring array into a text file
> This newsgroup does not exist (see FAQ). Please do not follow-up here
> without pointing this out. sorry, what did you mean by that? there is an alternative usenet newsgroup for perl? I frankly found the traffic here a bit low given the popularity of perl. -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 12:04am up 24 min 1 user 0.55 0.24 |
Re: Pring array into a text file
toylet wrote:
>> This newsgroup does not exist (see FAQ). Please do not follow-up here >> without pointing this out. > > > sorry, what did you mean by that? there is an alternative usenet > newsgroup for perl? I frankly found the traffic here a bit low given the > popularity of perl. On one USENET server, this bogus newsgroup of comp.lang.perl has only 459 articles online. The proper newsgroup comp.lang.perl.misc has 3146 articles online. Go there for more info. -Joe |
| All times are GMT. The time now is 07:29 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.