onyourmark
asked on
reading in arguments
Hi. I was wondering why the code below works but it won't work if I change the line
my $file = shift;
to
my $file = @_;
and also, if I run this code (using the name cat.pl) with a comma separated list of arguments why it skips the first argument. For example if I run
perl cat.pl SampleForGraphing.csv, second.csv
it only prints the file second.csv
Thanks.
my $file = shift;
to
my $file = @_;
and also, if I run this code (using the name cat.pl) with a comma separated list of arguments why it skips the first argument. For example if I run
perl cat.pl SampleForGraphing.csv, second.csv
it only prints the file second.csv
Thanks.
#!/Perl/bin/perl
use strict;
#use warnings;
sub print_file {
my $file = shift;
open FILE, $file;
while (my $line = <FILE>) {
print $line;
}
}
sub cat {
while (my $file = shift) {
print_file $file;
}
}
cat @ARGV;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
ASKER
$_[0]
What is $_ reading? I thought @_ reads the arguments from the function from which it is called. How about $_ ?