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

[MacPerl] new: Mac::FileSpec::Unixish in CPAN



I've just sent to CPAN a new module, Mac::FileSpec::Unixish.  It should be in
<http://www.perl.com/CPAN/authors/id/S/SB/SBURKE/>; if it's not there, wait a few hours and look again.  I'm guessing it should have progatated all around by Tuesday morning GMT definitely.

Here's a description of the module, partially excerpted from the POD:

			Mac::FileSpec::Unixish

Mac::FileSpec::Unixish -- Unixish-compatability in file specifications

SYNOPSIS
  use Mac::FileSpec::Unixish; # exports 'unixify' and 'nativize'
  
  @input = map( unixify($_), @ARGV);
  foreach $item (@input) {
    my $_native_item = nativize($item);
    next unless
             $item =~ m<([^/]+)$>s # assumes / is the path separator
             and -f $_native_item;
    printf("File %s is %d bytes long...\n", $1, -s _ );
    open(IN, "<$_native_item")
      || die "Can't open $_native_item : $!\n";
    print "First line: ", scalar(<IN>);
    close(IN);
  }

DESCRIPTION
Mac::FileSpec::Unixish provides two functions, `nativize' and `unixify'
(both of which are exported by default), that will allow you to denote
and manipulate pathspecs in Unixish style, and let you convert these
pathspecs to and from the native OS's format for conveying such things.
It currently assumes that if you are not running under MacOS (as
reported in `$^O'), you must be on a Unix box. If you want better, I
suggest using File::Spec. (In essence, I wrote Mac::FileSpec::Unixish as
a cheap hack to get around using File::Spec.)

Using this library, you can, in your code, refer to files using a
Unixish notation, a la:

  $foo = "../analyses/ziz.txt";
  open(OUT, '>' . &nativize($foo) ) || die "Couldn't open $foo \: $!";

Under Unix, `nativize($foo)' will be simply "../analyses/ziz.txt"
(`nativize' and `unixify' are nearly no-ops under Unixes); but under
MacOS it will be "::analyses:ziz.txt".

[...] In other words, this:

  @items = map(&unixify($_), @ARGV);
  foreach $one (@items) {
    print "$one => ", -s &nativize($one), " bytes\n";
    my $one_copy = $one;
    $one_copy =~ s/[^/]+$//s;
    print " in the directory $one_copy";
  }

will work equally well under MacOS as under Unix, regardless of the fact
that items in @ARGV will be in "foo:bar:baz" format if run under MacOS,
and "/foo/bar/baz" format if run under Unix. ...

This library exists so that a careful programmer who knows what
filespecs are legal and meaningful both under Mac and under Unix, can
write code that manipulates files and filenawes, and have this code
work equally well under MacOS and under Unix.  [...]  "Unixish" path
specification means pathspecs expressed with the meanings that Unix
assigns to '/', '.', and '..'  [...]



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch