Andrew Libby on 18 Jan 2006 13:24:20 -0000 |
Hello Eric, Even though you've solved the problem, I'd think that you could use split to accomplish the task. The first parameter to split can be a regular expression or a string. Provided your field values won't have any whitespace in them, you can probably get away with something like this: while(<FILE>) { my ($f1, $f2, $f3, $junk, $junk2, $data) = split(/\s+/); } OR if you really only want the sixth column, you might try something like this: while(<FILE>) { my $data = ( split(/\s+/) )[5]; } Hope this helps. Andy Eric wrote: >Replying to my own question: I've decided to just edit the file manually >and remove the tabs and/or re-align the columns as necessary. The file >is a "translation table" and should not change (at least not frequently.) > >Eric > >On Tuesday 17 January 2006 6:55 pm, Eric wrote: > > >>I know there are perl hackers about... >> >>I have a file - a typical line might look like this: >> >>1 1 1 Ownership FeeSimple Fee >> >> >Simple > > >>The desired data is the last field - indexed by the first three and forget >> >> >the > > >>other two. The "hitch", if you will, is that I'm using unpack to get the >>fields like this: >> >>#!/usr/local/bin/perl >>open EAT, "<Translation.txt" or die "bummer dude - no file?\n" ; >>while (<EAT>) { >> ($f1, $f2, $f3, $junk, $junk2, $data) = unpack("a10, a9, a8, a26, a18, a35 >> >> >", $_) ; > > >> print $data ; >>} >> >>Some, but not all, of the rows in this file use TABS to keep the columns >>aligned. That's all well and good but perl then grabs more characters >>than I want it to thereby 'nipping' a random amount off the front of my >> >> >data. > > >>Is there a way to get perl to deal with the columns instead of the >> >> >characters? > > >>Thanks, >>Eric >>-- >>------------------------------------------------------------------------ >># Eric A Lucas >># ------------ >># "Oh, I have slipped the surly bond of earth >># and danced the skies on laughter-silvered wings... >># -- John Gillespie Magee Jr. >>___________________________________________________________________________ >>Philadelphia Linux Users Group -- http://www.phillylinux.org >>Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce >>General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug >> >> >> >> >> > > > -- Andrew Libby alibby@philadelphiariders.com http://philadelphiariders.com/ Motorcycle Enthusiasm, Philadelphia Style 1999 SV650 1999 Laverda 750S 1996 BMWR1100RS 1981 Moto Guzzi CX100 (in Lemans I clothing) ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|