This is a somewhat confusing question. the first argument to a perl script is in $ARGV[0]. so you can do this.
Result: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
perl argin.pl argin.pl Name of file:argin.pl size of file:684
In reply to Re: How can we read input argument file to a script from its main library?
by huck
in thread How can we read input argument file to a script from its main library?
by Meena212
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |