On Thu, 4 Nov 2004 10:58:16 -0600, Robert Citek
<[EMAIL PROTECTED]> wrote:
> 
> On Thursday, Nov 4, 2004, at 10:49 US/Central, Scott Pham wrote:
> > Why don't you just split the line and use the whitespace as separator?
> >
> > $line =~ s/\s+/ /;
> > my
> > ($record,$date,$cust,$temp1,$temp2,$temp3,$temp4,$temp5,$shipping,$paid
> > )
> > = split (/ /,$line);
> 
> As I was reminded the other day, split works with an RE, so you can
> skip that first list :
> 
> $ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS      " .
>    "RD    222264       UPSGNDSVR   PREPAID";
>    my ($cust,$shipping) = (split (/\s+/,$line))[2,-2];
>    print "$cust, $shipping\n";'
> DUC000, UPSGNDSVR
> 
> But all that depends on the formatting of the input lines.

Thanks for the replies.  My first thought was to use split on the
spaces, but the "NET 60 DAYS" could throw that off and the fact that
the line can have additional spaces, etc.

I found out that the line I am trying to parse is being produced in
fixed-width, so here's my solution:

my @line = unpack("A8 x1 A8 x1 A6 x1 A16 x1 A5 x1 A13 x1 A11 x1 A9", $_);
$custnum = $line[2];
$isups = $line[6];

Thanks!
-- 
Kevin Old
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to