Re: RE efficiency question.
On Thu, Oct 17, 2002 at 01:56:22PM +0100, Kevin Gurney said: P.S If anyone feels so inclined, a better way of matching the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. Why not split on whitespace? $line =~ s/\*\* TOTALS\s+//; my vals = split /\s+/, $line; Simon
Re: RE efficiency question.
On Thu, 17 Oct 2002, Kevin Gurney wrote: ** TOTALS 5533.860.000.000.00 5533.86 0.00 5533.860.00 5533.86 5533.86 P.S If anyone feels so inclined, a better way of matching the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. unpack is your friend here: [simonwmorpheus perl]$ cat kevin.pl my $test = ** TOTALS 5533.860.000.000.00 5533.860.00 5533.860.00 5533.86 5533.86; my bits = unpack A9A12A12A12A12A12A12A12A12A12, $test; foreach (bits) { print $_,\n; } print bits[1] + bits[5], \n; [simonwmorpheus perl]$ perl kevin.pl ** TOTALS 5533.86 0.00 0.00 0.00 5533.86 0.00 5533.86 0.00 5533.86 11067.72 Perl even does the Right Thing [tm] when you try and add two of the numbers together :) Simon. -- We have normality. Anything you still can't cope with is therefore your own problem
Re: RE efficiency question.
Kevin Gurney wrote: P.S If anyone feels so inclined, a better way of matching the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. In the interest of more than one way, here's something else: pos($_) = 9; # skip first 9 chars push ext, $1 while /(.{12})/g; Belden
Re: RE efficiency question.
On Thu, 17 Oct 2002, Belden Lyman wrote: Kevin Gurney wrote: P.S If anyone feels so inclined, a better way of matching the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. In the interest of more than one way, here's something else: pos($_) = 9; # skip first 9 chars push ext, $1 while /(.{12})/g; Wouldn't it be better to use split with a zero width lookahead assertion? S. -- Shevek I am the Borg. sub AUTOLOAD{my$i=$AUTOLOAD;my$x=shift;$i=~s/^.*://;print$x\n;eval qq{*$AUTOLOAD=sub{my\$x=shift;return unless \$x%$i;{$x}(\$x);};};} foreach my $i (3..65535) { {'2'}($i); }
Re: RE efficiency question.
On Thu, Oct 17, 2002 at 09:37:11PM +0100, Shevek wrote: On Thu, 17 Oct 2002, Belden Lyman wrote: pos($_) = 9; # skip first 9 chars push ext, $1 while /(.{12})/g; No need for the while. pos($_) = 9; # skip first 9 chars push ext, /.{12}/g; Graham.
Re: RE efficiency question.
Shevek wrote: On Thu, 17 Oct 2002, Belden Lyman wrote: Kevin Gurney wrote: P.S If anyone feels so inclined, a better way of matching the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. In the interest of more than one way, here's something else: pos($_) = 9; # skip first 9 chars push ext, $1 while /(.{12})/g; Wouldn't it be better to use split with a zero width lookahead assertion? S. Dunno - I'm having trouble writing such a split. zero width lookahead; not my forte. I assume the use of the lookahead is to skip the pos() ?
Re: RE efficiency question.
On Thu, 17 Oct 2002, Belden Lyman wrote: the numbers would be most appreciated as I'm simply picking everything in a 12 char range each time. In the interest of more than one way, here's something else: pos($_) = 9; # skip first 9 chars push ext, $1 while /(.{12})/g; Wouldn't it be better to use split with a zero width lookahead assertion? Dunno - I'm having trouble writing such a split. zero width lookahead; not my forte. I assume the use of the lookahead is to skip the pos() ? Look at the example in perldoc -f split: print join(':', split(/(?=\w)/, 'hi there!')); Something like that might work. S. -- Shevek I am the Borg. sub AUTOLOAD{my$i=$AUTOLOAD;my$x=shift;$i=~s/^.*://;print$x\n;eval qq{*$AUTOLOAD=sub{my\$x=shift;return unless \$x%$i;{$x}(\$x);};};} foreach my $i (3..65535) { {'2'}($i); }