Hello perlisok, and welcome to the Monastery!
In these lines:
my $fields; eval $_; die if $@; my ( $name, $location, $mapref, $type, $description ) = @$fields;
you create an empty variable $fields, then you set the values of $name, $location, etc., in the eval, but then you overwrite them in the very next line. This treats $fields as an array reference, but since $fields is still empty, dereferencing it as an array produces an empty list, and the 5 variables lose the values they were assigned in the eval!
Here is the skeleton of a solution:
#! perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; $Data::Dumper::Useqq = 1; $Data::Dumper::Purity = 1; my ($name, $location, $siteMapRef, $type, $description, $mapRef); while (<DATA>) { eval $_; die if $@; my $fields = [ $name, $location, $siteMapRef, $type, $description +]; $_ = Data::Dumper->new( [ $fields ], [ 'fields' ] )->Dump(); $_ .= "\n"; } continue { print $_; } __DATA__ $name="MyName";$location="MyLoc";$mapRef="MyRef";$type="MyType";$descr +iption="MyDesc";
which produces the output:
$fields = ["MyName","MyLoc",undef,"MyType","MyDesc"];
Update: If you’d had use strict at the start of your script, it would have caught the problem for you. Always begin every script with:
use strict; use warnings;
See The strictures, according to Seuss. :-)
Plus minor edits.
Hope that helps,
Athanasius <°(((>< contra mundum
In reply to Re: Cannot update record in file with Dump module
by Athanasius
in thread Cannot update record in file with Dump module
by perlisok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |