Home: Perl Programming Help: Intermediate:
"os.path.join()" equivalent in Perl



matt.georgey
New User

Jan 11, 2012, 8:48 PM


Views: 5614
"os.path.join()" equivalent in Perl

Python's os.path.join () method intelligently joins directories and file names w/o repeating the sub directories, present in both directory path and file path.

Any equivalent method is there in perl..?

Like, say path =dir1/dir2/dir3 and path1=dir2/dir3/filename; then when joining the result should be something like "dir1/dir2/dir3/filename"


rovf
Veteran

Jan 12, 2012, 5:55 AM


Views: 5601
Re: [matt.georgey] "os.path.join()" equivalent in Perl


Quote
Like, say path =dir1/dir2/dir3 and path1=dir2/dir3/filename; then when joining the result should be something like "dir1/dir2/dir3/filename"


os.path.join does not behave in that way. See attached screenshot.
Attachments: MWSnap2012-01-12_14-53-28.png (16.5 KB)


matt.georgey
New User

Jan 13, 2012, 12:57 AM


Views: 5596
Re: [rovf] "os.path.join()" equivalent in Perl

Thanks for the reply.

But the documenthttp://docs.python.org/library/os.path.html says its intelligent to avoid any repetition.

Even if it doesn't, forget it.
But is there any method does the job what i'm intended to do..?


rovf
Veteran

Jan 13, 2012, 4:03 AM


Views: 5594
Re: [matt.georgey] "os.path.join()" equivalent in Perl

Actually, the documentation you are refering to, does not apply to the example which you had provided, because in the precondition, it says If any component is an absolute path ..., and your example had only relative pathes.

I'm not aware of any (standard- or CPAN-)module which would offer the desired functionality. The "usual" routines for manipulating pathes in a system-independend way are in File::Spec::Functions (but I guess you've seen them already?), so I think you have to implement them by yourself.

Just being curious: What application does this function have?