yesilikeit
Programmer
Hi experts,
I am new in Perl and DBI - I have been following book:
I cannot deal with chapter:
I rewrote the code and I try to run it with my text-db xxx.txt :
My code:
It gives no effects after:
Could you help me? Probably format of my file-db is wrong...
I am new in Perl and DBI - I have been following book:
O'reilly - Programming Perl DBI - From the ...
I cannot deal with chapter:
2.5.1 The Perl Data:umper Module
I rewrote the code and I try to run it with my text-db xxx.txt :
Code:
$name="MyName";$location="MyLoc";$mapRef="MyRef";$type="MyType";$description="MyDesc";
My code:
Code:
#!/usr/bin/perl
use Data::Dumper;
$Data::Dumper::Indent = 0;
$Data::Dumper::Useqq = 1;
$Data::Dumper::Purity = 1;
die "Usage: updatemegadata <data file> <site name> <new map reference>\n"
unless @ARGV == 3;
my $megalithFile = $ARGV[0];
my $siteName = $ARGV[1];
my $siteMapRef = $ARGV[2];
my $tempFile = "tmp.$$";
open MEGADATA, "<$megalithFile" or die "Can't open $megalithFile: $!\n";
open TMPMEGADATA, ">$tempFile" or die "Can't open temporary file $tempFile: $!\n";
while ( <MEGADATA> ) {
next unless m/\Q$siteName/;
my $fields;
eval $_;
die if $@;
my ( $name, $location, $mapref, $type, $description ) = @$fields;
next unless $siteName eq $name;
$fields = [ $name, $location, $siteMapRef, $type, $description ];
$_ = Data::Dumper->new( [ $fields ], [ 'fields' ] )->Dump();
$_ .= "\n";
} continue {
print TMPMEGADATA $_ or die "Error writing $tempFile: $!\n";
}
close MEGADATA;
close TMPMEGADATA or die "Error closing $tempFile: $!\n";
unlink $megalithFile or die "Can't delete old $megalithFile: $!\n";
rename $tempFile, $megalithFile or die "Can't rename '$tempFile' to '$megalithFile': $!\n";
exit 0;
It gives no effects after:
perl myScript.pl xxx.txt MyName Lalala
Could you help me? Probably format of my file-db is wrong...