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

Hello monks, I hope you can help me solve my task: I have a perl script, and it gives the error:
Software error: Can't open [http://b-my.com/cgi-bin/templates/friendlyurls/global_head +er.txt]: No such file or directory at modules/template.pm line 59.
See it working (not) here: http://b-my.com/cgi-bin/login.cgi Why is that, when the file http://b-my.com/cgi-bin/templates/friendlyurls/global_header.txt is there, i mean it is not missing but i receive an error? The file access code is 755? Here is my code:
package template; use strict; use warnings; sub files { my $templatepath = shift; opendir (DIR, "$templatepath"); my @files = grep { /.txt/ } readdir(DIR); close (DIR); @files = sort @files; return @files; } sub themes { my $templatepath = shift; opendir (DIR, "$templatepath"); my @files = grep { /./ } readdir(DIR); close (DIR); @files = sort @files; return @files; } sub save { my $name = shift; my $data = shift; my $templatepath = shift; open (DATABASE,">$templatepath/$name"); flock (DATABASE,2); print DATABASE "$data"; flock (DATABASE,8); close (DATABASE); } sub load2 { my $name = shift; my @bannerfile = shift; my @bannerfilebot = shift; my $templatepath = shift; open(DAT, "$name") or die "Can't open [templates/${name}]: $!"; flock (DAT, 2); my @data = <DAT>; flock (DAT, 8); close(DAT); return @data; } sub load { my $name = shift; my $templatepath = shift; open(DAT, "$name".'.txt') or die "Can't open [${name}.txt]: $!"; flock (DAT, 2); my @data = <DAT>; flock (DAT, 8); close(DAT); return @data; } sub loadsub { my $name = shift; my $templatepath = shift; open(DAT, 'accounts/$userid/templates/'. $name .'.txt') or die "Ca +n't open [templates/${name}.txt]: $!"; flock (DAT, 2); my @data = <DAT>; flock (DAT, 8); close(DAT); return @data; } sub print { my $name = shift; my @data = template::load($name); my @bannerfile = shift; my @bannerfilebot = shift; my $templatepath = shift; my $SITETEMPLATEgh = join ('', @data); print $SITETEMPLATEgh; } 1; # return true

Replies are listed 'Best First'.
Re: File missing error...why?
by ikegami (Patriarch) on Mar 22, 2011 at 07:20 UTC

    open takes a system path, not a URL. You'll have to give the appropriate path to the file if it's a local file, and you'll need to use LWP::UserAgent or something to download the document if it's a remote file.

      Cool, thanks a lot! Sometimes things are quite simple :)