Kevin Old wrote: > > Hello all, Hello,
> I have run into a situation that I've never faced before. I've always > parsed delimited (comma, pipe, etc) data. Now I'm faced with parsing > fixed-width data. That's fine and I understand how to do it and have > even found a module for it (Parse::FixedLength). You would usually use unpack() for this. > Say I have the following string and the first 10 characters are the > first name, the second 10 are the last name and the next 7 are the > price. > > Kevin Old001.000 1234567890123456789012345678 Usually, text fields in fixed length format are left justified. > I understand that with the name fields I can just strip off the \s > characters and then I have my first name, but what about the price? > Some times it could be like 1000.00 or 0100.00....but with the preceding > zeros it makes it confusing. Do I need to explicitly strip off the > preceding zeros? No. > Any help on dealing with fixed width data is appreciated, my $record = ' Kevin Old001.000'; my ( $first, $last, $price ) = unpack 'A10 A10 A7', $record; # If the fields are right justified then: my ( $first, $last, $price ) = map { s/^\s+//; $_ } unpack 'A10 A10 A7', $record; Note that the 'A' format to unpack will automatically strip trailing whitespace. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]