SPUG: Data::Dumper for an entire package?

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Wed Jul 11 19:41:11 CDT 2001


> I'd like to dump (and restore later) the state of all the variables in a
> particular package. Is there a way to do this?
> 
> I tried a few things along the lines of
> 
> 	#!/usr/bin/perl -w
> 	use Data::Dumper;
> 
> 	package otherpackage;
> 	$a = 1;
> 	@a = ('a', 'b');
> 	$b = 2;
> 	%b = ('key', 'value');
> 	$c = 3;
> 
> 	package main;
> 	open DATA, ">otherpackage.data";
> 	$data = Dumper (\%otherpackage::);
> 	print $data;
> 	print DATA $data;
> 	close DATA;
> 
> but from looking at the output file (otherpackage.data), that didn't do
> what I was hoping.
> 

Perhaps Dumpvalue is more what you want:

   use Dumpvalue;

   Dumpvalue->new->dumpvars('otherpackage');


   which'll print: 

   $a = 1
   @a = (
     0  'a'
     1  'b'
   ...
   etc.


perldoc Dumpvalue


Rgds,
--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list