Re: perl extracting substrings from string
- From: "Dean G." <dguttadauro@xxxxxxxx>
- Date: 28 Dec 2006 14:43:21 -0800
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.
.
- Follow-Ups:
- Re: perl extracting substrings from string
- From: DJ Stunks
- Re: perl extracting substrings from string
- References:
- perl extracting substrings from string
- From: archilleswaterland@xxxxxxxxxxx
- perl extracting substrings from string
- Prev by Date: perl extracting substrings from string
- Next by Date: Re: better way to skip first few lines of file read?
- Previous by thread: perl extracting substrings from string
- Next by thread: Re: perl extracting substrings from string
- Index(es):