Leser: 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
my $collection_times = "Mo-Fr 10:00; Sa 10:00; Su 11:00;"; CreateCollectionTimeTable(); sub CreateCollectionTimeTable { my(@days) = split( /;/, $collection_times ); foreach $day (@days){ $_ = $day; s/^\s+//; # fuehrende Leerzeichen entfernen s/\s+$//; # nachfolgende Leerzeichen entfernen my($dayname,$daytime) = split( / /, $_ ); print "|".$dayname."| - |".$daytime."|\n"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $collection_times='Mo-Fr 15:00,18:00,19:00,23:00; Sa 15:00; Su 10:30,23:00'; my @collection_list; for my $collection (split(/;\s*/,$collection_times)) { my ($day,$time)=split(/\s+/,$collection,2); # ist es wirklich ein Wochentag? (mo tu we th fr sa su) if($day=~/^[motuwehsa-]+$/i) { my @time=split(/\s*,\s*/,$time); push(@collection_list,{day=>$day, time=\@time}); } } print Dumper(\@collection_list);