in reply to Re: Extract first word from certain lines in a file
in thread Extract first word from certain lines in a file

my (@w, $c); local ( $", $_ ) = ", "; do { $_ = <DATA>; if ( defined $_ && !/^Product:/ ) { push @w,(split ' ')[0]; } elsif ( @w ) { print "Product: ", ++$c, "\n@w\n"; @w = (); } } while ( defined $_ ); __DATA__ Product: redball This is for Mike. greenball This is for Dave. Product: smallbox This is for apples bigbox This is for orange
output:
Product: 1 redball, greenball Product: 2 smallbox, bigbox
Boris

Replies are listed 'Best First'.
Re^3: Extract first word from certain lines in a file
by CountZero (Bishop) on Oct 26, 2004 at 05:42 UTC
    I was wondering why you use local ( $", $_ ) = ", "; since there is no enclosing scope other than the script file itself. The local does not seem to serve any purpose.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      I t is just good habit.
      Boris