http://qs321.pair.com?node_id=200281


in reply to Positional Pattern-Matching

Perhaps some monks will decrie some inefficiencies in my code, but I think this works fairly well and has been tested:
#!/usr/local/bin/perl -w use strict; use POSIX; # added after observing BrowserUK's code my (%schedule, $backup_type); my $today = strftime( '%A', localtime ); # changed after observing Bro +wserUK's code while (my $line = <DATA>) { chomp $line; my $count = 0 ; if ($line =~ /schedule:\s+(\w+)/i){ my $count++; $backup_type = $1; } if ( $line =~ /(\w+day)\s+(\d{2}\:\d{2}\:\d{2})/i ){ $schedule{$1} = { 'backup_type' => $backup_type, 'time' => $2 }; } } printf "Today is %s and the backup type is %s to begin at %s\n", $today, $schedule{$today}->{'backup_type'}, $schedule{$today}->{'tim +e'}; __DATA__ ...etc
So you're making a hash of hashrefs - the key of the parent hash is the day of the week, and then "type" and "time" are accessible through each day of the week.

Any improvements are welcomed. I may be playing fast and loose with the regex to match the day of the week, depending on what else is in your __DATA__.

--Kozz

edit: removed unneeded /g modifier from regexes, modified code to get current DOW as seen in BrowserUK's code (I learn something every day)