[31435] in Perl-Users-Digest
Perl-Users Digest, Issue: 2687 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 22 06:09:38 2009
Date: Sun, 22 Nov 2009 03:09:05 -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 Sun, 22 Nov 2009 Volume: 11 Number: 2687
Today's topics:
Re: Help with HoH and accessing right keys <cyrusgreats@gmail.com>
Re: Help with HoH and accessing right keys <martien.verbruggen@invalid.see.sig>
Re: Help with HoH and accessing right keys <martien.verbruggen@invalid.see.sig>
Re: Help with HoH and accessing right keys <martien.verbruggen@invalid.see.sig>
Re: Help with HoH and accessing right keys <ben@morrow.me.uk>
Re: Help with HoH and accessing right keys <cyrusgreats@gmail.com>
Re: Help with HoH and accessing right keys <ben@morrow.me.uk>
Re: Help with HoH and accessing right keys <cyrusgreats@gmail.com>
Re: Help with HoH and accessing right keys <tadmc@seesig.invalid>
Re: Help with HoH and accessing right keys <ben@morrow.me.uk>
Re: help with regex <martien.verbruggen@invalid.see.sig>
Re: help with regex <cyrusgreats@gmail.com>
Re: help with regex <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 21 Nov 2009 13:26:11 -0800 (PST)
From: Obama <cyrusgreats@gmail.com>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <d9326560-4d33-40f6-bb40-f2e2593c5fa0@b36g2000prf.googlegroups.com>
On Nov 21, 12:55=A0pm, Obama <cyrusgre...@gmail.com> wrote:
> As a point of style, repeating essentially the same deref expression
>
> > over and over is terribly messy. Assign it to a temporary:
>
> > =A0 =A0 my $start =3D $servers{$server}{Start};
> > =A0 =A0 my $end =A0 =3D $servers{$server}{End};
>
> > =A0 =A0 print <<OUT;
> > =A0 =A0 Server: $server
> > =A0 =A0 =A0 =A0 Start Date: $start->{date}
> > =A0 =A0 =A0 =A0 ...
> > =A0 =A0 OUT
>
> > Ben
>
> Thank you so much Ben, I got it to work god bless you
The hash table seems it overwrites if one server has more than one
'Start|End', I got more than 300 records, when I run the program it
record the last 23, any idea?
------------------------------
Date: Sun, 22 Nov 2009 08:18:36 +1100
From: Martien Verbruggen <martien.verbruggen@invalid.see.sig>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <cfl9eh.lo6.ln@news.heliotrope.home>
On Sat, 21 Nov 2009 08:24:00 -0800 (PST),
Obama <cyrusgreats@gmail.com> wrote:
> I post before but I was not doing it the right way, here is the
> complete code that I need your help, please do let me know if you do
> have any other question. Thanks
Please stop machine-gun posting. And please do not start new threads
when a perfectly fine one is already available to you.
Wait for some of the replies to come back before adding more and more
posts that add or change information.
Anyone who wants the full history on this now has to try to find three
unrelated threads, and read a large number of posts just to get the
picture.
if you have not already done so, please read
http://www.rehabitation.com/clpmisc.shtml
and
http://www.catb.org/~esr/faqs/smart-questions.html
if you don't want to run out of credit before you start.
Martien
--
|
Martien Verbruggen | prepBut nI vrbLike adjHungarian! qWhat's
first.last@heliotrope.com.au | artThe adjBig nProblem? -- Alec Flett
|
------------------------------
Date: Sun, 22 Nov 2009 08:38:59 +1100
From: Martien Verbruggen <martien.verbruggen@invalid.see.sig>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <jlm9eh.lo6.ln@news.heliotrope.home>
On Sat, 21 Nov 2009 13:26:11 -0800 (PST),
Obama <cyrusgreats@gmail.com> wrote:
> On Nov 21, 12:55Â pm, Obama <cyrusgre...@gmail.com> wrote:
>> As a point of style, repeating essentially the same deref expression
>>
>> > over and over is terribly messy. Assign it to a temporary:
>>
>> > Â Â my $start = $servers{$server}{Start};
>> >   my $end  = $servers{$server}{End};
>>
>> > Â Â print <<OUT;
>> > Â Â Server: $server
>> > Â Â Â Â Start Date: $start->{date}
>> > Â Â Â Â ...
>> > Â Â OUT
>>
>> > Ben
>>
>> Thank you so much Ben, I got it to work god bless you
>
> The hash table seems it overwrites if one server has more than one
> 'Start|End', I got more than 300 records, when I run the program it
> record the last 23, any idea?
Yes. At the level where you now have the hash ref with Start and End
keys, put an array ref. When you see a start tag, create a new array
element and put a hash ref in it which has keys Start and End, just as
the one single one you have now. When you see an End tag, add that to
the last element of that array (beware of possible dangling end lines).
Let us know if you have troubles implementing that, by showing us what
you did, and how it's failing.
More changing requirements. You are what Eric Raymond calls a time-sink.
Martien
--
|
Martien Verbruggen | Computers in the future may weigh no
first.last@heliotrope.com.au | more than 1.5 tons. -- Popular
| Mechanics, 1949
------------------------------
Date: Sun, 22 Nov 2009 08:50:04 +1100
From: Martien Verbruggen <martien.verbruggen@invalid.see.sig>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <can9eh.lo6.ln@news.heliotrope.home>
On Sun, 22 Nov 2009 08:38:59 +1100,
Martien Verbruggen <martien.verbruggen@invalid.see.sig> wrote:
> Yes. At the level where you now have the hash ref with Start and End
> keys, put an array ref. When you see a start tag, create a new array
> element and put a hash ref in it which has keys Start and End, just as
> the one single one you have now. When you see an End tag, add that to
> the last element of that array (beware of possible dangling end lines).
BTW. This assumes that start-end pairs for the same 'server' cannot
overlap in any way. If they do, and there is no other information that
can be used to match start and end tag, there is no solution.
Martien
--
| Yes; Windows is great for running &
Martien Verbruggen | developing viruses, for instance. It's
first.last@heliotrope.com.au | also very popular, but then again, so is
| the common cold. -- Dave Hinz
------------------------------
Date: Sat, 21 Nov 2009 22:47:57 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <t97mt6-ii21.ln1@osiris.mauzo.dyndns.org>
Quoth Martien Verbruggen <martien.verbruggen@invalid.see.sig>:
> On Sat, 21 Nov 2009 13:26:11 -0800 (PST),
> Obama <cyrusgreats@gmail.com> wrote:
> > On Nov 21, 12:55Â pm, Obama <cyrusgre...@gmail.com> wrote:
> >> As a point of style, repeating essentially the same deref expression
> >>
> >> > over and over is terribly messy. Assign it to a temporary:
> >>
> >> > Â Â my $start = $servers{$server}{Start};
> >> >   my $end  = $servers{$server}{End};
> >>
> >> > Â Â print <<OUT;
> >> > Â Â Server: $server
> >> > Â Â Â Â Start Date: $start->{date}
> >> > Â Â Â Â ...
> >> > Â Â OUT
> >>
> >> Thank you so much Ben, I got it to work god bless you
> >
> > The hash table seems it overwrites if one server has more than one
> > 'Start|End', I got more than 300 records, when I run the program it
> > record the last 23, any idea?
>
> Yes. At the level where you now have the hash ref with Start and End
> keys, put an array ref. When you see a start tag, create a new array
> element and put a hash ref in it which has keys Start and End, just as
> the one single one you have now. When you see an End tag, add that to
> the last element of that array (beware of possible dangling end lines).
An alternative would be to move the printing logic into the 'End' block,
so that you never need to remember more than one 'Start' line per
server.
Ben
------------------------------
Date: Sat, 21 Nov 2009 14:59:23 -0800 (PST)
From: Obama <cyrusgreats@gmail.com>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <a0747b5c-65fd-43a0-b303-03a73db76ae9@g22g2000prf.googlegroups.com>
On Nov 21, 2:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Martien Verbruggen <martien.verbrug...@invalid.see.sig>:
>
>
>
> > On Sat, 21 Nov 2009 13:26:11 -0800 (PST),
> > =A0 =A0Obama <cyrusgre...@gmail.com> wrote:
> > > On Nov 21, 12:55=A0pm, Obama <cyrusgre...@gmail.com> wrote:
> > >> As a point of style, repeating essentially the same deref expression
>
> > >> > over and over is terribly messy. Assign it to a temporary:
>
> > >> > =A0 =A0 my $start =3D $servers{$server}{Start};
> > >> > =A0 =A0 my $end =A0 =3D $servers{$server}{End};
>
> > >> > =A0 =A0 print <<OUT;
> > >> > =A0 =A0 Server: $server
> > >> > =A0 =A0 =A0 =A0 Start Date: $start->{date}
> > >> > =A0 =A0 =A0 =A0 ...
> > >> > =A0 =A0 OUT
>
> > >> Thank you so much Ben, I got it to work god bless you
>
> > > The hash table seems it overwrites if one server has more than one
> > > 'Start|End', I got more than 300 records, when I run the program it
> > > record the last 23, any idea?
>
> > Yes. At the level where you now have the hash ref with Start and End
> > keys, put an array ref. When you see a start tag, create a new array
> > element and put a hash ref in it which has keys Start and End, just as
> > the one single one you have now. When you see an End tag, add that to
> > the last element of that array (beware of possible dangling end lines).
> ,
> An alternative would be to move the printing logic into the 'End' block,
> so that you never need to remember more than one 'Start' line per
> server.
>
> Ben
I'm sorry I'm totally lost again here, will you please tell me how to
that please, please, I've not slept over this since yesterday, I'm not
good at this Hash-of-has, please.
------------------------------
Date: Sat, 21 Nov 2009 23:49:03 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <fsamt6-9q21.ln1@osiris.mauzo.dyndns.org>
Quoth Obama <cyrusgreats@gmail.com>:
> On Nov 21, 2:47 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth Martien Verbruggen <martien.verbrug...@invalid.see.sig>:
> >
> > > Yes. At the level where you now have the hash ref with Start and End
> > > keys, put an array ref. When you see a start tag, create a new array
> > > element and put a hash ref in it which has keys Start and End, just as
> > > the one single one you have now. When you see an End tag, add that to
> > > the last element of that array (beware of possible dangling end lines).
> > ,
> > An alternative would be to move the printing logic into the 'End' block,
> > so that you never need to remember more than one 'Start' line per
> > server.
>
> I'm sorry I'm totally lost again here, will you please tell me how to
> that please, please, I've not slept over this since yesterday, I'm not
> good at this Hash-of-has, please.
Pleading will not make anyone more inclined to help you. The basic logic
you need looks like
for each line
if it's a 'Start' line
store all the captured information under the appropriate
server name.
if it's an 'End' line
check you have a 'Start' line recorded for this server.
print the data.
delete the 'Start' entry now that you've finished with it.
Now you write the code. You have all the pieces you need already.
Ben
------------------------------
Date: Sat, 21 Nov 2009 17:01:49 -0800 (PST)
From: Obama <cyrusgreats@gmail.com>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <e755bb9f-3f27-4a0e-98e9-81a88f0baf93@g10g2000pri.googlegroups.com>
On Nov 21, 3:49=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Obama <cyrusgre...@gmail.com>:
>
>
>
> > On Nov 21, 2:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth Martien Verbruggen <martien.verbrug...@invalid.see.sig>:
>
> > > > Yes. At the level where you now have the hash ref with Start and En=
d
> > > > keys, put an array ref. When you see a start tag, create a new arra=
y
> > > > element and put a hash ref in it which has keys Start and End, just=
as
> > > > the one single one you have now. When you see an End tag, add that =
to
> > > > the last element of that array (beware of possible dangling end lin=
es).
> > > ,
> > > An alternative would be to move the printing logic into the 'End' blo=
ck,
> > > so that you never need to remember more than one 'Start' line per
> > > server.
>
> > I'm sorry I'm totally lost again here, will you please tell me how to
> > that please, please, I've not slept over this since yesterday, I'm not
> > good at this Hash-of-has, please.
>
> Pleading will not make anyone more inclined to help you. The basic logic
> you need looks like
>
> =A0 =A0 for each line
> =A0 =A0 =A0 =A0 if it's a 'Start' line
> =A0 =A0 =A0 =A0 =A0 =A0 store all the captured information under the appr=
opriate
> =A0 =A0 =A0 =A0 =A0 =A0 server name.
> =A0 =A0 =A0 =A0 if it's an 'End' line
> =A0 =A0 =A0 =A0 =A0 =A0 check you have a 'Start' line recorded for this s=
erver.
> =A0 =A0 =A0 =A0 =A0 =A0 print the data.
> =A0 =A0 =A0 =A0 =A0 =A0 delete the 'Start' entry now that you've finished=
with it.
>
> Now you write the code. You have all the pieces you need already.
>
> Ben
I have this one and it does not work..
if ($action eq "Start") {
$servers{$name}{start_server} =3D {
date =3D> $date,
time =3D> $time,
};
if ($action eq "End") {
if (exists $servers{$name}{start_server}) {
$servers{$name}{$action} =3D {
date =3D> $date,
time =3D> $time,
size =3D> $size,
};
my $start=3D $servers{$name}{Start};
my $end=3D $servers{$name}{End};
print "Server: $servers{$name}\n";
print "Start date: $start->{date}\n";
print "Start time: $start->{time}\n";
print "End date: $end->{date}\n";
print "End time: $end->{time}\n";
print "End size: $end->{size}\n";
delete $servers{$name}{start_server};
}
}
}
}
------------------------------
Date: Sat, 21 Nov 2009 19:42:56 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <slrnhgh5je.5aa.tadmc@tadbox.sbcglobal.net>
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth Obama <cyrusgreats@gmail.com>:
>> I'm sorry I'm totally lost again here, will you please tell me how to
>> that please, please,
> Pleading will not make anyone more inclined to help you.
And the Posting Guidelines warn against pleading too.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 22 Nov 2009 01:33:05 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with HoH and accessing right keys
Message-Id: <hvgmt6-ca31.ln1@osiris.mauzo.dyndns.org>
Quoth Obama <cyrusgreats@gmail.com>:
> On Nov 21, 3:49 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > for each line
> > if it's a 'Start' line
> > store all the captured information under the appropriate
> > server name.
> > if it's an 'End' line
> > check you have a 'Start' line recorded for this server.
> > print the data.
> > delete the 'Start' entry now that you've finished with it.
> >
> > Now you write the code. You have all the pieces you need already.
>
> I have this one and it does not work..
Fix your indentation.
<snip>
> $servers{$name}{start_server} = {
<snip>
> if (exists $servers{$name}{start_server}) {
<snip>
> my $start= $servers{$name}{Start};
<snip>
One of these is not the same as the other two, not to mention that the
second level of hash is redundant at this point.
> print "Server: $servers{$name}\n";
> print "Start date: $start->{date}\n";
> print "Start time: $start->{time}\n";
> print "End date: $end->{date}\n";
> print "End time: $end->{time}\n";
> print "End size: $end->{size}\n";
Learn how to use heredocs.
Ben
------------------------------
Date: Sun, 22 Nov 2009 08:13:38 +1100
From: Martien Verbruggen <martien.verbruggen@invalid.see.sig>
Subject: Re: help with regex
Message-Id: <26l9eh.lo6.ln@news.heliotrope.home>
On Sat, 21 Nov 2009 12:34:04 -0800,
John W. Krahn <someone@example.com> wrote:
> Jürgen Exner wrote:
>
>> No, not necessarily. Using barewords as keys for hashes is perfectly
>> fine as long as they don't contain whitespace.
>
> as long as they don't contain any \W characters.
\begin{pedantry}[level='slight']
It wouldn't, by definition. A 'bareword' is a 'word' (see perldata), and
a word consists entirely of \w characters, as that is how \w is defined.
\end{pedantry}
Martien
--
|
Martien Verbruggen | There are only 10 types of people in the
first.last@heliotrope.com.au | world; those who understand binary and
| those who don't.
------------------------------
Date: Sat, 21 Nov 2009 13:42:48 -0800 (PST)
From: Obama <cyrusgreats@gmail.com>
Subject: Re: help with regex
Message-Id: <7ae18a4b-6b98-4ea8-a749-db71ea938eba@u16g2000pru.googlegroups.com>
On Nov 21, 1:07=A0pm, Martien Verbruggen
<martien.verbrug...@invalid.see.sig> wrote:
> On Sat, 21 Nov 2009 08:19:05 -0800 (PST),
> If you have any questions, don't hesistate to ask.
> Martien
Martien,
thanks for your help, I do have a log file which contains more than
3000 records, after running the program it records only 23, the reason
I guess that code overwrites if one server has more than one 'Start|
End'. One server could 'Start' say at Nov 15 00:03:45 and 'End' Nov 15
00:3:55 and have another session later on the log, say at Nov 18
00:08:41 and 'End' Nov 18 00:08:59. The last one overwrite the earlier
ones! Again thanks for your help if you can help me out on this!
------------------------------
Date: Sat, 21 Nov 2009 20:32:26 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: help with regex
Message-Id: <B93Om.36502$6c2.2799@newsfe03.iad>
Martien Verbruggen wrote:
> On Sat, 21 Nov 2009 12:34:04 -0800,
> John W. Krahn <someone@example.com> wrote:
>> Jürgen Exner wrote:
>>
>>> No, not necessarily. Using barewords as keys for hashes is perfectly
>>> fine as long as they don't contain whitespace.
>> as long as they don't contain any \W characters.
>
> \begin{pedantry}[level='slight']
>
> It wouldn't, by definition. A 'bareword' is a 'word' (see perldata), and
> a word consists entirely of \w characters, as that is how \w is defined.
>
> \end{pedantry}
Yes, and a 'bareword' with whitespace isn't really a 'bareword' either.
Perhaps you meant to direct this to Jürgen instead of me?
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2687
***************************************