Pring array into a text file

A

avashisht

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
 
M

Maximus

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 ?
 
T

toylet

how could yOu read them from file.txt and store in memory again?
is there a binary format for hash?
 
N

nobull

toylet <[email protected]> top-posts:

[ don't top-post, it is rude ]
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.
 
T

toylet

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.
 
J

Joe Smith

toylet said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top