ruby - Problem with string -
ruby - Problem with string -
i'm doing script in ruby read pack files , see contain. wrote simple script yesterday gives me headache:
arch = file.new(*file_name*, "r") z = arch.sysread(1).unpack('h*') puts z content = arch.sysread(32) the variable z above has value of 10. if pass sysread error, yet if define variable x , assign value of 10 , pass in, runs ok.
why can't pass z sysread?
read file binary, "rb" instead of "r", , said gives error, error?
anyway, unpack function returns array, in case, hexadecimal number string. want this: content = arch.read(z.first.to_i(16)).
this code makes more sense (if trying think):
arch = file.open("filename", "rb") # open file binary z = arch.read(1).bytes.first # first byte integer content = arch.read(z) # read next z bytes ruby string integer fixnum
Comments
Post a Comment