develooper Front page | perl.beginners | Postings from August 2009

regex patern matching script

Thread Next
From:
Tim Bowden
Date:
August 30, 2009 21:46
Subject:
regex patern matching script
Message ID:
1251693936.4739.32.camel@mordor
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About