in reply to Problem printing contents of file

You don't need a module. Does the file contain data? Open like this:
open(FILE, '<', '../frame.txt') or die $!; while(<FILE>) { print $_, "\n"; } close(FILE);
To check the size of a file, you can do something like the following:
my $file = '../frame.txt'; if(-s ($file) >0) { open(FILE, '<', $file) or die $!; while(<FILE>) { print $_, "\n"; } close(FILE); }else{ print "$file contains no data\n"; }
7 hours sleep in 2 days is not healthy

Replies are listed 'Best First'.
Re^2: Problem printing contents of file
by ikegami (Patriarch) on Jun 17, 2008 at 14:58 UTC

    If you're going to tell him to use 3-arg open, you might as well recommend lexical file handles and a better error message too.

    And I find it's usually better to check what you got rather than checking what you will get.

    my $frame_qfn = 'temp'; open(my $frame_fh, '<', $frame_qfn) or die("Unable to open frame file $frame_qfn: $!\n"); while (<$frame_fh>) { print; } if (!$.) { print "$frame_fh contains no data\n"; }
Re^2: Problem printing contents of file
by ketaki (Acolyte) on Jun 18, 2008 at 06:16 UTC
    i tried ur script to check the file size... it goes to the else part and says ../frame.txt contains no data. but i checked and the file frame.txt is not empty. this code is in register.cgi file in cgi-bin directory and the file frame.txt is in the folder above cgi-bin folder.so am i writing '../frame.txt' correctly?

      Please read my reply to you. In it, I mention that, when running under a webserver, the current directory likely is not what you think. Do not use relative filenames when running under a webserver.

      You could have avoided a large part of this wild goose chase by making it clear from the start, in your top post, that you are running your script under a webserver account as a CGI script. That would've made it more clear to us where a likely cause for the error lies.

        hey! thanx a lot.... i put the absolute path and it works now :)