Thread Welches Modul zum Pfade auflösen? (22 answers)
Opened by lichtkind at 2013-07-01 22:32

topeg
 2013-07-02 02:49
#168698 #168698
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Ich habe bisher so was benutzt:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package path;
use strict;
use warnings;

my $sep;
my $sep_not;
BEGIN {
  if($^O=~/linux|os2|vms|unix|epoc/i)
  {
    $sep=qr!/!;
    $sep_not=qr![^/]!;
  }
  elsif($^O=~/win/i)
  {
    $sep=qr/\\/;
    $sep_not=qr/[^\\]/;
  }
  elsif($^O=~/cygwin/i)
  {
    $sep=qr'[/\\]';
    $sep_not=qr'[^/\\]';
  }
  elsif($^O=~/mac/i)
  {
    $sep=qr!:!;
    $sep_not=qr![^:]!;
  }
  else
  {
    $sep=qr([/\\:]);
    $sep_not=qr([^/\\:]);
  }
}

sub clean($)
{
  my $path=shift;
  1 while( $path=~s!$sep($sep)!$1!gs );
  1 while( $path=~s!(^|$sep)\.$sep!$1!s );
  1 while( $path=~s!$sep$sep_not*$sep\.\.!!s );
  1 while( $path=~s!^$sep\.\.?(?=$sep)!!s );
  1 while( $path=~s!^\.$sep!!s );
  1 while( $path=~s!($sep)\.$!$1!s );
  return $path;
}

sub strip($)
{
  my $path=shift;
  1 while( $path=~s!^\.\.?$sep!!s );
  1 while( $path=~s!(^|$sep)\.\.?(?=$sep|$)!$1!s );
  1 while( $path=~s!$sep($sep)!$1!gs );
  return $path;
}

1;


path::clean entfernt .. und . mit den nötigen Änderungen am Pfad;
path::strip entfernt .. und .

View full thread Welches Modul zum Pfade auflösen?