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

Re: [MacPerl] Hoaky MacPerl Regular Expression Question



Well, without the extra linebreaks you want, I came up with:

#!perl
use File::Basename;
use strict;
use vars qw(@last);

my @list = (
  'Macintosh HD:myFiles:a.txt',
  'Macintosh HD:myFiles:b.txt',
  'Macintosh HD:myFiles:more:a.txt',
  'Macintosh HD:myFiles:more:b.txt',
  'Macintosh HD:myFiles:more:yetmore:a.txt',
  'Macintosh HD:myFiles:more:yetmore:b.txt',
  'Macintosh HD:yurFiles:a.txt',
  'Macintosh HD:yurFiles:b.txt',
);

foreach (sort @list) {
  my @path = split /:/;
  my $dir = dirname($_);

  for (0 .. $#path) {
    next if defined($last[$_]) && $path[$_] eq $last[$_];
    $last[$_] = $path[$_];
    print " " x ($_*2), $path[$_], "\n";
  }
}

Which gives me:

Macintosh HD
  myFiles
    a.txt
    b.txt
    more
      a.txt
      b.txt
      yetmore
        a.txt
        b.txt
  yurFiles
    a.txt
    b.txt

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org