in reply to Filehandle opened only for output error

In your open statement, using the 3-argument version of open, you have specified '>' which means that you want the file opened for "output" only.

In the next line you then proceed to try to read from that file (i.e., you try to use the file for "input"). But you didn't open the file for input...only for output.

If you need to read (i.e., input) from the file, then you need to open the file for input. You do that, in the 3-argume open, by specifying '<' as the 2nd argument instead of the '>' that you used.

ack Albuquerque, NM

Replies are listed 'Best First'.
Re^2: Filehandle opened only for output error
by Sismetic (Initiate) on Aug 21, 2009 at 16:43 UTC

    Oh,sorry to bother again, but I did what u said, and it doesnt show anything although I have gave it parameters('mon.txt') after finishing the subroutine,but it doesnt show me anything(I have checked that it does have something).Any suggestions?

      According to what you showed us, you never print out anything. You don't even call the function to read the file!
      well then probably something else is wrong. could you show us a wider context in which this function is used. here is an example that refers to your 'problem' but with a working procedure.
      use strict; use Data::Dumper; open(FILE, "<", "file.in") || die "Error in : $!"; my @array = <FILE>; close FILE; print Dumper(\@array); file.in here i am , where are you, i am here and you also here
      cheers

      PS

      try dumping the @lineas to check if the data is in the array. if it is then surely the problem is somewhere else.

      use Data::Dumper; sub Take_Txt{ my $archivo = shift; open my $ARCHIVO, '>', $archivo or die $!; my @lineas = <$ARCHIVO>; close $ARCHIVO; shift(@lineas); die Dumper(\@lineas); return @lineas; }