On 2/3/11 Thu Feb 3, 2011 5:05 AM, "Téssio Fechine"
<[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/