Ok i got this code wish counts the amount of lines in a file
open ( FH, "news.txt" ) ¦¦ die "Couldn't open that file\n";
while ( <FH> ) {
$count++;
}
$count # contains now amount of lines in file: news.txt
But now i want to count lines that only start with the worth "today"
so i must try something like:
open ( FH, "news.txt" ) ¦¦ die "Couldn't open that file\n";
while ( <FH> ) {
for (@File) {
if ($_ =~ /^$search/);
$count++;
push(@contents,$_);
}
}
but this aint work it gives error or counts all lines with "today" works the other way around ... hehehe
but iwant to count only the lines starting with "today"
please advise ;-)
thx
12 if ($_ =~ /^${search}/);
Line 12 syntax error at /home/web/www/bfa/clean.cgi line 12, near ");"
Here is the full code why?
aint it counting the lines starting with $search
what do i do wrong here?
#######
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
$search = "Today";
$file = "news.dat";
open (F, "$file") ¦¦ die "Can't open - $!\n";
flock(F,2);
for (@File) {
# if ($_ =~ /^$search/) {
push(@contents,$_);
$count++;
}
}
print "the file ($file) contains ($count) lines stating with worth: ($search) \n";
#!/usr/local/bin/perl
#####################
print "Content-type: text/html\n\n";
$file = "news.dat";
$when = "TodaY";
open ( FH, "$file" ) ¦¦ die "Couldn't open that file\n";
while ( <FH> ) {
if ($_ =~ /^$when/) {
$count++;
}
print "i found:$count lines starting with: $when <BR>\n";
}
It counts lines starting with $when but it looks like its loping and still count the other lines as well.
i have a datafile news.dat inside you find this data:
TodaY
TodaY
TodaY
TodaY
TodaY
TodaY
TodaY
TodaY
TodaY
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
Tomorow
now when i rutn the above script its not priting
i found 9 lines ... it keeps looping it print this:
i found:1 lines starting with: TodaY
i found:2 lines starting with: TodaY
i found:3 lines starting with: TodaY
i found:4 lines starting with: TodaY
i found:5 lines starting with: TodaY
i found:6 lines starting with: TodaY
i found:7 lines starting with: TodaY
i found:8 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
i found:9 lines starting with: TodaY
===
While it should print only this:
i found:9 lines starting with: TodaY
whats wrong why looping true each line etc....?