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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
parse by matching


New User

Aug 18, 2011, 7:52 AM

Post #1 of 3 (409 views)
parse by matching Can't Post

Hey guys, i'm very new to pearl trying to figure this one out having a really tough time. I have a really long and complex string (actually I have an array of these) from which I need to extract 2 pieces of information. The information I want is prefixed by "Name: " and "Date: ". I got some help which prints me the information I need, but I need to parse those 2 pieces of information into 2 separate variables, $name and $date.

Here is my code:

 foreach( @complexstring ) { 
/^(Name|Date):\s+/i && print $_, "\n";

With 2 elements in my array, this prints me:
Name: Carly
Date: Jun 07 2011
Name: Jessica
Date: Jun 29 2011

I need to parse the 'name' and 'date' into variables $name and $date within the for loop.

Please help. Thank you.

(This post was edited by t6 on Aug 18, 2011, 7:53 AM)


Aug 18, 2011, 8:57 AM

Post #2 of 3 (406 views)
Re: [t6] parse by matching [In reply to] Can't Post

Either the array @complexstring does not contain what you described or this is not the code your are executing! Print and post all of @complexstring for the two samples.
Good Luck,


Aug 18, 2011, 4:20 PM

Post #3 of 3 (399 views)
Re: [t6] parse by matching [In reply to] Can't Post

try this regex change


to get the data after the Name or date and : its saved in the $1 variable.... so

my $NameDate = $1;

this will match if it starts with Name or Date followed by a space 1 or more times then captures everthing beyond that the * means 0 or more. only thing is if you get data in lower cases it will skip it.

(This post was edited by wickedxter on Aug 18, 2011, 4:23 PM)


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

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