Re: perl extracting substrings from string




archilleswaterland@xxxxxxxxxxx wrote:
$tina = abc_mn123_ln1xy8_dkxhs

I want to get

$mnval = 123;
$lnval = 1;
$xyval = 8;

without using substr thrice.

I tried this .. but this is wrong syntax.

($mnval,$lnval,$xyval) =~ m/^abc_mn(\d\d\d)_ln(\d)xy(\d)_.*$/;

Try this :

($trash,$mnval,$lnval,$xyval) = split /\D+/ $tina;

This splits on any set of non-digit characters, and unless it starts
with a digit, the first value will always be empty and thus "trash".

Dean G.

.