in reply to Re: I need to read data from an array and write into a text file
in thread I need to read data from an array and write into a text file

Thanks your help, that worked great... The only thing I need to do is to add a NewLine for every data. I couldn't handle with that print statement. Thanks your help again.
  • Comment on Re^2: I need to read data from an array and write into a text file

Replies are listed 'Best First'.
Re^3: I need to read data from an array and write into a text file
by JediWizard (Deacon) on Mar 11, 2005 at 20:20 UTC

    This will add the new lines between each element of the array.

    my @array = qw(some data you want to print to a file); open(my $fh, '>', '/path/to/a/text/file.txt') || die "could not open o +utput file : $!\n"; print $fh join("\n", @array); close($fh);

    See join

    Update: you could also do this:

    my @array = qw(some data you want to print to a file); open(my $fh, '>', '/path/to/a/text/file.txt') || die "could not open o +utput file : $!\n"; { local $, = "\n"; print $fh @array; } close($fh);

    See: perlvar. Sorry I had the wrong variable there originally... hence the update.


    A truely compassionate attitude towards other does not change, even if they behave negatively or hurt you

    —His Holiness, The Dalai Lama

      Thanks very much for your help, now everything works great...