Sun751 has asked for the wisdom of the Perl Monks concerning the following question:
sub dispatch { my $HRR_resource = shift; my $HRR_wnt = shift; my $HRR_unx = shift; my $HRR_Scomponent = shift; my $HRR_Wcomponent = shift; my $Pkey; my $Wkey; my $Ukey; my $SCkey; my $WCkey; my $Flag; open(FR, "<$source_file")|| die "Unable to open input file: $sourc +e_file $!"; open(FW, ">$dest_file")|| die "Unable to open output file: $dest_f +ile $!"; while (my $line=<FR>) { $line =~tr/\r\n//d; if ($line) { $Flag = 1; if ($line =~ /PLATFORM_INDEPENDENT/){$Pkey = $line}; if ($Pkey) { $Flag = undef; $Pkey =~ s/\s*//; if($Pkey ne '</PLATFORM_INDEPENDENT>') { if ($line =~ /Id="(.*?)".*?>(.*?)</) { my $key_id = $1; my $key_val = $2; if (exists $$HRR_resource{$key_id}) { my $val = $$HRR_resource{$key_id}; $val =~ /.*?>(.*?$)/; $val = $1; $line =~ s/>.*?</>$val</; print FW "$line\n"; delete($$HRR_resource{$key_id}); } else { print FW "$line\n"; } } else { print FW "$line\n"; } } if ($line =~ /<\/PLATFORM_INDEPENDENT>/) { foreach my $addline(keys %$HRR_resource) { print FW "<RESOURCE Id=\"$addline\" $$HRR_resource +{$addline}</RESOURCE>}\n"; } print FW "$line\n"; $Pkey = undef; } } if ($line =~ /WNT/){$Wkey = $line}; if ($Wkey) { $Flag = undef; $Wkey =~ s/\s*//; if ($Wkey eq '<WNT>' && $Wkey ne '</WNT>') { if ($line =~ /Id="(.*?)".*?>(.*?)</) { my $key_id = $1; my $key_val= $2; if (exists $$HRR_wnt{$key_id}) { my $val = $$HRR_wnt{$key_id}; $val =~ /.*?>(.*?$)/; $val = $1; $line =~ s/>.*?</>$val</; print FW "$line\n"; delete($$HRR_wnt{$key_id}); } else { print FW "$line\n"; } } else { print FW "$line\n"; } } if ($line =~ /<\/WNT>/) { foreach my $addline(keys %$HRR_wnt) { print FW "<RESOURCE Id=\"$addline\" $$HRR_wnt{$add +line}</RESOURCE>}\n"; } print FW "$line\n"; $Wkey = undef; } } if ($line =~ /UNX/){$Ukey = $line}; if ($Ukey) { $Flag = undef; $Ukey =~ s/\s*//; if ($Ukey ne '</UNX>') { if ($line =~ /Id="(.*?)".*?>(.*?)</) { my $key_id = $1; my $key_val= $2; if (exists $$HRR_unx{$key_id}) { my $val = $$HRR_unx{$key_id}; $val =~ /.*?>(.*?$)/; $val = $1; $line =~ s/>.*?</>$val</; print FW "$line\n"; delete($$HRR_unx{$key_id}); } else { print FW "$line\n"; } } else { print FW "$line\n"; } } if ($line =~ /<\/UNX>/) { foreach my $addline(keys %$HRR_unx) { print FW "<RESOURCE Id=\"$addline\" $$HRR_unx{$add +line}</RESOURCE>}\n"; } print FW "$line\n"; $Ukey = undef; } } if ($Flag) { print FW "$line\n"; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for smart solution
by GrandFather (Saint) on Jun 23, 2009 at 05:51 UTC | |
|
Re: Looking for smart solution
by Your Mother (Archbishop) on Jun 23, 2009 at 06:34 UTC | |
by Sun751 (Beadle) on Jun 23, 2009 at 08:57 UTC | |
by Anonymous Monk on Jun 23, 2009 at 09:05 UTC | |
by marto (Cardinal) on Jun 23, 2009 at 09:07 UTC | |
by Your Mother (Archbishop) on Jun 23, 2009 at 14:53 UTC |