regular expression problem

$string1="1+";
$string2="2+3+4+";

while($string1=~/([^\+]+)/g)
  {$a=$1;
   print("a=$a\n");
   while($string2=~/([^\+]+)/g)
     {$b=$1;
      print("b=$b\n");
      &SomeMoreRegularExpressions($a,$b);
     }
  }

This code is supposed to print output:
a=1
b=2
b=3
b=4

But it prints
a=1
b=2
b=3
b=4
b=3
b=4
b=4
b=4

What is wrong? How can I fix it?
LVL 2
serg111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhurstCommented:
you are doing a while and not chabnging the condition tested in the while.  
0
prady_21Commented:
I tested your code on my system and it is working perfect.
I think you should check the regular expressions after the
print statement.ie after  --print("b=$b\n");

i just did cut and paste and you can check the result


#!/usr/bin/perl

### a test program

$string1="1+";
$string2="2+3+4+5+";

while($string1=~/([^\+]+)/g)
 {
  $a=$1;
  print("a=$a\n");
  while($string2=~/([^\+]+)/g)
    {
     $b=$1;
     print("b=$b\n");
    }
 }





%./resttest.pl
a=1
b=2
b=3
b=4
b=5
0
ozoCommented:
what does
&SomeMoreRegularExpressions($a,$b);
do?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

desktop2Commented:
Problem is somewhere in this function SomeMoreRegularExpressions since without it the while with regular expression is working fine


sub SomeMoreRegularExpressions{
local($ip,$port)=@_;
local(@output,$output,$path);
$childID=fork();
if($childID)
  {return 0; }
if($PathWww=~/([^\/]+)(\/.+)/)
 {$ip=$1;
  $path=$2;
 }
else
 {$path="/";
 }
$socket=IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>$ip,PeerPort=>$port,Reuse =>1,Timeout=>40);
$request="POST $path HTTP/1.0\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 7\n\nr=test\n";
print $socket $request;
@output = <$socket>;
# ===============================
foreach(@output)
  {$output.=$_;}
close($socket);

if($output eq "OK" || ($output=~/\r?\n\r?\nOK/g))
 {return 1; }
else
 { exit; }
}
0
desktop2Commented:
actually $string1 and $string2 contains names of servers and port number to connect
0
jmcgOwnerCommented:
If the code Desktop2 found in one of your other questions is still the code you're using, the explanation of the behavior you are seeing is pretty clear:

Each value found in string 2 results in an additional process. When the output of the request handled by the child is "OK", you end up with both processes continuing to process the list in string2. The first value gets processed by the first child. The original process and the first child both process the second value. And each of them creates a child so there end up being 4 processes working on the 3rd value.

The obvious fix is to change your subroutine so that the child process always exits.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
desktop2Commented:
Thanks, it helped!
mmm... can't find any button to accept this answer
0
serg111Author Commented:
Sorry - I've connected from home computer with different username
0
jmcgOwnerCommented:
Ah, the mystery of how desktop2 knew what was in the subroutine is now solved.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.