Message from discussion
Rekenbewerking op text file
Path: g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!131.211.141.196.MISMATCH!humbolt.nl.linux.org!news.nl.linux.org!transit.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Newsgroups: nl.comp.os.linux.programmeren
From: Kees de Koster <r...@dragonhill.xs4all.nl>
Subject: Re: Rekenbewerking op text file
References: <slrnd1loso.emr.root@dragonhill.xs4all.nl> <newscache$hpbbci$x9d$1@news.emea.compuware.com>
X-Face: ;]#0#|ml|Y?*"|nX^FYY3+ZB`((]{I^5?%Yei0wJ(*XwG'?TmkQ`LFJ&OQR&:\l/+F{Ky1m M[3n7"c~MK|G?`ov>or:*\A?-7rwtl^'o9_EyBO=ty?#o)V%}5=yL9PE)QqADi|]0U8dze&Gf5v!r" BuMQ7KMwrTR"mU}g\29hWG\8"Jy^Y\~-@*UyyJ9nQe~+T?|W(yK?pvMn_ZS'fZ3QRVf.qqqGfU5F'R xAK@XV%\%7$6>XxpdIK`8W+x0/K{
Date: Thu, 24 Feb 2005 11:13:39 +0100
Message-ID: <slrnd1ra6j.s09.root@dragonhill.xs4all.nl>
User-Agent: slrn/0.9.8.1-cdk (Debian GNU/Linux)
Lines: 113
NNTP-Posting-Host: 213.84.64.204
X-Trace: 1109240019 news.xs4all.nl 28976 [::ffff:213.84.64.204]:12217
X-Complaints-To: abuse@xs4all.nl
In article <newscache$hpbbci$x9...@news.emea.compuware.com>, Koos Pol wrote:
[...]
>
> Met een Perl scriptje bijv.:
>
> use strict;
> use warnings;
>
> my $line;
> my ($be, $ae); # before equal sign, after equal sign
> my @numbers;
> while ($line = <DATA>) {
> ($be, $ae) = split /=/, $line;
> @numbers = split /,/, $ae;
> pop @numbers;
> @numbers = map {$_ * 4} @numbers;
> print join " ", map {"[$_]"} @numbers;
> print "\n";
> }
>
[...]
Bedankt Koos, (en alle andere natuurlijk) ik heb je voorbeeld gebruikt
om het volgende Perl progje in elkaar te frutselen.
#v+
#!/usr/bin/perl
if ($#ARGV != 2) {
print "usage: input-file output-file factor\n";
exit;
}
$inputfile = $ARGV[0];
$outputfile = $ARGV[1];
$factor = $ARGV[2];
open(IF, $inputfile);
open(OF, ">$outputfile");
my $line;
my ($bl, $el);
my @numbers;
my $volume;
while ($line = <IF>) {
($bl, $el) = split /=/, $line;
if ($bl > 19000000000000) {
@numbers = split /,/, $el;
$volume = pop @numbers;
@numbers = map {$_ * $factor} @numbers;
use integer;
$volume = $volume / $factor;
print OF $bl;
print OF "=";
print OF join "", map {"$_,"} @numbers;
print OF $volume;
print OF "\n";
} else {
print OF $line;
}
}
close(IF);
close(OF);
exit;
#v-
<INPUT>
ChartPath=/home/sircrow/Qtstalker/data/Stocks/AAB
0=Plugin=HorizontalLine|Name=0|Value=19.9431|Plot=Main Plot|Color=#0055ff
19940103000000=8.15,8.36,8.13,8.33,2893070
19940104000000=8.35,8.35,8.26,8.26,4084400
19940105000000=8.33,8.33,8.28,8.3,5622470
20050218000000=21.16,21.28,21.08,21.16,6017510
20050221000000=21.17,21.19,20.82,20.88,6842220
BarType=0
CHARTOBJECTS=0
Plugin=Stocks
Symbol=AAB
Title=AAB
Type=Stock
</INPUT>
<OUTPUT> (factor = 4)
ChartPath=/home/sircrow/Qtstalker/data/Stocks/AAB
0=Plugin=HorizontalLine|Name=0|Value=19.9431|Plot=Main Plot|Color=#0055ff
19940103000000=32.6,33.44,32.52,33.32,723267
19940104000000=33.4,33.4,33.04,33.04,1021100
19940105000000=33.32,33.32,33.12,33.2,1405617
20050218000000=84.64,85.12,84.32,84.64,1504377
20050221000000=84.68,84.76,83.28,83.52,1710555
BarType=0
CHARTOBJECTS=0
Plugin=Stocks
Symbol=AAB
Title=AAB
Type=Stock
</OUTPUT>
Er zullen wel wat niet zulk mooie constructies inzitten maar tis m'n
eerste Perl progje, ga vanmiddag naar de bieb een Perl boek zoeken.
GG
Kees
--
momentum, n.:
What you give a person when they are going away.
11:12:05 up 2 days, 1:47, 4 users, load average: 0.27, 0.07, 0.05
Visit me @ http://www.xs4all.nl/~kostercd/ | ICQ #179658498 -- # EOE