[28828] in Perl-Users-Digest
Perl-Users Digest, Issue: 72 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 24 21:54:21 2007
Date: Wed, 24 Jan 2007 18:53:47 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 24 Jan 2007 Volume: 11 Number: 72
Today's topics:
Re: Statistics Extraction <doni.sekar@gmail.com>
Re: Statistics Extraction <DJStunks@gmail.com>
Re: Statistics Extraction <purlgurl@purlgurl.net>
Re: Statistics Extraction <purlgurl@purlgurl.net>
Re: Statistics Extraction <john@castleamber.com>
Re: Statistics Extraction <josef.moellers@fujitsu-siemens.com>
Re: Statistics Extraction <DJStunks@gmail.com>
Re: Statistics Extraction <josef.moellers@fujitsu-siemens.com>
Re: Statistics Extraction <doni.sekar@gmail.com>
Re: Statistics Extraction <glex_no-spam@qwest-spam-no.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Jan 2007 15:10:43 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169593843.048823.142330@a34g2000cwb.googlegroups.com>
On Jan 23, 2:22 pm, "DJ Stunks" <DJStu...@gmail.com> wrote:
#!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my (%statistics, $type);
> while ( my $line = <DATA> ) {
> if ( $line =~ m{^ (\S+) }x ) {
> $type = $1;
> }
> elsif ( $line =~ m{ (\d+) \s+ (.+?) \s* $}mx ) {
> $statistics{ $type }{ $2 } = $1;
> }
> }
>
> print "MAC stats for 'frames with invalid header': ",
> $statistics{ MAC }{ 'frames with invalid header' },
> "\n";
>
I tried the above method but I didnt get any result for "frames with
invalid header"..
Sekar
------------------------------
Date: 23 Jan 2007 15:23:09 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169594589.924062.193650@a75g2000cwd.googlegroups.com>
On Jan 23, 4:10 pm, "doni" <doni.se...@gmail.com> wrote:
> On Jan 23, 2:22 pm, "DJ Stunks" <DJStu...@gmail.com> wrote:
> #!/usr/bin/perl
>
> > use strict;
> > use warnings;
>
> > my (%statistics, $type);
> > while ( my $line = <DATA> ) {
> > if ( $line =~ m{^ (\S+) }x ) {
> > $type = $1;
> > }
> > elsif ( $line =~ m{ (\d+) \s+ (.+?) \s* $}mx ) {
> > $statistics{ $type }{ $2 } = $1;
> > }
> > }
>
> > print "MAC stats for 'frames with invalid header': ",
> > $statistics{ MAC }{ 'frames with invalid header' },
> > "\n";
>
> I tried the above method but I didnt get any result for "frames with
> invalid header"..
I only post working code. You need to get rid of any indentation in
the DATA section for the regexs to work.
-jp
------------------------------
Date: Tue, 23 Jan 2007 16:21:19 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Statistics Extraction
Message-Id: <45B6A67F.4000604@purlgurl.net>
doni wrote:
(snipped)
> I wanted to extract specific information of MAC and PHY statistics from
> the statistics log file.
> MAC statistics:
> 0 frames with invalid header
> 546 confirmed frames sent succesfully
#!perl
&Query;
sub Query
{
my ($yes_no);
print "Statistics To Search: MAC PHY Network?\n";
$search = <STDIN>;
chomp $search;
print "Search $search correct? Yes No?\n";
$yes_no = <STDIN>;
if (!($yes_no =~ /yes/i))
{ &Query; }
elsif (!($search =~ /mac|phy|network/i))
{ print "Incorrect Statistics To Search\n"; &Query; }
else
{
print "Enter Search Terms: ";
$search_terms = <STDIN>;
if (!($search_terms))
{ &Query; }
else
{ chomp ($search_terms); &Search; }
}
}
sub Search
{
$search_terms =~ tr/A-Z/a-z/;
if ($search =~ /mac/i)
{
print "\n";
while (<DATA>)
{
if (index ($_, "PHY") > -1)
{ print "\nFinished Searching MAC"; last; }
if (index ($_, $search_terms) > -1)
{ print $_; }
}
}
elsif ($search =~ /phy/i)
{
my ($phy);
print "\n";
while (<DATA>)
{
if (index ($_, "Network") > -1)
{ print "\nFinished Searching PHY"; last; }
if (index ($_, "PHY") > -1)
{ $phy = "true"; }
if ($phy eq "true")
{
if (index ($_, $search_terms) > -1)
{ print $_; }
}
}
}
else
{
my ($network);
print "\n";
while (<DATA>)
{
if (index ($_, "Network") > -1)
{ $network = "true"; }
if ($network eq "true")
{
if (index ($_, $search_terms) > -1)
{ print $_; }
}
}
print "\nFinished Searching Network";
}
}
__DATA__
MAC statistics:
0 frames with invalid header
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
542 confirmed frames received
4597 total frames received
851 data packets received
549 packets sent successfully
152 packets sent unsuccessfully
763 packets queued by network layer
61 packet transmissions timed out
0 packets with invalid length
0 out of order fragments received
87 duplicate fragments received
0 partial packets received
4 packet reassemblies timed out
0 no buffers
PHY statistics:
3404 frames transmitted
105 transmits aborted due to rx
0 transmit errors
0 late transmits
11 tx buffer loads interrupted
0 tx buffer load failures
4598 receive interrupts
4598 frames received
0 received frames lost
0 zero length frames received
0 receive cmd errors
Network statistics:
851 total packets received
0 bad packet length
0 bad version number
0 outgoing packets with no route
0 input packets with bad destination address
0 input packets from wrong channel
0 packets dropped for exceeding TTL
0 packets dropped due to full socket buffers
0 packets dropped due to no receiver
0 packets dropped due to running out of memory
762 total packets sent
549 packets succesfully transmitted
213 packets sent unsuccessfully
--
Purl Gurl
------------------------------
Date: Tue, 23 Jan 2007 16:34:08 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Statistics Extraction
Message-Id: <45B6A980.4080307@purlgurl.net>
Purl Gurl wrote:
> doni wrote:
(snipped)
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
549 packets succesfully transmitted
Incidentally, misspelled words in your data suggests
your article and data are fabricated. I hope this
is not the case. I become very annoyed by trolls.
You do not want me, personally, to become annoyed.
Purl Gurl
------------------------------
Date: 24 Jan 2007 00:50:20 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Statistics Extraction
Message-Id: <Xns98C1BFA357943castleamber@130.133.1.4>
Purl Gurl <purlgurl@purlgurl.net> wrote:
*cries*
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Wed, 24 Jan 2007 11:10:08 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Statistics Extraction
Message-Id: <ep7bes$b8u$1@nntp.fujitsu-siemens.com>
doni wrote:
> Michele Dondi wrote:
>=20
>=20
>>What have you tried thus far? In any case you may try some regexen
>>like
>>
>> /(\d+)\s+frames with invalid header/
>>
>=20
>=20
> I was trying to do something other than regexp so that If I need
> multiple searches, I can easily incorporate them.
Waht you could try is to build a HoH from your input data and then=20
satisfy your query from the HoH:
<untested>
my %netstat; # Will be the HOH
my $stats; # some kind of state variable
while (<$netstat>) {
chomp;
if (/^(\S+)\s+statistics:/) {
$stats =3D $_;
$netstat{$stats} =3D { };
} elif (/^\s+(\d+)\s+(\S.*)/) {
next unless defined $stats;
$netstat{=A7stats}->{$2} =3D $1;
}
}
</untested>
Then you'd find PHY's "tx buffer loads interrupted" in
$netstat{PHY}->{"tx buffer loads interrupted"}.
Still involves regexen, though.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 24 Jan 2007 06:46:43 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169650003.711457.248950@m58g2000cwm.googlegroups.com>
On Jan 24, 3:10 am, Josef Moellers <josef.moell...@fujitsu-siemens.com>
wrote:
> doni wrote:
> > Michele Dondi wrote:
>
> >>What have you tried thus far? In any case you may try some regexen
> >>like
>
> >> /(\d+)\s+frames with invalid header/
>
> > I was trying to do something other than regexp so that If I need
> > multiple searches, I can easily incorporate them.Waht you could try is =
to build a HoH from your input data and then
> satisfy your query from the HoH:
For some reason I really, really like this approach to this problem!
Sheer genius, IMO :P
> <untested>
> my %netstat; # Will be the HOH
> my $stats; # some kind of state variable
> while (<$netstat>) {
> chomp;
> if (/^(\S+)\s+statistics:/) {
> $stats =3D $_;
ITYM
$stats =3D $1;
> $netstat{$stats} =3D { };
no need for this step; let autoviv take care of it for you.
> } elif (/^\s+(\d+)\s+(\S.*)/) {
> next unless defined $stats;
not a bad idea, I didn't have this test in my version of this script.
> $netstat{=A7stats}->{$2} =3D $1;
a new Perl6 sigil? just kidding. no need for the arrow for the
embedded hash. Perl knows what you mean
$netstat{ $stats }{ $2 } =3D $1
> }}</untested>
>
> Then you'd find PHY's "tx buffer loads interrupted" in
> $netstat{PHY}->{"tx buffer loads interrupted"}.
same as before, no arrow required. see perldoc perlref.
-jp
------------------------------
Date: Wed, 24 Jan 2007 16:21:23 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Statistics Extraction
Message-Id: <ep7tpr$ssq$1@nntp.fujitsu-siemens.com>
DJ Stunks wrote:
> On Jan 24, 3:10 am, Josef Moellers <josef.moell...@fujitsu-siemens.com>=
> wrote:
>=20
>>doni wrote:
>>
>>>Michele Dondi wrote:
>>
>>>>What have you tried thus far? In any case you may try some regexen
>>>>like
>>
>>>> /(\d+)\s+frames with invalid header/
>>
>>>I was trying to do something other than regexp so that If I need
>>>multiple searches, I can easily incorporate them.Waht you could try is=
to build a HoH from your input data and then
>>
>>satisfy your query from the HoH:
>=20
>=20
> For some reason I really, really like this approach to this problem!
> Sheer genius, IMO :P
Thank you, I feel honoured.
>><untested>
>>my %netstat; # Will be the HOH
>>my $stats; # some kind of state variable
>>while (<$netstat>) {
>> chomp;
>> if (/^(\S+)\s+statistics:/) {
>> $stats =3D $_;
>=20
>=20
> ITYM
>=20
> $stats =3D $1;
Yes, of course.
>> $netstat{$stats} =3D { };
>=20
>=20
> no need for this step; let autoviv take care of it for you.
>=20
>=20
>> } elif (/^\s+(\d+)\s+(\S.*)/) {
>> next unless defined $stats;
>=20
>=20
> not a bad idea, I didn't have this test in my version of this script.
Most likely, it will never be used, but ... better safe than sorry.
>> $netstat{=A7stats}->{$2} =3D $1;
>=20
>=20
> a new Perl6 sigil? just kidding.
No, it's just to show that it's coded according to the law of least=20
surprise ;-)
no need for the arrow for the
> embedded hash. Perl knows what you mean
>=20
> $netstat{ $stats }{ $2 } =3D $1
>=20
>=20
>> }}</untested>
>>
>>Then you'd find PHY's "tx buffer loads interrupted" in
>>$netstat{PHY}->{"tx buffer loads interrupted"}.
>=20
>=20
> same as before, no arrow required. see perldoc perlref.
Learnt something new today,
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 24 Jan 2007 10:50:06 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169664606.872723.241100@h3g2000cwc.googlegroups.com>
On Jan 24, 7:21 am, Josef Moellers
<josef.moell...@fujitsu-siemens.com> wrote:
> >> } elif (/^\s+(\d+)\s+(\S.*)/) {
> >> next unless defined $stats;
thanks, for your reply....
Can I understand why we do "next unless defined $stats;" and why it
will never be used.
> > embedded hash. Perl knows what you mean
>
> > $netstat{ $stats }{ $2 } = $1
>
> >> }}</untested>
>
Can you let me know how can I find out the values in the HoH.
Thanks,
doni
------------------------------
Date: Wed, 24 Jan 2007 13:03:39 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Statistics Extraction
Message-Id: <45b7ad0d$0$709$815e3792@news.qwest.net>
doni wrote:
> On Jan 24, 7:21 am, Josef Moellers
> <josef.moell...@fujitsu-siemens.com> wrote:
[...]
>>> embedded hash. Perl knows what you mean
>>> $netstat{ $stats }{ $2 } = $1
>>>> }}</untested>
>
> Can you let me know how can I find out the values in the HoH.
By using the hash's keys, of course.
Do some research and try to find the answer. There is a very
good document on many useful data structures that comes with
perl.
perldoc perldsc
Look for "HASH OF HASH".
You can also "use Data::Dumper", to see the structure and values.
perldoc Data::Dumper
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 72
*************************************