Pam
Something like this should work, as long as the date in the record is
irrelevant and you want to include the full path to the file as its name.
#!/usr/bin/perl -w
our %file = ();
get_data();
print "$_: $file{$_}\n" foreach (keys %file);
#get data, split into date, and url
sub get_data{
open(IN, "/dept/unxmkt/bin/hits_news/data.txt")
or die ("There is no file: $!\n");
foreach (<IN>)
{
chomp;
my ($date, $url) = split / /;
$file{$url}++;
}
close IN;
}
#end get_data
HTH,
Rob
----- Original Message -----
From: "Pam Derks" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 17, 2002 4:54 PM
Subject: Re: problems with scalar(@array)
> my final goal is to loop through each filename and count how many times
each filename appears, example:
> archive/summer.html 2
> arts.html 2
> arttherapy.html 3.
>
>
> for right now, I'm just trying to loop through the array @url.
> Next step would be to compare whats in $line with what's in $url[$i] and
if it's different reset the counter...
>
> my understanding of scalar(@url) is that it should give me the total count
for the number of filenames.
> What I expected $i to do, was to keep increasting to 732 (as this is the
number of lines in the data.txt file)
>
> still confused,
> Pam
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------
> Hi Pam
>
> $i is incrementing. Your loop starts with $i at zero, as shown by your
> trace. The print statement executes, $i is incremented to 1, your test $i
<
> $num is made and found to be false ($i == $num) so the loop executes.
>
> I'm not sure exactly what you're wanting. The line split(/ /, $line) will
> split each record on whitespace, so will return the list ('021211',
> 'archive/summer.html') for the first record. This will assign $date =
> '021211', @url = ('archive/summer.html'), a single-element list.
>
> If you're intending to split on the '/' path separator then I suggest
>
> ($date, $url) = split(/ /, $line);
> @url = split /\//, $url;
>
> which will give $date = '021211', $url = 'archive/summer.html', @url =
> ('archive', 'summer.html'). Is this what you want?
>
> Cheers,
>
> Rob
>
>
>
>
>
> ----- Original Message -----
> From: "Pam Derks" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, December 17, 2002 2:50 PM
> Subject: problems with scalar(@array)
>
>
> > Howdy,
> >
> > why isn't $i incrementing?
> >
> > here's sample of data file containing date and filename:
> > 021211 archive/summer.html
> > 021211 archive/summer.html
> > 021211 archive/tipsheet.html
> > 021211 ats.html
> > 021211 arts.html
> > 021211 arttherapy.html
> > 021211 arttherapy.html
> > 021211 arttherapy.html
> > 021211 award.html
> > 021211 award.html
> > 021211 award.html
> > 021211 award.html
> > 021211 bio.html
> > 021211 bio.html
> >
> > here's the code thus far:
> >
> > 1 #!/usr/bin/perl -w
> > 2
> > 3 get_data();
> > 4
> > 5 #get data, split into date, and url
> > 6 sub get_data{
> > 7
> > 8 open(IN, "/dept/unxmkt/bin/hits_news/data.txt") or die
("There
> is n
> > o file: $!\n");
> > 9
> > 10 open OUT, ">>/dept/unxmkt/bin/hits_news/log.txt") or die
("no
> cant write to out file $!\n");
> > 11
> > 12 my @url = ();
> > 13 my $line = 0;
> > 14 my $date = 0;
> > 15 my $num = 0;
> > 16
> > 17 while ($line=<IN>) {
> > 18 chomp($line);
> > 19 ($date, @url)=split(/ /, $line);
> > 20
> > 21 $num = scalar(@url);
> > 22 print ("num = $num\n");
> > 23
> > 24 for ($i=0; $i<$num; $i++){
> > 25 print ("$i = $url[$i]\n");
> > 26 }
> > 27
> > 28 }
> > 29
> > 30
> > 31
> > 32 close IN;
> > 33 close OUT;
> > 34
> > 35 } #end get_data
> >
> >
> >
> >
> > output:
> > num = 1
> > 0 = archive/summer.html
> > num = 1
> > 0 = archive/summer.html
> > num = 1
> > 0 = archive/tipsheet.html
> >
> > thanks for any help,
> > Pam
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]