P and perls Data::Dumper

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’ ?

an explanation of how p knows what to print would also be helpful.
how is that defined in a class?

db

···


May 16 First report on SNOBOL distributed (within BTL), 1963
May 17 24" rain in 11 hours, Pearl River, S. China, 1982
May 17 Six SLA members killed in televised gun fight, 1974
May 18 Battle of Las Piedras in Uruguay
May 18 Napoleon crowned Emperor, 1804
May 16 Discovery Day in Cayman Islands
May 17 Constitution Day in Nauru and Norway
May 18 Flag Day in Haiti
May 18 Prayer Day in Denmark
May 18 Rick Wakeman is born in West London, England, 1949
May 17* Armed Forces Day (3rd Saturday of May)
May 16* Omer 49th day
May 17* Erev Shavout
May 18* Shavuot (Festival of Weeks; 50 days after Pesach)
May 18* Yizkor

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
#Foo:0x401f5b60
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

I must have made an error while trying something ealier
because a secont attempt to do

fh = File.open …
fh.puts “#{blah.inspect}”

works fine.

db

···

On Sat, May 17, 2003 at 04:19:20AM +0900, 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’ ?

an explanation of how p knows what to print would also be helpful.
how is that defined in a class?

db


May 16 First report on SNOBOL distributed (within BTL), 1963
May 17 24" rain in 11 hours, Pearl River, S. China, 1982
May 17 Six SLA members killed in televised gun fight, 1974
May 18 Battle of Las Piedras in Uruguay
May 18 Napoleon crowned Emperor, 1804
May 16 Discovery Day in Cayman Islands
May 17 Constitution Day in Nauru and Norway
May 18 Flag Day in Haiti
May 18 Prayer Day in Denmark
May 18 Rick Wakeman is born in West London, England, 1949
May 17* Armed Forces Day (3rd Saturday of May)
May 16* Omer 49th day
May 17* Erev Shavout
May 18* Shavuot (Festival of Weeks; 50 days after Pesach)
May 18* Yizkor


May 16 First report on SNOBOL distributed (within BTL), 1963
May 17 24" rain in 11 hours, Pearl River, S. China, 1982
May 17 Six SLA members killed in televised gun fight, 1974
May 18 Battle of Las Piedras in Uruguay
May 18 Napoleon crowned Emperor, 1804
May 16 Discovery Day in Cayman Islands
May 17 Constitution Day in Nauru and Norway
May 18 Flag Day in Haiti
May 18 Prayer Day in Denmark
May 18 Rick Wakeman is born in West London, England, 1949
May 17* Armed Forces Day (3rd Saturday of May)
May 16* Omer 49th day
May 17* Erev Shavout
May 18* Shavuot (Festival of Weeks; 50 days after Pesach)
May 18* Yizkor