Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

rel2abs doesnot work in unix

by Anonymous Monk
on Jun 16, 2005 at 11:46 UTC ( [id://467250]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks!
Im using rel2abs of file::spec module to convert the relative path to absolute path. Its works fine in windows. but when i run in linux the absolute path has not come out correctly.
pwd /sample/folder1/test $ perl test.pl "/sample/folder1/test/work/first.html"
what test.pl does is go into first.html; extract the files used and convert them to abs path and show the resultant file paths.
for the file '../pictures/logo.gif', it returns the path as /sample/folder1/test/work/../pictures/logo.gif' while actually it should be '/sample/folder1/test/pictures/logo.gif'
Can anyone tell me why it doesnot work

Replies are listed 'Best First'.
Re: rel2abs doesnot work in unix
by merlyn (Sage) on Jun 16, 2005 at 12:08 UTC
Re: rel2abs doesnot work in unix
by Smylers (Pilgrim) on Jun 16, 2005 at 16:41 UTC
    for the file '../pictures/logo.gif', it returns the path as /sample/folder1/test/work/../pictures/logo.gif'

    That has worked: you have it a relative path (one that depends on which directory you are in) and got back an absolute path (one that, in the case of Unix, starts with a slash and therefore refers to that file regardless of your current directory).

    while actually it should be '/sample/folder1/test/pictures/logo.gif'

    To clean up a path like that have a look at abs_path and friends in CWD.

    Smylers

Re: rel2abs doesnot work in unix
by petdance (Parson) on Jun 16, 2005 at 18:50 UTC
    You might want to think about how you phrase these things. You said
    rel2abs doesnot work in unix
    when the reality is
    I can't make rel2abs do what I expect in unix
    The former is accusatory, and incorrect.

    xoxo,
    Andy

      The problem with that line of thinking is that it requires outside knowledge to distinguish. True, not everything is inherently broken, but more often than not, it's easier to blame the tool than to blame the user, because more often than not, it is indeed the tool that is broken.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      I do hav only limited knowledge. May be i shd hav put it in differnt way. Pardon me if i hav mislead/sound accusing.
      -questioner
        But Andy, you didnt tell me what 's the correct way of using rel2abs to get the desired result. -questioner
Re: rel2abs doesnot work in unix
by Anonymous Monk on Jun 17, 2005 at 07:33 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://467250]
Approved by Tanalis
Front-paged by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found