Search notes:

Perl cheat sheet

pwd

Using Cwd and getcwd:
use Cwd;
my $cwd = getcwd();

Files

Extract suffix/extension from a file

my ($extension) = $filename =~ /(\.[^.]*$)/;
Using Perl module File::Basename and fileparse.
use File::Basename;
my ($file_without_suffix, $directory, $suffix) = fileparse ('/foo/bar/baz/file.pl', qr/\..[^.]*$/);

Get a relative file path

use File::Spec;

my $full_path = '/absoulte/path/to/a/file';
my $path      = '/absoulte/path';

my $relative_path=File::Spec->abs2rel($full_path, $path);
print $relative_path;
# prints:
#   to/a/file

Processing command line options

Use Perl module Getopt::Long
use Getopt::Long;

GetOptions(
    'option'  => \my $option,
    'v'       => \my $verbose,
    'help'    => \my $help
);

if ($option) {
   ...
}

See also

Perl

Index