On 11-02-03 08:05 AM, Téssio Fechine wrote:
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?
#!/usr/bin/perl
use strict;
use warnings;
my $field = shift @ARGV;
my $regex = '(\w+)\s*' x $field;
while (<STDIN>) {
if ( my @capture = /$regex/) {
print "$capture[$field-1]\n";
}
}
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/