It might be stupid, but why not do a diff?
Otherwise I guess this would work:
#!/bin/perl -w use strict; my( $file1, $file2)= @ARGV; my %v1= parse_att( $file1); my %v2= parse_att( $file2); $\="\n"; my @new= grep { !$v2{$_} } keys %v1; my @deleted= grep { !$v1{$_} } keys %v2; print "new: ", join "\n ", @new; print "deleted: ", join "\n ", @deleted; sub parse_att { my $file= shift; my %atts; my $field=''; open( FILE, "<$file") or die "I'd better tell you that the open su +cceded or I'll get --'ed into oblivion, I'll even report why I failed +: $!"; while( <FILE>) { chomp; my $val; if( m/^\s*-([\w-]+) \s*:\s*([^,]*),?$/) { ($field, $val)= ($1, $2); } elsif( m/^\s*([^,]*),?$/) { $val= $1; } else { die "uh-oh, looks like this line has a problem: $_"; } # why bother with clever data structures $atts{"$field $val"}=1; } return %atts; }
In reply to Re: Need to build attribute parser
by mirod
in thread Need to build attribute parser
by Lord Rau
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |