Martin Moss wrote:

lol - sorry Bill.

I have written a script which builds a large complex
array ref and eventually it dumps it into a text file.

Another script then takes several of these output text
files  and reads them all into a 'merged' data
structure and then does other things with this merged
structure. I can't merge them on the fly because of
really really crappy memory constraints.

Rather than write the dumped files in any sort of XML
csv format, and then have to parse them back in again,
I opted to write them as a large perl hashref
definition, which I could just run in an eval to
rebuild the structure quickly.

My only issue was that until I used Data::Dumper to
create the dump files, (which escapes any variables
that would make my dumped perl hashref definition
syntactically incorrect


e.g.

$hashref= {
             ''{ddd](@' => 'dfdfdfdd'${ggg@';
          }


As you can see I have too many chars which would break the perl syntax. This is because both the key and the value I'm writing could contain characters like '"[EMAIL PROTECTED] etc...

Actually there's only 2 characters you need worry about (') and (\).

You could replace any single occurrences with a (\')
and (\\).

e.g. for the above example

      key = '{ddd](@
      value = dfdfdfdd'${ggg@


I simply needed a mechanism which would escape these characters for me. Turns out I was reinventing the wheel somewhat, and Data Dumper does everything I wanted. I've just never thought about using it to dump temporary data files and then parse them back in again. - currently there aren't any show stopping taint issues.

You might also want to check out the Storable module.

--
  ,-/-  __      _  _         $Bill Luebkert
 (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to