Nik has asked for the wisdom of the Perl Monks concerning the following question:

files = <../data/texts/*>; foreach (@files) { $_ =~ s/.*[\/\\](.*)/$1/; } print start_form(-action=>"index.pl"); print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'}, 'Λόγ +ος Ψυχωφελής και Θαυμάσιος => ' ), popup_menu( -name=>'select', -values=> +\@files ), submit('ok')); print end_form(); $file = param("select") or $files[int(rand(@files))]; open(IN, "<../data/texts/$file") or die $!; @data = <IN>; close(IN); $data = join("", @data); $data =~ s/\n/\\n/g;
I t seems fine. $file takes either a random value or what the user selected from the drop down menu but then i beleive the it wont open the file....because i had print "@data"; after the close and its empty. Dow you know why? The code seems correct though....

Replies are listed 'Best First'.
Re: cant open file correcly
by davido (Cardinal) on May 21, 2004 at 16:11 UTC
    Can you prove that the script doesn't die? This is CGI, right? That being the case, your warning if the script dies will be a mysterious server error and an entry in the web server's error log. If it does die, you know the file never got opened in the first place. If your script has already printed the headers, it might be more difficult to find the error, because part of the page may still load. Perhaps using the CGI::Carp qw/fatalsToBrowser/; module will help you to see what's going on.

    If the file never got opened in the first place, possible reasons might be that you're looking in the wrong directory for a file that might exist in some other path location. This can happen when using relative paths. Or you may be attempting to open a file that your script (executing as 'nobody') doesn't have permission to open.


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.