parse a log file question

R

robertchen117

hi all,

the log file format is a long list of the item like:
Fri Oct 6 00:00:23 2006: TR_execute_task( Lib/Task: library_name1/
task_name2 run by www.hp.com on 7 targets, out = 257

I want to count the number of targets based on library_name1/
task_name2, but there are many library names and task names, so the
array size not know. How could I do this?

My perl codes is like this:

.....
open (TSK, "more /tmp/task28.log | grep '$now' | grep 'out =' |") or
die "cannot fork: $!";

while (<TSK>) { # count them up.
($foo,$foo,$foo,$time,$foo,$foo,$foo,$taskinfo,$foo,$foo,$foo,
$foo,$targets,$foo,$foo,$foo, $bytes) = split ' ';

should be like array[$taskinfo] += $targets;

How could I define the array or hash dynamicly?

Please help me, thanks.
 
P

Paul Lalli

hi all,

the log file format is a long list of the item like:
Fri Oct 6 00:00:23 2006: TR_execute_task( Lib/Task: library_name1/
task_name2 run bywww.hp.comon 7 targets, out = 257

I want to count the number of targets based on library_name1/
task_name2, but there are many library names and task names, so the
array size not know.

Perl couldn't care less what the size of the array is. Arrays grow
and shrink dynamically.
How could I do this?

My perl codes is like this:

....
open (TSK, "more /tmp/task28.log | grep '$now' | grep 'out =' |") or
die "cannot fork: $!";

while (<TSK>) { # count them up.
($foo,$foo,$foo,$time,$foo,$foo,$foo,$taskinfo,$foo,$foo,$foo,
$foo,$targets,$foo,$foo,$foo, $bytes) = split ' ';

GAH!

my ($time, $taskinfo, $targets, $bytes) = (split ' ')[3,7,12,16];
should be like array[$taskinfo] += $targets;

How could I define the array or hash dynamicly?

Other than the missing dollar sign, what exactly is wrong with that
statement? Did you try it out, or are you simply assuming it doesn't
work?

Please post a short-but-complete script that demonstrates the error
you're experiencing.

Paul Lalli
 
R

robertchen117

Sorry my question should be like this:
Fri Oct 6 00:00:23 2006: TR_execute_task( Lib/Task: library_name1/
task_name2 run bywww.hp.comon7 targets, out = 257

I know I can use $task_hash{$taskinfo} += targets; -->count by lib/
task name.
but problems is I also need to count by time:
output should like this:

9:00am - 9:59am
8,010 task2 lib3 77 targets 200,345 output
3,221 task12 lib3 12 targets 1,530,234 output
....

Do we have hash over hash? What should we implement this?


the log file format is a long list of the item like:
Fri Oct 6 00:00:23 2006: TR_execute_task( Lib/Task: library_name1/
task_name2 run bywww.hp.comon7 targets, out = 257
I want to count the number of targets based on library_name1/
task_name2, but there are many library names and task names, so the
array size not know.

Perl couldn't care less what the size of the array is. Arrays grow
and shrink dynamically.
How could I do this?
My perl codes is like this:
....
open (TSK, "more /tmp/task28.log | grep '$now' | grep 'out =' |") or
die "cannot fork: $!";
while (<TSK>) { # count them up.
($foo,$foo,$foo,$time,$foo,$foo,$foo,$taskinfo,$foo,$foo,$foo,
$foo,$targets,$foo,$foo,$foo, $bytes) = split ' ';

GAH!

my ($time, $taskinfo, $targets, $bytes) = (split ' ')[3,7,12,16];
should be like array[$taskinfo] += $targets;
How could I define the array or hash dynamicly?

Other than the missing dollar sign, what exactly is wrong with that
statement? Did you try it out, or are you simply assuming it doesn't
work?

Please post a short-but-complete script that demonstrates the error
you're experiencing.

Paul Lalli
 
J

Jürgen Exner

the log file format is a long list of the item like:
Fri Oct 6 00:00:23 2006: TR_execute_task( Lib/Task: library_name1/
task_name2 run by www.hp.com on 7 targets, out = 257

I want to count the number of targets based on library_name1/
task_name2, but there are many library names and task names, so the
array size not know.

So what? Arrays in Perl grow dynamically.
My perl codes is like this:
....
open (TSK, "more /tmp/task28.log | grep '$now' | grep 'out =' |") or
die "cannot fork: $!";

Ahhhhh! Is there a specific reason why you are shelling out 3 external
processes for a task that could be done by two lines of Perl internally?
Besides, that's a totally useless use of more(1).
And where is $now coming from?

Suggestion:
open (TSK, "/tmp/task28.log") or die "cannot fork: $!";
while (<TSK>) { # count them up.

Suggestion continued:
if (/$now/ and /out =/) {
($foo,$foo,$foo,$time,$foo,$foo,$foo,$taskinfo,$foo,$foo,$foo,
$foo,$targets,$foo,$foo,$foo, $bytes) = split ' ';

If you need a placeholder for a dummy value it is customary to use undef.
Beside, you can index the result from split like a array. I suggest you read
up on "array slice", too. Oh, and while you are at it check out the
documentation for split(), too. It defaults to split on whitespace if the
pattern is missing.
So you want something like
($taskinfo) = (split)[7];
should be like array[$taskinfo] += $targets;

$taskinfo is a string, isn't it? The numerical value of a string is (unless
it starts with a number) always 0. In other words you are overwriting
array[0] over and over again.
Did you mean to use a hash instead?
How could I define the array or hash dynamicly?

You don't. Perl arrays and hashes are always dynamic.

jue
 
P

Paul Lalli

On Mar 1, 8:15 am, "(e-mail address removed)"
Do we have hash over hash? What should we implement this?

I can't understand the vast majority of your post - that's why I told
you to post a short-but-complete script, which you ignored - so I'll
just answer this question: Yes, hashes of hashes are valid. Please
read:
perldoc perlreftut
perldoc perllol
perldoc perldsc

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top