went to 5.8.1 and now my while statement fails

P

pui ming Wong

My script which worked under 5.6.1 failed after I upgraded
to 5.8

The loop codes that failed is as below:
The print count line statement never gets printed at all; why?
------------------------------------------------
# read each message in turn

while( $msg = &read_message ) {
$count++;
print "count line is $count";
}
---------------------------------------------------
and its routine is:
-------------------------------------------------------
sub read_message
{
local( $msg ) = ""; # message to send back
local( $prev_blank ) = 1; # assume previous line blank
local( $seen_from ) = 0; # seen a from line
local( $line ) = ""; # current line

# reset some globals
$msg_status = "";
$msg_subject = "";
$msg_date = "";
while( $line = &get_line ) {

if( $line =~ /^From\s+([^\s]+)\s+(.*)$/ ) {
# if previous line was blank, then legal from line
if( $prev_blank ) {
# if already seen a legal from line, then this is next message
if( $seen_from ) {
# pushback this from line
$line_buffer = $line;
return $msg;
}
$seen_from++;
# From line found, extract information
( $msg_from, $msg_date ) = ( $1, $2 );
$msg_stamp = &rctime( $msg_date );
$msg_age = &days_old( $msg_stamp );
}
} elsif( $line =~ /^[Ss]tatus: ([A-Za-z]+)/ ) { ( $msg_status ) = ( $1 );
} elsif( $line =~ /^[Ss]ubject: (.*)$/ ) { ( $msg_subject ) = ( $1 );
}

# set previous line
if( $line =~ /^$/ ) {
$prev_blank = 1;
} else { $prev_blank = 0;
}

$msg .= $line;
}

return $msg;
}
-------------------------------------
BTW ,The perl routines required are:

require "getopts.pl"; # option handling
require "timelocal.pl"; # time conversion
require "ctime.pl"; # ctime for pseudo-mailing
require "stat.pl"; # file status

Any change to these after upgrade to 5.8 ?
that could be responsible for the failure of my old script?
 
R

Rafael Garcia-Suarez

pui said:
My script which worked under 5.6.1 failed after I upgraded
to 5.8

Which version ? Which OS ?
The loop codes that failed is as below:
The print count line statement never gets printed at all; why?

Probably because $msg is undefined, empty or "0" ?
Since you didn't provide the full source, or (better) the full
source trimmed down to a small example that demonstrates the
problem, it's difficult to figure out what's wrong.
# read each message in turn

while( $msg = &read_message ) {
$count++;
print "count line is $count";
}
require "getopts.pl"; # option handling
require "timelocal.pl"; # time conversion
require "ctime.pl"; # ctime for pseudo-mailing
require "stat.pl"; # file status

Any change to these after upgrade to 5.8 ?
that could be responsible for the failure of my old script?

No. the *.pl old-style libs are provided only for compatibility
with perl 4 scripts and are not maintained or modified anymore.
(I wonder if we shouldn't get rid of them completely, but, as
your code proves, there's still some perl 4-style code running
out there.)

The list of changes between 5.6.x and 5.8.x is outlined in the
perldelta manpage.
 
T

Tore Aursand

while( $msg = &read_message ) {
$count++;
print "count line is $count";
}

Change this to:

while ( $msg = read_message() ) {
print "Message is: '$msg'\n";
$count++;
print "Count line is: $count\n";
}

And tell us what you (don't) see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top