Gossamer Forum
Home : General : Perl Programming :

Extracting work times

Quote Reply
Extracting work times
Hi, I'm kinda stuck. I would really appreciate it if someone here could tell me how to extract times from a relatively simple schedule file using perl's reg exps. I'm still pretty new to perl. The format of the line is as follows:



Last, First<big white space>8:00a-12:00n<more white space>Not Av<white space>Req Off<white space>Off



There are seven days worth of scheduled work times. I believe I can extract the names pretty easily myself (low priority), but I cannot seem to get it to extract the times correctly. Here's where I'm at:

if ($whatever =~ /(..:...-..:...)|(Not\ Av)|(Off)|(ReqOff)/) {
$d1 = $1; $d2 = $2... and so forth;

}



Can anyone help me? Thanks a lot!
Quote Reply
Re: [cogito-ergo-sum] Extracting work times In reply to
Hello cognito-ergo-sum,

I looked at your stuff and tried :

# Last, First<big white space>8:00a-12:00n<more white space>Not Av<white space>Req Off<white space>Off

$sentence = 'Smith,John 8:00a-12:00n Not Av Req Off Off';

($last,$first,$time,$w1,$w2,$w3) = $sentence =~/(\w+)\W(\w+)\s+(\d+:\d+\w-\d+:\d+\w)\s+(\w+\s\w+)\s+(\w+\s\w+)\s+(\w+)/;

print " 1. $last 2. $first 3. $time 4. $w1 5. $w2 6. $w3 ";


Results in : 1. Smith 2. John 3. 8:00a-12:00n 4. Not Av 5. Req Off 6. Off


So this may work if your data is in the same format as above $sentence , or just adjust to suit.

if this does not work or Ya need More explanations or corrections please post an example of the data for a regExp.

Thanks

cornball

See also a RegExp thingy like : http://www.itlab.musc.edu/docs/perl_regexp/

Last edited by:

cornball: Sep 19, 2003, 7:50 PM