Reading into a two-dimensional array from STDIN 
Author Message
 Reading into a two-dimensional array from STDIN

Greets and Salutes,

I would like to read into a two-dimensional array after getting the input
from parsing an Apache log.

I start with lines (in the access_log) which look like this:
203.135.248.191 - - [27/Mar/2002:12:20:56 -0500] "GET
/sunysb/swebsock/0014879/0815702/SUNYSB/center.cml?12+5+x+x+x+x+x+x
HTTP/1.0" 200 9939
203.135.248.191 - - [27/Mar/2002:12:21:13 -0500] "GET
/sunysb/swebsock/0014879/0815702/SUNYSB/confhome.cml?19+6+225+x+x+x+x+x
HTTP/1.0" 200 18127

perform some grep(ing) and awk(ing) to get multiple occurrences of:
ctl1 view.cml
sunysb center.cml
sunysb center.cml
sunysb center.cml
synysb confhome.cml
synysb confhome.cml

The first is a directory, the second is a filename in that directory.  I
would like have a per-directory count of hits on a particular file then
email the results:
echo "Directory $dir had $count hits on file $filename." >> $file_to_email

I understand that first I must read the $dir and $filename into an array,
which I may then traverse in order to keep a count of occurrences.  How
exactly do I read into that array?

TIA,
Godwin



Sun, 19 Sep 2004 08:41:05 GMT  
 Reading into a two-dimensional array from STDIN

Quote:

> perform some grep(ing) and awk(ing) to get multiple occurrences of:
> ctl1 view.cml
> sunysb center.cml
> sunysb center.cml
> sunysb center.cml
> synysb confhome.cml
> synysb confhome.cml
> I understand that first I must read the $dir and $filename into an array,
> which I may then traverse in order to keep a count of occurrences.  How
> exactly do I read into that array?

The best place to start is at the beginning. If you knew anything
about perl at all, you'd know that you can do everything you want to
do here, without external grepping or awking, or two-dimensional
arrays.

I would use a hash. The directory is the name of the hash, the file as
the key of the hash, and keep count using the value of the hash.
However, there are as many ways to do any given thing in perl as there
are people using perl.



Mon, 20 Sep 2004 02:38:10 GMT  
 Reading into a two-dimensional array from STDIN
I appreciate your point in the right direction.  If I may extend my welcome
to ask for pointers on "hash", I'd be even more appreciative.  Trouble is, I
don't really know Perl other than to know is a great data extraction tool.

tnx,
Godwin



Quote:
> > perform some grep(ing) and awk(ing) to get multiple occurrences of:
> > ctl1 view.cml
> > sunysb center.cml
> > sunysb center.cml
> > sunysb center.cml
> > synysb confhome.cml
> > synysb confhome.cml

> > I understand that first I must read the $dir and $filename into an
array,
> > which I may then traverse in order to keep a count of occurrences.  How
> > exactly do I read into that array?

> The best place to start is at the beginning. If you knew anything
> about perl at all, you'd know that you can do everything you want to
> do here, without external grepping or awking, or two-dimensional
> arrays.

> I would use a hash. The directory is the name of the hash, the file as
> the key of the hash, and keep count using the value of the hash.
> However, there are as many ways to do any given thing in perl as there
> are people using perl.



Mon, 20 Sep 2004 04:44:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Weird Hash w/ n-dimensional two-dimensional array !!!!!!

2. Associative array of a two dimensional array

3. 2-dimensional array into 1 dimensional array?

4. two-dimensional arrays

5. how to build two dimensional array?

6. how to build two dimensional array?

7. Two dimensional array

8. Different ways of initialising a two dimensional array

9. Dynamic Two-Dimensional Array Creation?

10. two-dimensional arrays, lists, whatever

11. sort a two-dimensional array....

12. Two dimensional array

 

 
Powered by phpBB® Forum Software