I am doing the following:
my $cookie = $r->headers_in->{'Cookie'};
my @cookieArray = split(/\;\s/,$cookie);
my %hashMap;
my $cookieItem;
foreach $cookieItem (@cookieArray){
my @subArray = split("=",$cookieItem);
my $key = $subArray[0];
my $value = $subArray[1];
$hashMap{$key}=$value;
}
my $userid;
if (exists($hashMap{'USERID'})) {
$userid=$hashMap{'USERID'};
} else {
return OK;
}
I was just wondering if I can do something much quicker than this. I need to
use it inside Apache and need it to be as lightweight as possible.
Thanks
Sumit
-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: Fri 2/23/2007 1:51 PM
To: [email protected]
Cc: Sumit Shah
Subject: Re: Perl Parsing
Sumit Shah wrote:
>
> I have a string like: 'a = 1; b = 2; c = 3; d = 4'
>
> Whats the best way to parse it so that I can get a value for c, which
is
> 3? I have used the hash approach. But, I was wondering if there is a
> faster way to do it in Perl.
What do you mean by 'the hash approach'? Can you post some code that
you've
written so that we can better understand what it is you're trying to
do? It
would also be nice to see some of the actual data you need to process,
as I
assume what you've shown is a simplification (otherwise all you would
need to
write is $c_value = 3).
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/