Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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.

Similarly:

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); }


Comment on Re^5: delete duplicated xml lines
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986743]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2014-09-30 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (380 votes), past polls