perlisok has asked for the wisdom of the Perl Monks concerning the following question:
Hi experts,
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::Dumper Module
I rewrote the code and I try to run it with my text-db xxx.txt : $name="MyName";$location="MyLoc";$mapRef="MyRef";$type="MyType";$description="MyDesc";My code:
It gives no effects after:#!/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 $temp +File: $!\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;
perl myScript.pl xxx.txt MyName Lalala
Could you help me? Probably format of my file-db is wrong...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cannot update record in file with Dump module
by Athanasius (Archbishop) on Aug 15, 2012 at 16:06 UTC | |
|
Re: Cannot update record in file with Dump module
by kcott (Archbishop) on Aug 15, 2012 at 17:39 UTC |