in reply to Re^4: Cannot open a file using a relative path
in thread Cannot open a file using a relative path

print p( {align=>'center'}, a( {href=>'/cgi-bin/vault.pl'}, img{src=>'/data/images/hellas.gif'} ));
Here Perl can find is own way to determine and opne the file, how come it doesnt need an absolute path here?

Perl never sees those uris (not paths) as anything but strings. Those uris are sent to the web browser as is, never checked or opened.

The web browser create absolute uris from those relative uris and the uri of the document in which they are found, parses the uris into their components, requests those uris (sending only the path portion of the the absolute uri). Apache converts the partial uris to disk paths with the help of DocumentRoot and serves the files.

How would i be able to specify the correct path since the paths would differ?

Well, you could put it in a directory relative to your script, or you could place a configuration file with the location of the file in a directory relative to the script.

Replies are listed 'Best First'.
Re^6: Cannot open a file using a relative path
by Nik (Initiate) on Apr 24, 2007 at 22:50 UTC
    It seems that i have mistaken uris as relative paths!!

    Iam not quite sure i have understood the 2nd paragraph though....

    If only i could use a way to try to open files with relative apths that would be very nice.

      If only i could use a way to try to open files with relative apths that would be very nice.

      In Windows, any path that doesn't start with /, \ or d:\ (for some letter d) is a relative path

      # Relative to the current dir on the current drive open(my $fh, '<', 'file') open(my $fh, '<', './file') open(my $fh, '<', '../file') open(my $fh, '<', '../dir/file') open(my $fh, '<', 'dir/file') # Relative to the current dir on the drive c: open(my $fh, '<', 'c:file') open(my $fh, '<', 'c:./file') open(my $fh, '<', 'c:../file') open(my $fh, '<', 'c:../dir/file') open(my $fh, '<', 'c:dir/file')

      Like the commments indicate, they're not relative to DocumentRoot. Mind you, you could chdir to DocumentRoot, at which point they will effectively be relative to DocumentRoot.