in reply to what's wrong with this?
what's wrong with this?
my $first = shift || die "first file\n"; my $sec = shift || die "second\n";
The || operator has higher precedence than the = operator so you need to either enclose the assignment in parentheses or use the lower precedence or operator.
You can accomplish the same result more simply with a single hash:
#!/usr/bin/perl use strict; use warnings; my $first = shift or die "first file\n"; my $sec = shift or die "second\n"; open my $FIRST, '<', $first or die "$first: $!"; open my $SEC, '<', $sec or die "$sec: $!"; print "processing $first\n"; my %common = map { /^\s*(\?.*?)\s/, 0 } <$FIRST>; print "processing $sec\n"; /^\s*(\?.*?)\s/ and $common{ $1 }++ while <$SEC>; print "finding common keys\n"; delete @common{ grep !$common{ $_ }, keys %common }; print "there are @{[scalar keys %common]}:\n"; system 'pause'; for my $key ( keys %common ) { print "\n\n\n$key\n\n\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: what's wrong with this?
by Anonymous Monk on Oct 24, 2008 at 14:21 UTC |