[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] An interesting problem...



I wrote this small program on a Unix box.  I haven't tried
this with MacPerl yet but I thought I'd pass it along.  On
our system (which is running Perl v5.003) this produces the
following output:

RO|jecase@s-m-s.com|3094|Re: 486DX2-50, hard drives, monitors (flame followup--long).
RO|jecase@s-m-s.com|1|3094

RO|ksmith@genoa.jsc.nasa.gov|892|twork off s
RO|ksmith@genoa.jsc.nasa.gov|1|892

RO|shores|1684|Re: Perl
RO|shores|1|1684

RO|cwilkey@u.washington.edu|2937|Re: Printer & Modem porters and Web servers
RO|cwilkey@u.washington.edu|1|2937

Where the first line is what I was expecting and the second
line is what I got with "%i" in the third location.  The
interesting thing is that all of the lines have a "1" stuck
into the position of the "%i".  Any ideas?  Thanks!  Here
is the program:

#!perl
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
#   Routine which returns the list of available mail messages.
#
    @theMail = ();
    $mailFile = $ENV{'MAIL'};
    open( MAIL, $mailFile ) || die "Could not open $mailFile - aborting.\n";
    @theMail = <MAIL>;
    close( MAIL );

    $msgNumber = -1;
    @whoFrom = ();
    @theSubject = ();
    @theStatus = ();
    @theLength = ();
    @msgStart = ();
    for( $i=0; $i<=$#theMail; $i++ ){
        if( $theMail[$i] =~ /^From /i ){
            $msgNumber++;
            $msgStart[$msgNumber] = $i;
            @theLine = split( / /, $theMail[$i] );
            $whoFrom[$msgNumber] = $theLine[1];
            }

        if( $theMail[$i] =~ /^Subject\: /i ){
            @theLine = split( / /, $theMail[$i] );
            $theLine[0] = " ";
            chop( $theLine[$#theLine] );
            $theSubject[$msgNumber] = join( " ", @theLine );
            $theSubject[$msgNumber] =~ s/^\s+//;
            }

        if( $theMail[$i] =~ /^Status\: /i ){
            @theLine = split( / /, $theMail[$i] );
            chop( $theLine[1] );
            $theStatus[$msgNumber] = $theLine[1];
            }

        if( $theMail[$i] =~ /^Content-Length\: /i ){
            @theLine = split( / /, $theMail[$i] );
            $theLength[$msgNumber] = $theLine[1];
            }
        }

    $msgStart[$msgNumber+1] = $i;
    for( $i=0; $i<=$msgNumber; $i++ ){
        if( $theLength[$i] < 1 ){
            $curLength = 0;
            for( $j=$msgStart[$i]; $j<$msgStart[$i+1]; $j++ ){
                $curLength += length( $theMail[$j] );
                }

            $theLength[$i] = $curLength;
            }
        }

    for( $i=0; $i<=$msgNumber; $i++ ){
        printf( "%s|%s|%s|%s\n", $theStatus[$i], $whoFrom[$i], $theLength[$i], $theSubject[$i] );
        printf( "%s|%s|%i|%s\n", $theStatus[$i], $whoFrom[$i], $theLength[$i], $theSubject[$i] );
		print "\n";
        }

    exit( 0 );