[Tutor] unpack/regexp

Paul Kraus pkraus at pelsupply.com
Tue Apr 11 16:29:25 CEST 2006


Ok sorry for the perl refernce but I can't figure out how to do this.
I have a fixed width text file i need to parse.

so lets say I want an array to containt the pieces i need.
if the fields I want are lengths from left to right.
10 10 13
12345678901234567890123456789012
I want to turn this into an array that has these elements.
1234567890
1234567890
123456789012 <--notice white space

In Perl its a simple
my @array = unpack ( "A10 A10 A13" , $line )
this extracts it and removes the whitespace after doing so.

or if i wanted i could do
my @array = ( $1, $2, $3 ) if ( $line =~ m/^(.{10})(.{10})(.{13}) )


-- 
Paul Kraus
=-=-=-=-=-=-=-=-=-=-=
PEL Supply Company
Network Administrator
216.267.5775 Voice
216.267.6176 Fax
www.pelsupply.com
=-=-=-=-=-=-=-=-=-=-=


More information about the Tutor mailing list