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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.