Pring array into a text file

Discussion in 'Perl' started by avashisht, Feb 16, 2004.

  1. avashisht

    avashisht Guest

    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
    avashisht, Feb 16, 2004
    #1
    1. Advertising

  2. avashisht

    Maximus Guest

    (avashisht) wrote in message news:<>...
    > 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 ?
    Maximus, Feb 17, 2004
    #2
    1. Advertising

  3. avashisht

    toylet Guest

    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
    toylet, Feb 19, 2004
    #3
  4. avashisht

    Guest

    toylet <> 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.
    , Feb 20, 2004
    #4
  5. avashisht

    toylet Guest

    > 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
    toylet, Feb 20, 2004
    #5
  6. avashisht

    Joe Smith Guest

    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
    Joe Smith, Feb 21, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Chapman

    Load contents of a text file into a text box

    Jeremy Chapman, Aug 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    758
    Tommy
    Aug 15, 2003
  2. saltedcoffee
    Replies:
    2
    Views:
    565
    Daniel T.
    Apr 5, 2006
  3. Allen
    Replies:
    3
    Views:
    271
    Patrice
    Oct 4, 2009
  4. Zeynel
    Replies:
    7
    Views:
    297
    Zeynel
    Nov 9, 2010
  5. Replies:
    5
    Views:
    257
Loading...

Share This Page