[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

marshalling and serialiing to IO problem

Junkone

6/5/2008 6:34:00 PM

hello
i am trying to serialise a object to file. i have errors when i try to
restore the object. any ideas

for eg
irb(main):009:0> a=Hash.new
=> {}
irb(main):010:0> a[1]='key'
=> "key"
irb(main):011:0> a[1]='kew'
=> "kew"
irb(main):016:0> a=> {1=>"kew"}
irb(main):022:0> f=File.new("c:\\temp\\log",File::CREAT|File::TRUNC|
File::RDWR)
=> #<File:c:\temp\log>
irb(main):023:0> data=Marshal.dump(a,f)
=> #<File:c:\temp\log>
irb(main):024:0> f.close
=> nil
irb(main):025:0> f1=File.open("c:\\temp\\log",File::NONBLOCK|
File::RDONLY)
=> #<File:c:\temp\log>
irb(main):026:0> Z=Marshal.load(f1)
IOError: not opened for reading from (irb):26:in `getc'
from (irb):26:in `load'
from (irb):26
3 Answers

Robert Klemme

6/5/2008 7:45:00 PM

0

On 05.06.2008 20:34, Junkone wrote:
> hello
> i am trying to serialise a object to file. i have errors when i try to
> restore the object. any ideas
>
> for eg
> irb(main):009:0> a=Hash.new
> => {}
> irb(main):010:0> a[1]='key'
> => "key"
> irb(main):011:0> a[1]='kew'
> => "kew"
> irb(main):016:0> a=> {1=>"kew"}
> irb(main):022:0> f=File.new("c:\\temp\\log",File::CREAT|File::TRUNC|
> File::RDWR)
> => #<File:c:\temp\log>
> irb(main):023:0> data=Marshal.dump(a,f)
> => #<File:c:\temp\log>
> irb(main):024:0> f.close
> => nil
> irb(main):025:0> f1=File.open("c:\\temp\\log",File::NONBLOCK|
> File::RDONLY)
> => #<File:c:\temp\log>
> irb(main):026:0> Z=Marshal.load(f1)
> IOError: not opened for reading from (irb):26:in `getc'
> from (irb):26:in `load'
> from (irb):26

Works for me. Why do you open in nonblocking mode? That might cause
issues on your system and it's not needed. Also, why do you open in RW
mode when you want to write only?

Here's what I usually do

irb(main):001:0> a={1=>2}
=> {1=>2}
irb(main):002:0> File.open("foo","wb") {|io| Marshal.dump(a,io)}
=> #<File:foo (closed)>

irb(main):007:0> File.open("foo","rb") {|io| Marshal.load io}
=> {1=>2}

If you prefer boolean flags:

irb(main):009:0> File.open("foo", File::WRONLY | File::BINARY) {|io|
Marshal.dump(a,io)}
=> #<File:foo (closed)>
irb(main):010:0> File.open("foo", File::RDONLY | File::BINARY) {|io|
Marshal.load io}
=> {1=>2}

Cheers

robert

ropeyarn@gmail.com

8/12/2008 12:31:00 AM

0

Karen Burns wrote:
> ropeyarn@gmail.com wrote:
>> fvicarel3@aol.com wrote:
>>> And only partially for the right reasons..
>>>
>>> There. I admitted it.
>>
>> This is my first summer olympics with high def.
>>
>> Oh my.
>
>
> Ditto! I am actually enjoying watching handball?!? I don't think I had
> ever even heard of it before, but in HD, I can't not watch.
> Mens' Archery today (Italy/Korea) was cool, too.


During the opening ceremony's, they mentioned China's Project 119
(designed to up the PRC's gold medal count in track and field, swimming,
rowing, sailing and canoe/kayak)..from their *one* of the 119 available
in Sydney in 2000.

So, I was watching me some archery over the weekend. And wondering if a
50-something, with four years of good corporate sponsorship, top quality
teaching and no other distractions could master the technology needed to
put arrows into the "10" circle in Olympic archery. Mostly it looked
like a technology solution more than athletic event...

I'm sure I'm underestimating how hard it is.

But seems like somebody in my demographic has a better shot at that than
winning the 100 meter dash...


Karen Burns

8/12/2008 1:22:00 AM

0

ropeyarn@gmail.com wrote:
> Karen Burns wrote:
>> ropeyarn@gmail.com wrote:
>>> fvicarel3@aol.com wrote:
>>>> And only partially for the right reasons..
>>>>
>>>> There. I admitted it.
>>>
>>> This is my first summer olympics with high def.
>>>
>>> Oh my.
>>
>>
>> Ditto! I am actually enjoying watching handball?!? I don't think I
>> had ever even heard of it before, but in HD, I can't not watch.
>> Mens' Archery today (Italy/Korea) was cool, too.
>
>
> During the opening ceremony's, they mentioned China's Project 119
> (designed to up the PRC's gold medal count in track and field, swimming,
> rowing, sailing and canoe/kayak)..from their *one* of the 119 available
> in Sydney in 2000.
>
> So, I was watching me some archery over the weekend. And wondering if a
> 50-something, with four years of good corporate sponsorship, top quality
> teaching and no other distractions could master the technology needed to
> put arrows into the "10" circle in Olympic archery. Mostly it looked
> like a technology solution more than athletic event...
>
> I'm sure I'm underestimating how hard it is.
>
> But seems like somebody in my demographic has a better shot at that than
> winning the 100 meter dash...
>
>

I am waiting for the Olympics that feature something I consider myself
fairly good at... grocery shopping!
lol