Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Apr 2004 13:46:36 -0400 (EDT)
From:      "Aaron Peterson" <aaron@alpete.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: perl  coding ?
Message-ID:  <47729.162.114.211.139.1082569596.squirrel@mail.alpete.com>
In-Reply-To: <4086AF7E.5050102@ukug.uk.freebsd.org>
References:  <MIEPLLIBMLEEABPDBIEGMEHHFMAA.Barbish3@adelphia.net> <4086AF7E.5050102@ukug.uk.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
>> An temp field $dup-counter contains an counter that is
>> suffixed with x as in 23x  have no idea how big of an
>> number the counter can grow to. The suffix is all ways
>> one position but has different alpha values.
>>
>> How do I separate $dup-counter into two new  fields?
>> $dup-number  and  $dup-sufix

> This will do it:
>
> $dup-number = substr($dup-counter, 0, length($dup-counter) - 1);
> $dup-suffix = substr($dup-counter, -1, 1);

or alternately:

($dup-number,$dup-suffix) = $dup-counter =~ /(\d+)(\w+)/;

the regex could be loosened or made more strict as needed...
aaron



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47729.162.114.211.139.1082569596.squirrel>