I'm trying to extend (again) the short regex checking script given in
Learning Perl (Absolutely fabulous book btw! Highly recommend it to
anyone trying to learn Perl).  I'd like to cycle through the memory
variables printing those as well as $`, $& and $' as given in the
original script.  Are these ($1, $2...) stored in some array also?

#!/usr/bin/perl -wT
use strict;

my $regex = shift @ARGV;
print "my regex is: $regex\n";
while (<>){
  chomp;
  if (/$regex/){
    print "matched: |$`<$&>$'|\n";
    # for (@some_memory_array){
    #  print "next memory var:$_\n";
    #}
  } else {
    print "No match :-(\n";
  }
}

Given the regex is being provided as an arg to the script, it's not
possible in advance to predict how many matched memories there will be.

Thanks,
Tim Bowden


-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to