CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [davorg] look simple, finding tough to split: Edit Log



MrPJ
User

Feb 17, 2005, 11:34 AM


Views: 9015
Re: [davorg] look simple, finding tough to split

A quick attempt...


Code
my $line = 'first=Andrew last=chapell time="2005:02:14 21:59:59" info="Successfully authenticated" userid=andrew src=45231 dst=3213';  
my $last = 0;
my %temp = ();
my $past = '';

while ($line =~ /((\w+)=)/g) {
my $match_len = length $1;
my $start_pos = $last;
$last = pos $line;
$temp{$past} = substr($line, $start_pos, $last - $start_pos - $match_len) if ($past);
$past = $2;
}
$temp{$past} = substr($line, $last);

print "Content-type: text/plain\n\n";
print map { "$_ => $temp{$_}\n" } sort keys %temp;



(This post was edited by MrPJ on Feb 17, 2005, 11:35 AM)


Edit Log:
Post edited by MrPJ (User) on Feb 17, 2005, 11:35 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives