my $file_name = @ARGV ? shift(@ARGV) : 'answerfile';
open(my $fh, '<', $file_name)
or die("Unable to open answer file \"$file_name\": $!\n");
####
use File::Spec::Functions qw( rel2abs );
my $full_name = rel2abs($file_name);
##
##
use File::Basename qw( dirname );
my $dir_name = dirname($full_name);
##
##
E:\some\path>type ..\bin\routine.pl
use strict;
use warnings;
use File::Basename qw( dirname );
use File::Spec::Functions qw( rel2abs );
my $file_name = @ARGV ? shift(@ARGV) : 'answerfile';
open(my $fh, '<', $file_name)
or die("Unable to open answer file \"$file_name\": $!\n");
my $full_name = rel2abs($file_name);
my $dir_name = dirname($full_name);
print("Name: $file_name\n");
print("Full Name: $full_name\n");
print("Dir Name: $dir_name\n");
print("Contents:\n");
print while <$fh>;
E:\some\path>type answerfile
Answer file in \some\path
E:\some\path>type ..\otherpath\answerfile
Answer file in \some\otherpath
E:\some\path>..\bin\routine.pl
Name: answerfile
Full Name: E:\some\path\answerfile
Dir Name: E:\some\path
Contents:
Answer file in \some\path
E:\some\path>..\bin\routine.pl ..\otherpath\answerfile
Name: ..\otherpath\answerfile
Full Name: E:\some\path\..\otherpath\answerfile
Dir Name: E:\some\path\..\otherpath
Contents:
Answer file in \some\otherpath
E:\some\path>..\bin\routine.pl e:\some\otherpath\answerfile
Name: e:\some\otherpath\answerfile
Full Name: E:\some\otherpath\answerfile
Dir Name: E:\some\otherpath
Contents:
Answer file in \some\otherpath