From: Joel VanderWerf Date: 2003-05-17T04:26:39+09:00 Subject: Re: p and perls Data::Dumper Daniel Bretoi wrote: > p is extremely usefl, for debugging etc. > > Perl has it's equivalent with Data::Dumper > > Another thing I've found useful, is that's easy to record a > data structure to a file, then read it back, and getting > the information using eval. > > In perl, I would do > print FILEHANDLE Dumper %somehash > > and I could easily read back everything in the hash. > > Is ther eany way of recording the output of 'p' ? Kernel#inspect returns the string that #p prints. irb(main):001:0> x=[] [] irb(main):002:0> def x.inspect; "inspected!"; end nil irb(main):003:0> p x inspected! nil But for user defined classes, the default #inspect string can't be read in as an object using eval. irb(main):008:0> class Foo; end nil irb(main):009:0> p Foo.new # nil irb(main):010:0> eval Foo.new.inspect nil You may find AMarshal interesting, though: http://raa.ruby-lang.org/list.rhtml?name=amarshal