Part one of your question lost me (three times!) in (sic)

" ...and add a new along with a few other changes that I will mention. There aren't any other breaks in the file so as long as it found the FIRST, skipped down ONE line, printed a new ..then that would be fine....

Please, clarify!

However, the second part -- the one you characterize as "much more complicated" -- is not.

Others may well offer better approaches, but perhaps this long-winded but simple code (with lots of prints to help you track what's happening) will be useful. Note, however, that it's only a partial solution.

#!C:/perl/bin use strict; use warnings; our $newdate = 0; our $string = '<a href="SERVER122007/intranet.htm" target="_blank">Dec + 2007</a>'; $string =~ /.+?"SERVER(\d{6}).+blank">([A-Z,a-z]{3}\s\d{4}).*/; our $ds = $1; our $monyr = $2; # changing this may require a dispatch table or a Da +te::xxx module print "\nRaw \$ds is $ds\n"; print "\$monyr is $monyr\nCode to modify this left as exercise (hint a +bove) for the OP\n\n"; if ( $ds =~ /(\d\d).*/) { our $check_yr_change = $1; if ($check_yr_change == 12) { changeyear($ds); } else { print "OK! It's not yet time to change the year\n\n"; $newdate = sprintf( '%.2x',(substr($ds,0,2) +1 ) ) . substr($ds, +2,4); print "\$newdate is: $newdate"; } } ####### sub sub changeyear { use vars qw($mo $oldyr $newyr); $mo = "01"; if ( $ds =~ /\d\d(\d{4})/) { $oldyr = $1; print "\$oldyr: $oldyr\n"; } $newyr = ( $oldyr + 1 ); $newdate= ($mo . $newyr); print "\n\$newdate in sub is: $newdate\n"; } =head OUTPUT for <a href="SERVER072007/intranet.htm" target="_blank">Jul 2007</a>: Raw $ds is 072007 $monyr is Jul 2007 Code to modify this left as exercise for the OP OK! It's not yet time to change the year $newdate is: 082007 and for <a href="SERVER122007/intranet.htm" target="_blank">Dec 2007</ +a>: Raw $ds is 122007 $monyr is Dec 2007 Code to modify this left as exercise for the OP $oldyr: 2007 $newdate in sub is: 012008 =cut

This would be somewhat shorter, were you to use Unix-ish (aka, pretty much standard, internationally) date formats; eg: YYYY-MM-DD. TTBOMK, the verbose form, "Jul 2007," is not a standard, but is common; in any case, incrementing it is less problematic.

Additional hint: Date::Manip is a fine "Leatherman" or "Swiss Army Knife." It handles an enormous range of date_time transformations and calculations, but I found it "not well suited" to this problem (or, maybe, I just didn't find the "well suited" functions) so it may repay you well to see if Date::Calc, Date::Parse and others in the Date::... family.


In reply to Re: string automation by ww
in thread string automation by dhudnall

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.