Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
there must be good CPAN module. Below is not good...
I wonder why my code becomes so ugly...
use strict; use warnings; use Date::Manip::Date; my $date=new Date::Manip::Date; open my $fh, '<', "/etc/crontab" or die $!; foreach my $line (<$fh>){ chomp $line; #skip SHELL=,PATH=,comment,empty line next if ( $line=~ /^SHELL/ || $line =~ /^PATH/ || $line =~ /^#/ || + $line=~ /^$/); #skip @reboot,@hourly, etc next if ( $line =~ /^@/ ); my ($min, $hour, $day, $month)=(split(/\s+/, $line))[0 .. 3]; foreach my $target (\$min, \$hour, \$day, \$month){ $$target=expand2commasep($$target); } my $error=""; foreach my $e_month (split(/,/, $month)){ foreach my $e_day (split(/,/, $day)){ foreach my $e_hour (split(/,/, $hour)){ foreach my $e_min(split(/,/, $min)){ $e_min=sprintf("%02d",$e_min); $e_hour=sprintf("%02d",$e_hour); $e_day=sprintf("%02d",$e_day); $e_month=sprintf("%02d",$e_month); if( $date->parse_format( "%Y/%m/%d %H:%M:%S", ,"2011/$e_month/$e_day $e_hour:$e_min:01")){ $error.="#############################\n"; $error.="LINE=$line\n"; $error.="target date/time=2011/$e_month/$e_day + $e_hour:$e_min:01\n $error.=$date->err . "\n"; } } } } } if( $error ne ''){ print $error; } } close $fh; sub expand2commasep{ my ($val) = @_; # 1-9 format to comma separated list while ( $val =~ /(\d+)-(\d+)/ ){ my $buff=''; foreach my $item ( $1 .. $2){ $buff .= $buff eq '' ? $item : "," . $item; } $val =~ s/\d+-\d+/$buff/; } #*/d format to 1 if ($val =~ m^\*/(.*)^ ){ if ($1 =~ /\d+/){ $val=~ s^(\*/\d+)^1^; } else { print "error: not numeric $val\n"; } } #* to 1 if ($val =~ /\*/ ){ $val=~ s/\*/1/; } return($val); }

In reply to Re^2: To get first non-active date from cron entry by remiah
in thread To get first non-active date from cron entry by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-12-06 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?