The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl

=begin metadata

Name: basename
Description: print the basename of a file
Author: Abigail, perlpowertools@abigail.be
License: perl

=end metadata

=cut


use strict;
use File::Basename;

my ($VERSION) = '1.2';

unless (@ARGV == 1 || @ARGV == 2) {
    $0 = basename ($0);
    print <<EOF;
$0 (Perl bin utils) $VERSION
$0 string [suffix | /pattern/]
EOF
    exit;
};

if (@ARGV == 2) {
    $ARGV [1] = quotemeta $ARGV [1] unless $ARGV [1] =~ s{^/(.*)/$}{$1};
}

print +(fileparse @ARGV) [0], "\n";

__END__

=pod

=head1 NAME

basename - print the basename of a file

=head1 SYNOPSIS

basename string [suffix | /pattern/]

=head1 DESCRIPTION

I<basename> prints the file component of a path. A second argument to
I<basename> is interpreted as a suffix to remove from the file. If the
suffix is sandwiched between slashes, the suffix is considered a
Perl regular expression, anything at the end of the string that matches
is removed before printing it out.

=head2 OPTIONS

I<basename> does not accept any options.

=head1 ENVIRONMENT

The working of I<basename> is not influenced by any environment variables.

=head1 BUGS

I<basename> has no known bugs.

=head1 STANDARDS

This I<basename> implementation is compliant with the B<IEEE Std1003.2-1992>
specification, also known as B<POSIX.2>.

This I<basename> implementation is compatible with the
B<OpenBSD> implementation.

The I</pattern/> is specific for this Perl implementation.

=head1 AUTHOR

The Perl implementation of I<basename> was written by Abigail,
I<perlpowertools@abigail.be>.

=head1 COPYRIGHT and LICENSE

This program is copyright by Abigail 1999.

This program is free and open software. You may use, copy, modify, distribute
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others to do the same.

=cut