Link to home
Start Free TrialLog in
Avatar of robocop100
robocop100

asked on

Perl string parsing

I have a string with the value:

200 result=12345

There is sometimes a newline character after the 5, sometimes not.

Using Perl how can I extract 12345 into a new variable?
Avatar of Ivan Kulchytskyi-Kostyk
Ivan Kulchytskyi-Kostyk
Flag of Ukraine image

$subject = "200 result=12345";
if ($subject =~ m/=(\d{1,5})/m) {
	$result = $&;
} else {
	$result = "";
}
print $result;

Open in new window

Avatar of robocop100
robocop100

ASKER

the string result may be of unknown length (it's just 5 in this example)
ASKER CERTIFIED SOLUTION
Avatar of Ivan Kulchytskyi-Kostyk
Ivan Kulchytskyi-Kostyk
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wilcoxon
Even simpler...

$string = "200 result=12345\n";  # below works with or without the newline in the string
$string =~ m{=(.*)$};
$result = $1;