the same script, the final step, and again does not do what I wnat it to do

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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.
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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:
    > 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?
    The following bits of your code seem to work fine for me -
    #!/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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139