Mariana aņez wrote: > > I wrote this two scripts (to do "./mynum | ./mycount" on linux shell): > > mynum: > > #******************************************************************* > # Write a number from 1 to oo > #****************************************************************** > > #!/usr/bin/perl
Because standard input and output are buffered you have to add this line to get the results you want: $| = 1; > my $i=1; > while ($i>0){ > print "$i\n"; > sleep 5; > $i++; > } > > mycount: > > #*********************************************************************** > ****# Read from standard input (STDIN) a number pulsing it with before > number > # and each 10 seconds print the result value on the screen > #*********************************************************************** > **** > > #!/usr/bin/perl > > my $sum=0; > my $first; my $first = 0; If you don't initialize $first you will get a warning when you compare it to zero in your if statement. > my $count; > my $last; > > local $SIG{'ALRM'}=\&on_count; > > alarm 10; > > while ( <STDIN> ) { > my $num = <STDIN>; You are reading every _second_ line from STDIN. Is that really what you want? > chop $num; > next if(!($num=~m/(^([0-9]+)$)/)); > $sum=$sum+$num; > } while ( <> ) { # if you really only want every second line then uncomment the next line # next if $. % 2; chomp; next unless /^\d+$/; $sum += $_; } > sub on_count{ > if ($first==0) > { > $first=1; > $last=$sum; > print "NAN:$sum\n"; > } > else{ > > $count=$sum-$last; > $last=$sum; > print "Contador=$count\n"; > } > > alarm 10; > > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]