in reply to Need to build attribute parser
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Need to build attribute parser
by Lord Rau (Novice) on Sep 28, 2000 at 23:59 UTC | |
by mirod (Canon) on Sep 29, 2000 at 00:51 UTC |