use strict; use warnings; my $SOURCEFILE; my $TARGETFILE; my $REPORTFILE; my $converted; my $discarded; my $holder; my $titleid; print "Enter filename to convert: "; chomp($SOURCEFILE = <STDIN>); print "Save to:"; chomp($TARGETFILE =<STDIN>); print "Save Conversion Report to:"; chomp($REPORTFILE =<STDIN>); open SOURCEFILE, '<', $SOURCEFILE or die "Can't open $SOURCEFILE: $!"; open TARGETFILE, '>', $TARGETFILE or die "Can't open $TARGETFILE: $!"; open REPORTFILE, '>', $REPORTFILE or die "Can't open $REPORTFILE: $!"; $converted=0; $discarded=0; sub reporting { print TARGETFILE $holder; print REPORTFILE " -> "; print REPORTFILE $holder; $converted++; } #Evaluate per line foreach my $line (<SOURCEFILE>) { if ($line =~ /<NAME>(\w+)/) { print REPORTFILE $line; #saves original value to repor +tfile $line =~ s/<NAME>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<AGE>(\w+)/) { print REPORTFILE $line; $line =~ s/<AGE>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<ADDRESS>(\w+)/) { print REPORTFILE $line; $line =~ s/<ADDRESS>/|/; $line =~ s/\n//g; $holder = $line; reporting; } elsif ($line =~ /<PHONE>(\w+)/) { $discarded++; print REPORTFILE "<xx> "; print REPORTFILE $line; } } print TARGETFILE "^\n"; # eof line marker print REPORTFILE "No. of fields Converted: "; print REPORTFILE $converted, "\n"; print REPORTFILE "No. of fields Discarded: "; print REPORTFILE $discarded, "\n"; close SOURCEFILE or die "Can't close: $!"; close TARGETFILE or die "Can't close: $!"; close REPORTFILE or die "Can't close: $!";
In reply to convert directory content to dbf by oblate kramrdc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |