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: Intermediate:
calendar records

 



cycleops
Novice

Dec 3, 2011, 12:18 PM

Post #1 of 3 (1823 views)
calendar records Can't Post

Hi,
I'm trying to separate text into records. The text comes from calendar entries showing the day number followed by the entry for that day (if any). An example of the first 4 days of a month is:

1
blah, blah, blah
over 2 lines

2
3

2nd something or other starting at
8 p.m.

sometimes more than one line for the entry
4

I've tried several approaches with regex and split, but can't seem to capture the date and the entry for the date.
Any help/advice is appreciated.
Thanks in advance.


BillKSmith
Veteran

Dec 4, 2011, 6:15 AM

Post #2 of 3 (1810 views)
Re: [cycleops] calendar records [In reply to] Can't Post

This should get you started.


Code
use strict; 
use warnings;
my @entry;
my $new_day;
while (my $line = <DATA>) {
if ( $line =~ /^([1-9]|[12]\d|3[01])\s*$/ ) {
$new_day = $1;
next;
}
die 'internal error' if !$new_day;
$entry[$new_day] .= $line;
}
for my $day (1..4) {
print $day, "\n", $entry[$day], "\n";
}
__DATA__
1
blah, blah, blah
over 2 lines

2
3

2nd something or other starting at
8 p.m.

sometimes more than one line for the entry
4

Good Luck,
Bill


cycleops
Novice

Jan 30, 2012, 8:04 AM

Post #3 of 3 (1578 views)
Re: [BillKSmith] calendar records [In reply to] Can't Post

That worked.
Thanks very much, Bill.

 
 


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

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