On Sun, 3 Jun 2001, Chris Nandor wrote:

> I don't understand this code at all.
sorry for the confusion everyone
> 
> First, I can only assume that main() is supposed to be called first.
yeah i like c :)
> Second, note that you keep changing the value of $text:
i pass each recurence of foo a different version of $text but all
parents retain their value because $text is supposed to be a my variable
i think i skipped out on that when i copied in here.
> 
> At 16:50 -0400 2001.06.01, [EMAIL PROTECTED] wrote:
> >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;
> >  }
> >}
> 
> By the time you get to bar($text), $text is undef, because it has been
> reduced to undef.  If you put my() on each variable, that changes things
> completely.  Now bar() gets the full 9-char value, but it does nothing
> interesting with it:
> 
> >#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;
> >  }
> >}
> 
> You keep calling bar("23") over and over again after the first time it is
> called.  It won't ever stop.
> 
> >sub baz {
> >  my $text = shift;
> >  if ($text =~ /(2)/) {
> >    print $1;
> >  }
> >}
> 
> baz() is never called in your code at all.
> 
> If you give some working code that does what you say, perhaps we can help
> figure it out.
> 
> -- 
> Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
> Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/
> 

Reply via email to