N
Neil Montgomery
I have solved my actual programming problem, but was frustrated in my
attempt to determine the behaviour of @ARGV in the online docs.
I want to combine data from two files. This combined data will be sorted
and modified in various ways which aren't of any importance except that
I need to keep track of which file each datum came from.
I expected the following to do what I needed:
#!/usr/bin/perl
use warnings;
use strict;
my @data;
while (<>) {
chomp;
# print "$ARGV, $ARGV[0]\n"; # For debugging
my $file = ($ARGV eq $ARGV[0]) ? "First" : "Second";
push @data, [ $file , split(/,/) ];
}
foreach (@data) { print "@$_\n" };
__END__
I tested this program using two suitable files of three lines each
(appended at the end of this message) and was surprised by the following
output:
Use of uninitialized value in string eq at try line 8, <> line 4.
Use of uninitialized value in string eq at try line 8, <> line 5.
Use of uninitialized value in string eq at try line 8, <> line 6.
Second a b c
Second 1 2 3
Second 2 3 4
Second d f t r
Second 2 3 4 5
Second 5 6 8 8
I inserted the (commented out) print statement and concluded that the
elements of @ARGV are being 'shift'ed, but I wasn't able to find this
behaviour documented the online docs (perlvar, perlop, perlsyn, perldoc
-q, probably others). I had no success with Google either.
I fixed the program by saving a copy of @ARGV and using that copy
instead. Nevertheless I would like help in finding the documentation for
the way @ARGV is handled in this way.
Regards,
Neil
p.s. Here are the contents of the test files I used:
a,b,c
1,2,3
2,3,4
and
d,f,t,r
2,3,4,5
5,6,8,8
attempt to determine the behaviour of @ARGV in the online docs.
I want to combine data from two files. This combined data will be sorted
and modified in various ways which aren't of any importance except that
I need to keep track of which file each datum came from.
I expected the following to do what I needed:
#!/usr/bin/perl
use warnings;
use strict;
my @data;
while (<>) {
chomp;
# print "$ARGV, $ARGV[0]\n"; # For debugging
my $file = ($ARGV eq $ARGV[0]) ? "First" : "Second";
push @data, [ $file , split(/,/) ];
}
foreach (@data) { print "@$_\n" };
__END__
I tested this program using two suitable files of three lines each
(appended at the end of this message) and was surprised by the following
output:
Use of uninitialized value in string eq at try line 8, <> line 4.
Use of uninitialized value in string eq at try line 8, <> line 5.
Use of uninitialized value in string eq at try line 8, <> line 6.
Second a b c
Second 1 2 3
Second 2 3 4
Second d f t r
Second 2 3 4 5
Second 5 6 8 8
I inserted the (commented out) print statement and concluded that the
elements of @ARGV are being 'shift'ed, but I wasn't able to find this
behaviour documented the online docs (perlvar, perlop, perlsyn, perldoc
-q, probably others). I had no success with Google either.
I fixed the program by saving a copy of @ARGV and using that copy
instead. Nevertheless I would like help in finding the documentation for
the way @ARGV is handled in this way.
Regards,
Neil
p.s. Here are the contents of the test files I used:
a,b,c
1,2,3
2,3,4
and
d,f,t,r
2,3,4,5
5,6,8,8