Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^5: delete duplicated xml lines

by hbm (Hermit)
on Aug 10, 2012 at 13:31 UTC ( #986743=note: print w/replies, xml ) Need Help??

in reply to Re^4: delete duplicated xml lines
in thread delete duplicated xml lines

Phew, your indentation is overwhelming! Consider these examples to help:

#move this line up (and simplify it): #if(length($materialmapping_file) gt 0 or length($data_folder) gt 0 +) unless (defined $materialmapping_file and defined $data_folder) { print "Usage: $0 <materialmapping_file> <data_folder>\n"; exit; } # Now, everything that follows can be outdented one level.


while( ($filename = readdir(DIR))){ #if($filename =~ /\.xls$/i) { next unless $filename =~ /\.xls$/i; # everything below can be outdented my $parser = Spreadsheet::ParseExcel->new(); my $oBook = $parser->parse($data_folder.$filename); #if (defined $oBook ) { next unless defined $oBook; # everything below can be outdented ...

For your duplication problem, I think this might do:

my %seen; # a new global variable ... # then, whenever you 'createElement' and/or 'setAttribute', first a +ssemble the string: #my $materialmapping_item2 = $materialmapping_table_xml->createElem +ent("item3"); #$materialmapping_item2->setAttribute(decode('cp1252',$pr_cell_name +2->{Val}),$pr2); my $entry = join',', decode('cp1252',$pr_cell_name2->{Val}),$pr2; # and create it if it doesn't already exist: if (!exists $seen{$entry}++){ my $materialmapping_item2 = $materialmapping_table_xml->createEl +ement("item3"); $materialmapping_item2->setAttribute($entry); }

Replies are listed 'Best First'.
Re^6: delete duplicated xml lines
by cibiena (Initiate) on Aug 12, 2012 at 22:35 UTC
    Thankyou very much for your help hbm!!! I try your duplication solution but give me a error: "exists argument is not a HASH or ARRAY element or a subroutine" Perl is too much difficult for me :(

      Please provide the full error message, including line number; and the offending line of code.

      I'm guessing that your hash is not globally scoped; or you've tried something like %seen{$entry}, which should be $seen{$entry}.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986743]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-03-24 09:10 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.