>>>>> "TF" == Téssio Fechine <precheca...@yahoo.com.br> writes:

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

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

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

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

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

you don't. it is nasty coding and will bite you for sure down the road. 

it is trivial to deal with in other ways. the simplest is to just assign
the regex results in list context. that will return a list of all the
grabs and you can loop over that. 

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

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