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

Re: [FWP] Interpreting a columnar text file.



On Mon, Jun 21, 1999 at 02:02:57PM -0700, Randal L. Schwartz wrote:
> >>>>> "Chaim" == Chaim Frenkel <chaimf@pobox.com> writes:
> 
> Chaim> I found this piece of code useful to generate an unpack format when I
> Chaim> needed to translate a columnar text file.
> 
> Chaim> 	$fmt = "";
> Chaim> 	while(<>) {chomp; $fmt |= $_};
> 
> Chaim> 	$fmt =~ y/ /X/c;
> Chaim> 	$fmt =~ s/(X+\s+)/"A".(length($1)-1)."x"/ge;
> 
> It seems that "foo     bar" would be incorrectly translated to "A3xA3"
> with this?  I don't think you want to collapse \s+ there.
> 

It may seem that way, but what _actually_ happens (i.e. I ran the code) is
that "foo bar" is translated to "A7xXXX".  I guess that Chaim's code
expects each field to be terminated by a space.

Ronald

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org