Ask a Question related to PERL Beginners, Design and Development.
-
Danield #1
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
-
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... -
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:... -
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,... -
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... -
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 !=... -
Owen #2
Re: how to construct 2 consecutive if conditions?
On Sat, 24 Jan 2004 17:41:13 -0700
danield <sun_x86@telus.net> wrote:
<snip>>
> 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:
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



Reply With Quote

