Just wanted to say thanks to everybody -- even though I haven't had a need to do collumns, just from this simple question, I've learned some new stuff and different ways to do things. Cool. (I'm easily amused/entertained ;-). That unpack stuff was neat... wish I'd read that page of the llama a while back... Thanks again for the lightbulb over the head, Matt At 11:31 AM -0600 1/2/97, John Gilmore-Baldwin wrote: >>Hallo, >> >>I have a (text) file with the following format: >> >>123420010110010010101 (and so on this way => ) >>234531111101100101010 >>678940000010010111010 >>340151010101110101010 >>and so on... >> >>Now let's say the first four characters are a PIN number, >>the following two characters the subject's age, and so on. >>How can I read such a file split in (fixed) columns ? >>I would like to insert tabs at the end of each field, creating >>a tab-delimited text file. >> > >Try something along these lines: > >$template = "a4 a2 a2"; > >($pin, $age, $so-on) = unpack($template, $_); > >The "a4 a2 ..." is defining alpha fields for the unpack instruction. So >it'll take the first four chars and make it a field, the next 2 and make it >a field, etc. It's quite handy, and with Perl's loose type checking, quite >flexible. > >templates can do a whole lot more, if you want, and are discusses in the >programming perl books. childress@news-gazette.com http://www.news-gazette.com/