The program:
--
#use strict;
use warnings;

my $field = shift @ARGV;
my $regex = '(\w+)\s*' x $field;

while (<STDIN>) {
        if (/$regex/) {
                print "$$field\n";      # refers to a match variable
        }
}
--

Example Usage: 
--
$ echo 'Strange New World!' | ./this_program 3
$ World
--

How could I do this with 'use strict' turned on? 




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to