107 users online (0 members and 107 guests)  

  Results 1 to 3 of 3


  1. Active Perl subshell path    Forum: CGI Perl Forum
    Replies: 0
  2. Path to an External Database    Forum: CGI Perl Forum
    Replies: 0
  3. Longest path?    Forum: CGI Perl Forum
    Replies: 0
  4. Help with Path Problem???    Forum: CGI Perl Forum
    Replies: 1
  5. hiding image path    Forum: HTML Forum
    Replies: 3
  1. #1
    evergreenudaipur's Avatar
    New User

    Join Date
    May 2007

    Absoulte path in Perl

    Hello everyone,

    I am getting problems in Perl to get Absolute path,

    My Directory structure is :


    scripts details:

    #!/usr/bin/perl -w 
    use strict; 
    use CGI; 
    use Cwd 'abs_path'; 
    use Cwd; 
    my $cgi           = CGI->new; 
    print $cgi->header; 
    my $file = getcwd; 
    my $abs_path = abs_path($file); 
    my $output='';  
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # uncommenting this during debugging phase may be helpful 
    print <<"END_HTML"; 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <TITLE>Absolute Path Sample Script Showing How To Get Absolute Path In PERL </TITLE> 
    <strong>Sample Script Showing Absolute Path </strong> 
    <h3>The Absolute Path is:  $abs_path </h3> 

    But when I run this its shows :

    Sample Script Showing Absolute Path
    The Absolute Path is: c:/inetpub/wwwroot

    why its showing "c:/inetpub/wwwroot" instead of "c:/inetpub/wwwroot/mytestscripts/perl"

    is anything wrong ?

    Please suggest me asap..

    Thanks in advance..
    Mohit Mehta
    Last edited by vinyl-junkie; 05-31-2007 at 07:38 AM. Reason: Added code tags

  2. #2
    uthus's Avatar
    Senior Member

    Join Date
    Feb 2006
    Ft Hood

    Re: Absoulte path in Perl

    Hi evergreendiapur,

    Welcome to the forum.

    The first line of the script of the script defines the path to perl:

    #!/usr/bin/perl suggests that this program was written by a Linux/Unix user. On my system perl is, in fact, in /usr/bin/perl.

    You need to find perl.exe and put that in the first line. On a Windows box I have no idea where that'd be but it would be something like:

    #!c:/Program Files/something/perl


    Last edited by uthus; 06-04-2007 at 09:45 PM. Reason: Forgot the shebang

  3. #3
    xmassey's Avatar
    Senior Member

    Join Date
    Apr 2007

    Re: Absoulte path in Perl

    I would take a look at using module from CPAN File::Spec
    It will get you all the information you need. I did have a demo up on my website which shows a path, and then every operation File::Spec can do and shows what the result is on the path. If you want more help after looking at File::Spec lemme know

Tags for this Thread