in reply to seeking improvement in my smiple program using regular expression

At a guess, something like this ???
#!/usr/bin/perl -s use strict; my $count = 1; while (<>) { my @fields = split; print "@fields[0..16] ", $count++, " $fields[18]\n"; }
  • Comment on Re: seeking improvement in my smiple program using regular expression
  • Download Code

Replies are listed 'Best First'.
Re^2: seeking improvement in my smiple program using regular expression
by convenientstore (Pilgrim) on Aug 05, 2007 at 08:43 UTC
    hmmmm
    My code works, but I thought writing out ([^ ]+)(?:\s+) 18 times was stupid
    I thought there could be a way to do this
    ([^ ]+\s+){17}(\d{1,3})(?:\s+)
    But clearly above is not correct..
    your split code is neat though.. Let me look into that as well
      s/((?:\S+\s+){17})\d+(\s+\d+)$/$1$count$2/;