Ask a Question related to PERL Beginners, Design and Development.
-
Danield #1
the same script, the final step, and again does not do what I wnat it to do
Hello all,
Thanks to Charles and Tim, I have advanced to the final step with my
script. After the script verifies that there is line (Summary Log...)
and that the log is from correct year and month. I want it to find a
line where is " Impressions: XX" and retrieve that value.
However I got 0 (zero) as an result, even tough I know that there are
values (Impressions).
The script now looks like:
#!usr/bin/perl -w
use strict;
use Fcntl qw[:flock];
my $impressions = 0;
my $iofile =
'/other/XPSmaint/scripts/billing/daniel/input/c07_impressions_io.info';
open (IO, $iofile) || die("Could not open file 1!");
while (<IO> ) {
chop;
my ($FH, $output, $file2check, $month, $year) = split (/\s+/, $_);
open OUT, ">> $output";
chdir $FH or die "$!";
while (glob $file2check) {
open FH, $_ or die $!;
flock FH, LOCK_SH or die $!;
while (<FH> ) {
chomp;
if ( / Summary Log \(generated:/ ) {
my($emptyspce, $summary, $log, $generated, $day_word, $monthfile,
$day_number, $time, $timezone, $yearfile ) = split(/\s+/, $_);
#print "File $file2check is $monthfile, $year\n";
if ($monthfile eq $month
and $yearfile eq $year){
#print "File has this year: $yearfile and month: $monthfile in it.\n"}
if ( /Impressions:/ ) {
my($text, $value) = split(/:/, $_);
$impressions += $value if ($value =~ /\d+/);
}
}
}
}
close FH or die $!;
}
print OUT 'Total impressions: ', $impressions or die $!;
}
Any suggestions?
Thank you for your time.
danield
Danield Guest
-
Will pay someone to produce for me a step by step, detailed tutorialon how to integrate HTMLAREA or any similar CMS into a DreamWeaver builtsite.
Hi, Why don't you use KTML Lite? It's free and has a Server Behavior for easy usage in Dreamweaver... -
Will pay someone to produce for me a step by step, detailed tutorial on how to integrate HTMLAREA or any similar CMS into a DreamWeaver built site.
Will pay someone to produce for me a step by step, detailed tutorial on how to integrate HTMLAREA or any similar CMS into a DreamWeaver built site. -
FINAL DRAFT script into PDF
I'm new. I have an ibook OSX. I tried to convert a script in Final Draft 6.0 software to PDF, and it said it didn't recognize the file. Final Draft... -
Dialing script step
Is there a way to tell FMP to add a 1 to any number outside a certain area code automatically? So if you use the dialing script step it dials... -
Send mail script step
I have a script to send mail to email addresses in a field (noted in the To: part of the mail specification. When the script is run, the... -
Kenton Brede #2
Re: the same script, the final step, and again does not do what I wnat it to do
On Sat, Jan 24, 2004 at 10:14:24PM -0700, danield (sun_x86@telus.net) wrote:
The following bits of your code seem to work fine for me -> Hello all,
>
> Thanks to Charles and Tim, I have advanced to the final step with my
> script. After the script verifies that there is line (Summary Log...)
> and that the log is from correct year and month. I want it to find a
> line where is " Impressions: XX" and retrieve that value.
> However I got 0 (zero) as an result, even tough I know that there are
> values (Impressions).
>
> The script now looks like:
>
> #!usr/bin/perl -w
>
> use strict;
> use Fcntl qw[:flock];
>
> my $impressions = 0;
> my $iofile =
> '/other/XPSmaint/scripts/billing/daniel/input/c07_impressions_io.info';
>
> open (IO, $iofile) || die("Could not open file 1!");
>
> while (<IO> ) {
> chop;
> my ($FH, $output, $file2check, $month, $year) = split (/\s+/, $_);
>
> open OUT, ">> $output";
>
> chdir $FH or die "$!";
>
> while (glob $file2check) {
> open FH, $_ or die $!;
> flock FH, LOCK_SH or die $!;
> while (<FH> ) {
> chomp;
> if ( / Summary Log \(generated:/ ) {
> my($emptyspce, $summary, $log, $generated, $day_word, $monthfile,
> $day_number, $time, $timezone, $yearfile ) = split(/\s+/, $_);
> #print "File $file2check is $monthfile, $year\n";
> if ($monthfile eq $month
> and $yearfile eq $year){
> #print "File has this year: $yearfile and month: $monthfile in it.\n"}
> if ( /Impressions:/ ) {
> my($text, $value) = split(/:/, $_);
> $impressions += $value if ($value =~ /\d+/);
> }
> }
> }
> }
> close FH or die $!;
> }
> print OUT 'Total impressions: ', $impressions or die $!;
> }
>
> Any suggestions?
#!/usr/bin/perl
use warnings;
use strict;
open OUT, ">> output" or die $!;
my $impressions = 0;
while(<DATA>) {
if (/Impressions:/) {
my($text, $value) = split(/:/, $_);
$impressions += $value if ($value =~ /\d+/);
}
}
print OUT 'Total impressions: ', $impressions or die $!;
__DATA__
Impressions: 23
Impressions: 12
Impressions: 34
__END__
I would try putting "print" in front of -
"$impressions += $value if ($value =~ /\d+/);" and verify it is spitting out
what you want. If it doesn't I suspect the "0" comes from your global declaration
"my $impressions = 0;" That means a problem between the global
declaration and the last line of your inner 'while' loop -
"$impressions += $value if ($value =~ /\d+/);"
Or if the print statement shows
"$impressions += $value if ($value =~ /\d+/);" is spiting out what you
want then possibly "print OUT 'Total impressions: ', $impressions or die $!;"
needs to be moved into you inner while loop.
Just some thoughts.
Kent
--
Kenton Brede Guest



Reply With Quote

