hey everybody, i'm working on my any2xml parser and i've run into a
wall. it's recursive and uses the $1, $2 variables extensivly. the problem
is that when i make a recursive call, i want perl to remember the values
of $1, $2 for the current function and not let the recursive call over
write them. it's really not feasible to save all the values i will need
into save $one and $two counter parts because i allow users of my program
to embed perl expresions for later evaluation. this is the simple code i
wrote up to show the problem

sub main {
  $text="123456789";
  foo($text);
  bar($text);
}
sub foo {
  $text = shift;
  if ($text =~ /(.)(.*)/) {#first num in $1, the rest in $2
    foo($2);
    print $1;
  }
}
#if recursive calls did not overright the value (like i want for 
#this particular exersice, then foo would print out 987654321
#but it prints out 999999999
sub bar {
  $text = shift;
  if ($text =~ /(23)/) {
    bar($1);
    print $1;
  }
}
sub baz {
  my $text = shift;
  if ($text =~ /(2)/) {
    print $1;
  }
}
#this is a simple proof that a function call like baz does not overwrite
#bar's value of $1. the second prints out 223... not 22

does anyone have a way for me to keep all the match variables, across
a function call and restore them to their former glory? thanks a bunch
and see you at tuesdays meeting. 

-mike
----------------
Join Hotmail and we'll put an anoying signature at the
and of all your emails to advertise our service to all
your friends.


Reply via email to