Peter Davis wrote:

> I'm keeping my e-mail in MH format, which means each folder is a
> directory, and each message is in a separate file, and the filename is
> the message number.  Now I'm writing a Perl script to re-sort messages
> into different folders, so I need to find the highest number already in
> the folder, so I can add one to it and use that as the new filename.
> 
> I've been using the following code, but I wonder if there's a faster,
> more efficient way:
> 
> $mailstore = "C:/home/Mail";
> # Get number of messages
> $inboxpath = $mailstore . "/inbox";
> opendir(DIR, $inboxpath);
> @msgnums = grep { /^,?[0-9]*$/ } readdir(DIR);
> closedir(DIR);
> 
> # Find highest message number
> $maxmsg = 0;
> foreach $msgnum (@msgnums) {
>     if (substr($msgnum, 0, 1) eq ",") {
>         chop $msgnum;

Why are you chopping filenames that start with , ?
Shouldn't you be removing the , instead ?

>     }
>     if ($msgnum > $maxmsg) {
>         $maxmsg = $msgnum;
>     }
> }
> $nxtmsgnum = $maxmsg + 1;
> 
> 
> Ideas?

You could just sort them and use the first (or last) element
as the number (depending on sort order).

        my $nxtmsgnum = (sort { $a <=> $b } @msgnums)[-1];

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to