Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Pring array into a text file

Reply
Thread Tools

Pring array into a text file

 
 
avashisht
Guest
Posts: n/a
 
      02-16-2004
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
 
Reply With Quote
 
 
 
 
Maximus
Guest
Posts: n/a
 
      02-17-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (avashisht) wrote in message news:<(E-Mail Removed). 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 ?
 
Reply With Quote
 
 
 
 
toylet
Guest
Posts: n/a
 
      02-19-2004
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
 
Reply With Quote
 
nobull@mail.com
Guest
Posts: n/a
 
      02-20-2004
toylet <(E-Mail Removed)> 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:umper.

This newsgroup does not exist (see FAQ). Please do not follow-up here
without pointing this out.
 
Reply With Quote
 
toylet
Guest
Posts: n/a
 
      02-20-2004
> 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
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      02-21-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to pring a list object in Python? Zeynel Python 7 11-09-2010 03:17 AM
To write an array from the text file into an array variable using C amrutha0303 Software 0 08-03-2010 02:57 PM
How can I use print handler to pring a file? Allen ASP .Net 3 10-04-2009 11:35 AM
converting a text file into an "insert into ..." file kublaikhan55@hotmail.com Ruby 5 07-23-2006 07:35 PM
Inputting text from a text file into a 2 -D array saltedcoffee C++ 2 04-05-2006 10:15 PM



Advertisments