On 2/3/11 Thu  Feb 3, 2011  5:05 AM, "Téssio Fechine"
<precheca...@yahoo.com.br> scribbled:

> 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?

Use the @- and @+ arrays, which contain the beginning and ending offsets of
the captured substrings.

See 'perldoc perlvar'.



--
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