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

Re: [MacPerl] File reading ?'s



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 1:21 PM +0000 6/10/98, Jeremy Lee wrote:

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

Totally.  (Well, at least the first three are right.)

[snip]
} >} 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?

Not in this particular situation, since I don't know the structure of this
particular header.  But suppose you needed to assign the first six bytes of
the file's contents to six different variables.  You would say something
like:

read(INFILE,$buf,6)

($one,$two,$three,$four,$five,$six) = unpack("CCCCCC",$buf);

Basically what it does is to split the contents of $buf into pieces
according to the provided template.  It's by far the easiest way to split
out something like a header.

[snip]
} >
} >"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 ;-)

It's the definitive guide to Perl, and one of the authors is the inventor
of Perl.  It, like the Perl docs if read in order, will teach you Perl.  No
prior knowledge is necessary, although, as usual, if you've learned a
programming language before, it helps.  It's much the same in style as the
documents, because it was written more or less by the same people.

You might also consider buying Chris and Vicki's "MacPerl: Power and Ease",
but if you're going to seriously use Perl, at some point you either buy the
Camel or print out all the docs.  Buying the Camel is easier, although at
this point it is a little out of date.  The other book to consider is
"Learning Perl", by Randal Schwartz ("the Llama"), which is more
elementary, and there's probably no reason to pick that over Chris and
Vicki's book.

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

You can get to it by starting at
<http://devworld.apple.com/cgi-bin/ftpchooser.pl?partialURL=Technical_Documentat
ion/Inside_Macintosh/>

(which you might have to unwrap by hand to use).

}
} 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
} ------------------------
}

- -----
Paul J. Schinder
schinder@pobox.com

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBNX8fYlZaVc52j0XhEQKFDwCcD7HNU2KV+bHYv+IhFydKw3YYTuMAoNUD
XWKRq37tH/y8D1TKk9DFeVhN
=R4kf
-----END PGP SIGNATURE-----

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