Herman,
Depending on the context of the string you want to parse there is more than
one way to do it (correction in perl there is always more than one way to do
it TIMTOWTDI) ..

$string = " ... your string here ... ";
$string = substr($string,-9,9);

the above solution is assuming you do only want the last 9 digits of the
string.  Personally this will not be the first solution to come to my mind
(although after reading Effective Perl Programming I am starting to think that
sibstr might be more efficient than using split or regexp .. anyone interested
in doing a Benchmark.pm on them?).  And it is not as
generic as the other solutions but everybody beat me to an answer and I am
just aching to reply to this email ... :->


On Tue, Aug 21, 2001 at 06:28:12AM -0500, Steve Howard shaped the electrons to read:
> If you only have one equals sign dividing what you don't need, and what you
> are looking for:
> 
> $string = "interfaces.ifTable.ifEntry.ifInOctets.4 = 954819405";
> ($key, $val) = split /=/, $string;
> 
> Steve H.
> 
> -----Original Message-----
> From: Ask Bjoern Hansen [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 21, 2001 3:54 AM
> To: Herman Cremer
> Cc: [EMAIL PROTECTED]
> Subject: Re: string "cut"
> 
> 
> On Tue, 21 Aug 2001, Herman Cremer wrote:
> 
> > Hi
> > I have a string from a snmp get function...
> >
> > interfaces.ifTable.ifEntry.ifInOctets.4 = 954819405
> >
> > how can I "CUT" so the value is only 954819405 ?
> 
> with a regular expression.
> 
>   $string =~ s/.* = //;
> 
> would be one way to do it.
> 
> Another way would be
> 
> $string =~ m/ = (\d+)/;
> my $value = $1;
> 
> 
> which could be better written as:
> 
> my ($value) = ($string =~ m/ = (\d+)/);
> 
> 
>  - ask
> 
> --
> ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to