how to construct 2 consecutive if conditions?

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

  1. #1

    Default how to construct 2 consecutive if conditions?

    Hello all,

    I do have file where is:

    Summary Log (generated: Tue Apr 1 22:02:29 MST 2003)

    And I do have a script which goes through this file line by line. The
    first 'if' condition checks whether I have found the line I am
    interested in (Summary log...) The second 'if' then should check whether
    the month is "Apr" and the year is "2003". The script as it is now is
    not correct, since it evaluates the first condition and splits line into
    variables and then skips the second if.

    The script looks like:

    #!usr/bin/perl -w

    use strict;
    use Fcntl qw[:flock];

    my $impressions = 0;
    my $iofile = '/other/scripts/daniel/input/c07_impressions_io.info';

    open (IO, $iofile) || die("Could not open file 1!");

    while (<IO> ) {
    chop;
    (my$FH, my$output, my$file2check, my$month, my$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, my$summary, my$log, my$generated, my$day_word,
    my$monthfile, my$day_number, my$time, my$timezone, my$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"}
    }
    }
    close FH or die $!;
    }
    # print OUT 'Total impressions: ', $impressions or die $!;
    }

    Thank you for your time.

    danield

    Danield Guest

  2. Similar Questions and Discussions

    1. Query to find MAX(SUM()) of X consecutive fields
      Hello All, I have a database containing measurement data in which data is added every 5 minutes. I would like to get the hour in which the highest...
    2. CF needs to honor consecutive delimeters
      How do I get CF to honor consecutive delimiters? If I have four values and an empty one in a comma-delimited file, then I have something like this:...
    3. InDEsign Newbie - Consecutive numbering of figures in a document. How?
      I've placed text and graphics from a MS Word version of a User Manual that includes consecutively numbered figures for the graphics (eg: Figure 1,...
    4. tell me the best way to re-construct this menu!
      I'm trying to construct a menu much like the one here > http://www.miranda.com/ (center of page) Can I make this menu with complex...
    5. failing elseif construct
      Hi, Can anybody see anything wrong with this: <-- snip --> // some other ifs and elseifs that seem to work okay elseif ($CH_address_same !=...
  3. #2

    Default Re: how to construct 2 consecutive if conditions?

    On Sat, 24 Jan 2004 17:41:13 -0700
    danield <sun_x86@telus.net> wrote:
    >
    > I do have file where is:
    >
    > Summary Log (generated: Tue Apr 1 22:02:29 MST 2003)
    >
    > And I do have a script which goes through this file line by line. The
    > first 'if' condition checks whether I have found the line I am
    > interested in (Summary log...) The second 'if' then should check whether
    > the month is "Apr" and the year is "2003". The script as it is now is
    > not correct, since it evaluates the first condition and splits line into
    > variables and then skips the second if.
    >
    > The script looks like:
    <snip>
    I think I understand your request.

    Just try this. It reads line by line and has the three "if" conditions for a print. See if you can adapt that to your script. Also, chomp is preferred to chop.
    -------------------------------------------------------------
    #!/usr/bin/perl

    #use strict, etc as required as per your original script

    while(<DATA>){
    print if((/Summary Log/) and (/Apr/) and (/2003/))
    }


    __DATA__
    Summary Log (generated: The Apr 1 22:02:29 MST 2003)
    Summary Log (generated: Tue May 1 22:02:29 MST 2003)
    Summary Log (generated: Tue Jun 1 22:02:29 MST 2003)
    Summary Log (generated: Tue Apr 1 22:02:29 MST 2004)
    Summary Log (generated: Tue Apr 1 22:02:29 MST 2004)
    Summary Log (generated: The Apr 1 22:02:29 MST 2003)
    --
    Owen

    Owen 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