[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File reading ?'s



on 6/10/98 3:42 AM , Paul J. Schinder  wrote:

>}
>} open (INFILE, $file) or die "Couldn't open $file";
>}
>} binmode (INFILE);
>
>You don't need this.  binmode is a no-op in MacPerl.  Like Unix, files are
>byte streams; there's no fundamental distinction between binary and text
>files.

Thanks for the clarification.  I didn't seem to work without it either, 
but I figured it couldn't hurt

>}
>}  read (INFILE, $Channels, 1, 21); #Get the number of channels
>
>I think you're expecting byte 21 of the file to be read?  That's not how
>read works.  Read the documentation again.  

>From "Perl 5 for Dummies":

"read(HANDLE, VARIABLE, LENGTH, POSITION);

The Variable is the place where you want to read into, the length is the 
number of bytes to read, and the position is the byte in the file to 
start reading from."

it says that if you leave the Position empty, then it uses the current 
file position, but if you put a number there, that is the starting point. 
 Is this totally wrong?

>This will put one (the next,
>wherever the file pointer happens to be pointing) byte from the file and
>put it in position 21 of $Channels.  

I looked at this in Shuck, and that's exactly what it said. Thanks.

>seek(INFILE,21,0)
>read(INFILE,$Channels,1);

Thanks again.

>} But, changed to this:
>}
>} -----
>}
>} open (INFILE, $file) or die "Couldn't open $file";
>}
>} binmode (INFILE);
>}
>} read (INFILE, $HeadRead, 54, 0);
>}
>} close (INFILE);
>}
>} # Get the info from the Header
>}
>} $Channels = substr($HeadRead, 21, 1);
>
>And *here* you're putting one byte into $Channels, the 21st byte of the
>file, which is not what you're doing above. Do it this way, or learn how to
>use unpack.  Using unpack, you'll be able to fill in all of these with a
>single statement.

I found this function, but don't understand the documentation.  Can you 
give an example of how unpack might be used in this situation?

>} $Depth = substr($HeadRead, 27, 1);
>} $One = substr($HeadRead, 29, 1);
>} $Two = substr($HeadRead, 30, 1);
>} $Three = substr($HeadRead, 31, 1);
>
>
>
>}
>}
>} -----
>}
>} It worked fine.  Am I missing something about the "read" function?  I
>} used the syntax that I found in my "Perl for Dummies" book...
>
>"Perl for Dummies" really documents read this way?  If so, you need a real
>book. Go out and buy "Programming Perl", by Wall, Christiansen & Schwartz
>("the Camel"), which is the definitive reference for Perl.

Well, if it reads like the Shuck documents, it won't do me any good.  Is 
this an overtechnical read in which you are already supposed to 
understand the syntax of Perl in order to get anything out of it?  I 
wouldn't want the definitive guide to internal combustion engines to find 
out where the nearest gas station was ;-)

>}
>} Also, how do you read in the "Resource" fork?  I think that the info for
>} Sound Designer 2 files are located there.
>
>Mac::Resources is probably the way you want to do it.  Heed the warnings in
>the documentation for it, which can be reached from the Help menu of
>MacPerl.

Thanks again for the great info!  I think I found what I was looking for. 
 Where would I be able to find Inside Macintosh on the web?

Thanks,

Jeremy

Jeremy Lee                     |   Owner- 
Sound Designer/Technician      |   Madrone Ridge Sound Design
Oregon Shakespeare Festival    |   Sound for Multimedia
                               |
                 http://www.ashland.net/madrone
-------------------------------------------------------------------------
"Is it not strange that sheeps' guts should hale souls out of men's 
bodies?"  
        -  Wm. Shakespeare

"The mime sang:"  - Alfred Jarry
------------------------


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch