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

regex patern matching script

Thread Next
Tim Bowden
August 30, 2009 21:46
regex patern matching script
Message ID:
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 (<>){
  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.

Tim Bowden

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About