470,841 Members | 1,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,841 developers. It's quick & easy.

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
Jul 19 '05 #1
5 9183
as*************@target.com (avashisht) wrote in message news:<40**************************@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 ?
Jul 19 '05 #2
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
Jul 19 '05 #3
toylet <to****@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.
Jul 19 '05 #4
> 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
Jul 19 '05 #5
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
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by JackM | last post: by
5 posts views Thread by Andrew V. Romero | last post: by
11 posts views Thread by Walter Dnes (delete the 'z' to get my real address | last post: by
2 posts views Thread by melanieab | last post: by
9 posts views Thread by Miro | last post: by
7 posts views Thread by theballz | last post: by
8 posts views Thread by isaac2004 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.