All pastes #40919 Raw Edit

Someone

public text v1 · immutable
#40919 ·published 2006-02-09 21:42 UTC
rendered paste body
#!/usr/bin/perl
# basedir and basename v1.2 by xorc.
# now you dont have to give an argument, and defaults to current path/file

use strict;

sub basename {
        my @filepath;
        my $arg = shift;
        $arg = $arg ? $arg : $0;

        @filepath = split(/\//,$arg);
        return $filepath[@filepath-1];
}
sub basedir {
        my @dirArr;
        my $rtn;
        my $arg = shift;
        $arg = $arg ? $arg : $0;

        @dirArr = split(/\//,$arg);
        pop @dirArr;
        for (my $x=0; $x < @dirArr; $x++) {
                if ($dirArr[$x]) {
                        $dirArr[$x] =~ s/.//;
                        $rtn .= "/".@dirArr[$x];
                }
        }
        return $rtn;
}
print basedir();
print "\n";
print basename();