in reply to How to extract the different parts of a string stored in a varible?

Now that $text is already defined & has value... following code can be used,
my @txt_arr = split "\n",$text; my $header_hash{"req_line"} = shift @txt_arr; %header_hash = map { my $v = $_; (split /:/, $v)[0] => (split /:/,$v)[ +1] } @txt_arr;
%header_hash will now have keys are the sip header's name & values are values of the sip header.
http://techdiary-viki.blogspot.com/
  • Comment on Re: How to extract the different parts of a string stored in a varible?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to extract the different parts of a string stored in a varible?
by Viki@Stag (Sexton) on Jul 07, 2008 at 11:18 UTC
    sorry abt the mistake... i had not noticed ':' in the header values. Consider this code ...
    my @txt_arr = split "\n",$text; chomp @txt_arr; my $header_hash{"req_line"} = shift @txt_arr; %header_hash = map { (/(.+?):/) => (/.+?:(.*)/) } @txt_arr;


    http://techdiary-viki.blogspot.com/