[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

re: [MacPerl] Cross-platform file munging



Scott_Ananian@sil.org writes:
} What's the best (ie most portable) way to construct path names on an arbitrary
} system?  I've looked at File::Path, et al, but none seem to have a decent set of
} features, though I dimly recall a discussion a while back suggesting the use of
} some similar module package.

There should be, but aren't, subroutines, in somewhere you can count on
being there for any standard Perl installation, that do exactly that.
Say in File::Path routines such that $path =
File::Path::relpath(@names) gives a relative path and $path =
abspath(@names) that gives an absolute path. There should be similar
routines to do the reverse, and probably *path should be able to deal
with path fragments in @names as well.  Any of us that have done cross
platform work have probably already written such stuff. Almost all of
the remaining portability problems in any package I've looked at could
be dealt with such routines.

} 
} What is needed:
}  1) Given a file and a path, create a fully specified filename (combine them)
}     This obviously will probably involve adding the system specific directory
} separator; colon on the mac, backslash on Win, forward slash on unix.

That's easy with join.  $fullpath = join(":",$path,$file); change the character
as needed.  Would be nice if the character itself was in Config.pm.

}  2) Given a path, go up one directory.
}     ie path:: for Mac, path\.. for Win/Dos path/.. for Unix...
}     this could probably also be done by stripping the last part of the path off
} (to the last directory separator).

I don't quite get this one.  You want a call, say upone, that does what
chdir("::") would do but portably?

}  3) Given a fully specified pathname, separate filename and path.
}     I've seen modules that do this part.

File::Basaename in the standard Perl5 distribution  This one at least
already exists and works.

} 
} Any suggestions?
}   --Scott
} 
} 
} 
} 
---
--------
Paul J. Schinder
NASA Goddard Space Flight Center,
Code 693, Greenbelt, MD 20771 USA
schinder@pjstoaster.pg.md.us