This is a somewhat confusing question. the first argument to a perl script is in $ARGV[0]. so you can do this.
use strict; use warnings;
die 'I need an argument' unless ($ARGV[0]);
#
# capture name of file
#
my $name_of_file=$ARGV[0];
#
# call a subroutine with the name of file
# And capture the data it returns
#
my $data=do_something_else ($name_of_file);
exit;
sub do_something_else {
my $filename=shift;
print 'Name of file:'.$filename."\n";
#
# read all of file at once into single variable
#
my $file_contents;
{
local $/=undef;
open (my $infile,'<',$filename) or die 'cannot open'.$@;
$file_contents=<$infile>;
close ($infile);
}
print 'size of file:'.length($file_contents)."\n";
return $file_contents;
} #do_something else
Result:
perl argin.pl argin.pl
Name of file:argin.pl
size of file:684
|