[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

[perl] for lykke stoppe i utide



følgende perlprogram har jeg lavet for at holde øje med mine ungers (jeg er skolelærer) afleveringer af regnestykker på mail:

#!/usr/bin/perl
#matopg.pl
use warnings;
use strict;

#Vi grepper efter Forkert da antallet af rigtige stykker står i "Forkert-linien" i selve mailen.

my $rigtig = `grep Forkert "/home/magnus/.mozilla-thunderbird/298revko.default/Mail/Local\ Folders/Diverse.sbd/Skolen.sbd/matopg" | sed 's/[^0 1 2 3 4 5 6 7 8 9]//g' | sed 's/3002//g' | sed 's/^ *//g'`;

#skær newline af så vi kan addere
chop $rigtig;

#Skriv listen ud så vi kan se om den lægger rigtigt sammen (DET GØR DEN IKKE;
#DEN STOPPER MELLEM 10 OG 13, HVORFOR!!)


##Diverse test/print " " linier skal slettes når vi er færdige.


print "Her er listen: \n"; print "$rigtig\n\n"; my @liste = split(/ /,$rigtig);

#Hvor mange mails med rigtige resultater er modtaget?

print "hvor mange mails er modtaget:\n";
print scalar @liste, "\n\n";
print "læg sammen:\n";
our $total=0;
for (@liste) {
	
	$total = ((shift @liste)+$total);
	
	#Lad os lige teste og se om den gør det rigtigt undervejs.
	print "$total", "\n\n";
}

print "ialt $total rigtige stykker\n";


Det giver følgende output: sslug@sslug 20:09 ~$ perl matopg.pl Her er listen: 2 5 4 5 5 5 3 2 5 13 10 5 5 5 5 5 5 5 4 15

hvor mange mails er modtaget:
20

læg sammen:
2

7

11

16

21

26

29

31

36

49

ialt 49 rigtige stykker


Som skrevet i mine desperate kommentarer stopper for {} lykken mellem tallene 10 og 13, hvad enten jeg bruger shift eller pop til at hive tal ud af arrayet. Jeg er helt ny udi i perl (og programering i det hele taget), hvad har jeg overset?


/Magnus

--
"Ford, you're turning into a penguin. Stop it."

Douglas N. Adams (1952-2001)

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-09-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *