On Thu, Mar 22, 2007 at 02:36:08PM -0400, Mike Freyberger wrote:
> I am very new at this... but I am trying.
> My closest attempt is this:
>
> #!/usr/local/bin/perl -p
> $z = "32207";
> s/(ADNUM: )\d+/$1+$z . ++$x/ge;
This is very close. In Perl, a plus sign is always used for adding
numbers; the concatenation operator is period:
#!/usr/local/bin/perl -p
$z = "32207";
s/(ADNUM: )\d+/$1 . $z . ++$x/ge;
There are various ways to get a formatted date in Perl.
One way is to call localtime() and format the results:
my($day, $month, $year) = (localtime)[3, 4, 5];
$month++; # month starts at 0
$year %= 100; # convert year to 2 digits
my $date = "$month$day$year";
If you don't mind a suggestion about your ids... If you format the date as
YYYYMMDD rather than MDDYYYY, the numbers will sort in chronological
order. Also, you could pad the extra number as well. [*]
Here's an example of that, and also an example of another way to format the
date, using POSIX::strftime:
#!/usr/local/bin/perl -p
use POSIX qw/ strftime /;
# just set $date once at the beginning,
# rather than each time through the loop
BEGIN { $date = strftime("%Y%m%d", localtime); }
# 3 digits for the extra number allows up to 999 adnums per day
s/(ADNUM: )\d+/$1 . $date . sprintf "%03d", ++$x/ge;
__END__
The Date::Calc module is another popular way to work with dates.
[*] This will also prevent the occasional ambiguity; is 1121011 the first
entry from November 21st, 2001, or the 11th entry from November 2, 2010, or
the 11th entry from January 12, 2010?
HTH,
Ronald
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>