Link to home
Start Free TrialLog in
Avatar of onyourmark
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.
#!/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;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onyourmark
onyourmark

ASKER

Thanks.

$_[0]
What is $_ reading? I thought @_ reads the arguments from the function from which it is called. How about $_   ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!