Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Pring array into a text file (http://www.velocityreviews.com/forums/t24849-pring-array-into-a-text-file.html)

avashisht 02-16-2004 08:30 PM

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

Maximus 02-17-2004 10:41 AM

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 ?

toylet 02-19-2004 09:07 AM

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

nobull@mail.com 02-20-2004 01:21 PM

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.

toylet 02-20-2004 04:05 PM

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

Joe Smith 02-21-2004 06:51 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57