[18280] in Perl-Users-Digest
Perl-Users Digest, Issue: 448 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 8 21:05:33 2001
Date: Thu, 8 Mar 2001 18:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984103508-v10-i448@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 8 Mar 2001 Volume: 10 Number: 448
Today's topics:
Re: (Linux beginner) How to de-install and re-install P (Martien Verbruggen)
Re: [newbie] How to take parameters into the script? <fayolle@enseirb.fr>
Re: Arrghh..can anyone help? :( <mischief@velma.motion.net>
Re: Can it be done? <rod@roddy.demon.co.uk>
Re: creating dos exectable from perl script <fayolle@enseirb.fr>
Re: FAQ 6.0: Why do I get weird spaces when I print a <uri@sysarch.com>
Re: grep question <wyzelli@yahoo.com>
Re: Help to Install Perl (Damian James)
Re: How do I fetch clipboard content? (Abigail)
Newbies welcome <darrenls21@yahoo.com>
Re: number of characters (length) <wyzelli@yahoo.com>
Re: Perl & Recursion : Why doesn't this work? <durrett@xilinx.com>
Re: Perl & Recursion : Why doesn't this work? <joe+usenet@sunstarsys.com>
Re: Perl & Recursion : Why doesn't this work? <joe+usenet@sunstarsys.com>
Pine compatible Perl mailbox module? <kisrael@andante.eecs.tufts.edu>
Re: Quick script question - I'm lost (Abigail)
Re: Quick script question - I'm lost (Damian James)
Re: Quick script question - I'm lost (Tad McClellan)
Skilled discussion: Multiple inheritance (MI) of attrib <murat.uenalan@gmx.de>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 09 Mar 2001 01:21:25 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: (Linux beginner) How to de-install and re-install Perl on Linux
Message-Id: <slrn9agc0m.nts.mgjv@verbruggen.comdyn.com.au>
On 08 Mar 2001 00:25:28 -0300,
Jorge Godoy <godoy@conectiva.com> wrote:
> On Wed, 7 Mar 2001, mgjv@tradingpost.com.au wrote:
>> Garry Heaton <garry@heaton6.freeserve.co.uk> wrote:
>>> I'm new to Linux/Unix and want to remove the default Perl
>>> installation, then re-install from source code because I read
>>> somewhere that the Perl libraries on some Linux distributions are
>>> incomplete. How do I remove and re-install?
>>
>> It's better to leave the original installed, otherwise all other
>> packages managed by rpm will start whinging that you don't have perl
>> installed (and that includes bind, for crying out loud!).
>
> bind??? It seems like a packaging bug to me:
Maybe.
> [godoy@wintermute godoy]$ rpm -q --requires bind
> chkconfig
> /bin/sh
> ld-linux.so.2
> libc.so.6
> libc.so.6(GLIBC_2.0)
> libc.so.6(GLIBC_2.1)
> [godoy@wintermute godoy]$ rpm -q bind
> bind-8.2.3-4cl
> [godoy@wintermute godoy]$
Try this on Redhat 7 with bind-8.2.3-1
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Fri, 9 Mar 2001 01:56:01 +0100
From: "Pierre-Alain Fayolle" <fayolle@enseirb.fr>
Subject: Re: [newbie] How to take parameters into the script?
Message-Id: <9899nm$ebb$1@news.u-bordeaux.fr>
You can use sthg like this :
$t = @ARGV; #size of the tab
if ($t == 2) { #your code; exit; }
if ($t == 1) { #your code; exit;}
printf "usage m2s p1 p2\n";
if you want to use the name of your parameters you can use $ARGV[0] to get
p1 and $ARGV[1] to get p2
> say I have a script that will translate a morse code into an acsii code.
> This script called "m2s" and i want this m2s to take 2 parameter at the
> command when the script is activated. where parameter 1 is a file in
mosrse
> code, parameter 2 is the name of the file that the translated code is
> stored. It looks like:
> % m2s parameter1 parameter2
>
> in case of both parameters are missing, the script will output a usage
info.
> If only one parameters, the script will assume its the file to read and
> output the result (translated ascii code) to the screen.
>
------------------------------
Date: Fri, 09 Mar 2001 00:05:02 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Arrghh..can anyone help? :(
Message-Id: <tag7hegrrepnc9@corp.supernews.com>
mych@earthlink.net wrote:
> Hi there,
> I'm having a problem with a NT server running a PERL script. Here's my
> problem:
I haven't seen the other regulars do this yet, so I will...
It's `Perl' or `perl'. `Perl' refers to the language, while `perl'
refers to the interpreter or its implementation. The acronyms are
backronyms and folk legend.
Now that that's out of the way... (some have a pet peeve about that ;-)
> The problem is that when you set a cookie on NT with PERL, it will
> only work if you don't redirect to another place right after. If you
> redirect it refuses to set the cookie.
> It works fine on UNIX, but not NT.
This shouldn't depend on the server. If anything, it should depend on
the client (browser).
What happens if, perhaps, you set the cookie in the new location's
header? Do you not control the target page?
Or perhaps you could put a hidden form value in your page which is
doing the redirection, and check for it in your script. That way,
you refresh back to the same page the first time without the value
set. The second time, the value is set, so you redirect to the other
page without even trying to set the cookie in this pass.
> I was able to do was narrow it down to the problem which is these two
> lines of code:
> print "Set-cookie: $newcookie\n";
> print "Location: $websiteurl\n\n";
> The first line will only work if you don't include that second line.
> So, if I get rid of the second line, then the cookie sets like it
> should. But if you keep the second line in there, then the cookie
> refuses to set. I need both lines in there, and again, it work great
> with UNIX, but not NT.
If you did this in two passes, by setting a hidden form value in
pass one along with setting the cookie, refreshing, and checking for
that value in pass two then setting the redirect when it's found,
as mentioned above, you only have to send one at a time, and your
user still doesn't have to click to follow the redirect. I haven't
tested this yet, but I'd be willing if someone posted here and caught
my eye or emailed me about it.
> If anyone has used PERL script on NT, or can help me with this
> problem, i would appreciate it.
I've used ActiveState, but I haven't had the need to do what
you're trying to get Perl to do on NT. WIsh I could be more of
a help. I hope my suggestions above make sense and work or, if
nothing else, get someone thinking about a solution that works.
Chris
--
Christopher E. Stith
Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.
------------------------------
Date: Fri, 09 Mar 2001 00:01:54 +0000
From: roddy <rod@roddy.demon.co.uk>
Subject: Re: Can it be done?
Message-Id: <3AA81D69.7CE49867@roddy.demon.co.uk>
Hi
You might like to take a look at a perl prog called W3mir - I haven't used
it fully but it seems pretty well developed and I think will do what you
need.
Go to http://langfeldt.net/w3mir/
hope this helps
Roddy
Villy Kruse wrote:
> On Thu, 08 Mar 2001 12:14:58 GMT, Tomas <tomas@place1.com> wrote:
> >Hi Guys,
> >
> >Is there any pre written scripts or applications out there who can
> >handle the following tasks. (The same way as wget can handle it, except
> >that wget not seems to be able to handle https:// request).
> >
> >1. Remotely login to a secure web site https://www.domain.com/ using
> >assigned user name and password.
> >
> >2. Switch to different specified pages and download the complete HTML
> >page.
> >
> >Any help would be very appreciated.
> >
>
> Use the SSLeay perl module. It is either Crypt::SSLeay or Net::SSLeay
> that works together with LWP to provide access to https:// pages.
>
> Might want to get both from CPAN and install them. The openssl package
> from www.openssl.org is also required.
>
> Villy
------------------------------
Date: Fri, 9 Mar 2001 02:00:19 +0100
From: "Pierre-Alain Fayolle" <fayolle@enseirb.fr>
Subject: Re: creating dos exectable from perl script
Message-Id: <9899vo$ecs$1@news.u-bordeaux.fr>
> Try perl2exe, which will compile Your .pl files into .exe allowing U
> to run them without as stand alone apps;
> Also PerlDev Kit from ActiveState.com has PerlApp utility that will do
> the same, second being my choice.
>
One of my friends had difficulties to generate bytecode from perl script.
Have you used it? Do they run fine?
Are they efficient?
------------------------------
Date: Thu, 08 Mar 2001 23:05:59 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ 6.0: Why do I get weird spaces when I print an array of lines?
Message-Id: <x7snkndfoo.fsf@home.sysarch.com>
>>>>> "MC" == Michael Carman <mjcarman@home.com> writes:
MC> The regular FAQ postings have resulted in a lot of messages like
MC> this. While its great to see the folks here improving the quality
MC> of the answers, I've yet to see anyone say that they've submitted
MC> their enhancements for inclusion into future revisions. Have
MC> people been doing this silently? (I hope so.)
i have told many to CC the FAQ poster. that makes sure he gets it. and i
have had conversations with him and he is integrating worthwhile
changes. also i told him to add Mail-Copies-To: faq@denver.pm.org which
seems to be in there now but may not be obeyed by all newsreaders.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 9 Mar 2001 08:51:06 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: grep question
Message-Id: <WhUp6.8$Cy2.2091@vic.nntp.telstra.net>
"Droogie" <Ireally@dontthinkso.com> wrote in message
news:3aa7a1b9.78457164@reading.news.pipex.net...
> Id have used:
> m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/
>
> hey you did mention a regex debate
>
Sure, and there have been several about regexen to match IP addresses,
particularly in terms of what is a legal IP address.
I would shorten the above to
m/((\d{1,3}\.){3}\d{1,3})/
since \d == [0-9]
and the [0-9]\. pattern repeats three times...
I also could have done that with the one I submitted the other day...
m/((\d+\.){3}\d+)/
But I certainly don't claim that it only matches legal IP addresses.
However, it does work fine if you only feed it valid IP addresses.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: 9 Mar 2001 01:16:57 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Help to Install Perl
Message-Id: <slrn9agbog.412.damian@puma.qimr.edu.au>
Thus spake Chris Stith on Thu, 08 Mar 2001 17:40:08 -0000:
>...
>Perhaps a score-down of 3000?
>
>*dekaplonk* *dekaplonk* *dekaplonk*
>(tin plonks by 100 points by default ;-)
>
Hell, I went straight to -9999 (slrn), but then, I am not American (aside:
you used to ba able to get t-shirts here with 'I am not American' in English
and Arabic). I was annoyed when she turned out to be posting from multiple
addreses, but that was easy enough to fix.
Cheers,
Damian
--
"Monitoring a nuclear power plant? Well... maybe not. Not sure I'd trust
C for this either as a core dump could lead to, well, a core dump."
-- Michael Carman in comp.lang.perl.misc
------------------------------
Date: 9 Mar 2001 00:03:44 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How do I fetch clipboard content?
Message-Id: <slrn9ag7f0.ic5.abigail@tsathoggua.rlyeh.net>
Jim Turner (turnerj@lapdog.lmtas.lmco.com) wrote on MMDCCXLVI September
MCMXCIII in <URL:news:9891cq$6722@news1.lmtas.lmco.com>:
() Greetings. I am running Perl 5 in Linux and X. Is there a way to
() fetch the current contents of the clipboard? What I want to write is a Perl
() script which I can highlight text in an xterm, click on a button to invoke
() my Perl script and have it do something with the text I highlighted.
I've the following in my .fvwmrc:
Key F11 A N \
Exec /opt/netscape/netscape -noraise -remote \
"openURL(`perl -MTk -e 'print MainWindow->new->SelectionGet'`,\
new_window)"
which on hitting F11 fetches whatever is currently selected in a new
Netscape window.
The Perl part is obvious.
Abigail
--
perl -wlne '}print$.;{' file # Count the number of lines.
------------------------------
Date: Fri, 9 Mar 2001 00:31:39 -0000
From: "Darren" <darrenls21@yahoo.com>
Subject: Newbies welcome
Message-Id: <2xVp6.4139$t1.320148@news6-win.server.ntlworld.com>
This is to all newbies on this and any other newsgroup.
Do not ever be afraid of asking a question on something relevent to the
newsgroup you are visiting.
Bear in mind that every single person on any newsgroup was a newbie once, so
if they slate you for being a newbie then they are hypocrites and should be
ignored. Do not give up. Everybody learns, even the so called experienced
though they would often not admit it
------------------------------
Date: Fri, 9 Mar 2001 09:43:01 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: number of characters (length)
Message-Id: <u2Vp6.11$Cy2.3535@vic.nntp.telstra.net>
"francesca" <plusc@freeserve.net> wrote in message
news:9892rg$70o$1@news7.svr.pol.co.uk...
> while using this statement below to match words
> what do i need to add to match only the words >= 6 characters
>
> if ($matching=~ /\b(\w+)\b/)
>
> or how could i reduce the length to 6 after the matching ?
> removing the characters form the end only
>
It would seem to me that matching words >= 6 and reducing length to 6
are not the same thing at all.
For the first, match only words of 6 or more, use the quantifiers
if ($matching=~ /\b(\w{6,})\b/) # 6 or more characters {n,m} where n is
min, and m is max
For the second you need to remove everything after the first 6
characters. You could use substr, index or a re.
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Thu, 08 Mar 2001 16:20:44 -0700
From: Derrell Durrett <durrett@xilinx.com>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <3AA813CC.8A177446@xilinx.com>
Terrence Monroe Brannon wrote:
> I'm not exactly sure what your problem is. If you are new to Perl here is
> the first rule that will save you many headaches:
> ALWAYS use strict;
> ALWAYS use warnings;
> ALWAYS use diagnostics;
>
> Attached is a working example.
>
> Robert Shockley wrote:
>
> > I am new to Perl and having problems with recursive routines in Perl.
> > The following
> > code produces a 0 instead of 720, as it should, on input 6:
> >
> > sub factorial{
> > $number = shift @_;
> > return 1 if $number == 0;
> > return ( $number * factorial( $number - 1 ) );
> > }
> > print factorial(6) . "\n";
>
OK, so I get why the OP's version fails without use strict (I think). But in
playing with it myself, I stumbled on something I don't understand. Can
anyone explain why the ff code behaves just like the OP's? If I follow the
bouncing number (say, via the debugger), the recursive calls to factorial
contain the correct value of $number for each interation, and the logical
flow seems correct (returning 1 when $number == 0, as above).
#!/usr/local/bin/perl -w
use strict;
sub factorial
{
my $number = shift;
return 1 unless $number;
return $number * factorial(--$number);
}
print factorial(6) . "\n";
--
Derrell Durrett Xilinx, Inc. Productivity Engineering
Boulder, Colorado
303.544.5498
------------------------------
Date: 08 Mar 2001 19:55:10 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <m38zmfep75.fsf@mumonkan.sunstarsys.com>
Derrell Durrett <durrett@xilinx.com> writes:
> #!/usr/local/bin/perl -w
>
> use strict;
>
> sub factorial
> {
> my $number = shift;
> return 1 unless $number;
> return $number * factorial(--$number);
^^^^^^^ ^^^^^^^^^
This is quite clever, but in a Very Bad Way:
% perl -wle 'my $number=1 ; print $number * (--$number);'
0
%
It is a cardinal sin to rely on the order of evaluation
in a real program.
Joe Schaefer
--
%ENV=(); $A="\rr jpeurls ht\ba \rcankotehe"x666;END{ system
"$^X -wT $0 $^S";print"r\n"}sub foo{$_=pop||exit;/$_/;print
eval 'BEGIN{$^H='. ($^H+=666) .'}$_[-(()=$A=~//g)+$[]';}@_=
reverse$A=~/./g;&foo while$ARGV[0]=~//g;#evil mess for *nix
------------------------------
Date: 08 Mar 2001 20:03:26 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <m34rx3eotd.fsf@mumonkan.sunstarsys.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
> This is quite clever, but in a Very Bad Way:
>
> % perl -wle 'my $number=1 ; print $number * (--$number);'
> 0
OOPS. I meant to post-decrement:
% perl -wle 'my $number=1; print $number * $number--;'
0
% perl -wle 'my $number=1; print $number-- * $number;'
0
> It is a cardinal sin to rely on the order of evaluation
> in a real program.
Indeed.
--
Joe Schaefer "You can't depend on your eyes when your imagination is out of
focus."
--Mark Twain
------------------------------
Date: Fri, 09 Mar 2001 02:01:04 GMT
From: Kirk Is <kisrael@andante.eecs.tufts.edu>
Subject: Pine compatible Perl mailbox module?
Message-Id: <APWp6.1062$k2.42199@news.tufts.edu>
Is there a Perl module available that lets you perform basic mailbox tasks
(get headers, read message, delete message, mark message as read) in such
a way that Pine will understand what you were trying to do? (i.e. if you
try to read a message with "mail", Pine balks a bit and moves it to the
first message, or maybe mail does that.)
This is for a system where Pine just uses the local inbox in
/var/spool/mail/username. I'd like to continue a webfrontend I've
started/
--
Kirk Israel - kisrael@cs.tufts.edu - http://www.alienbill.com
DEALING WITH MORTALITY: A Skeptic's Guide - http://kisrael.com/mortal/
------------------------------
Date: 8 Mar 2001 23:22:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Quick script question - I'm lost
Message-Id: <slrn9ag52f.ic5.abigail@tsathoggua.rlyeh.net>
Ron Auer (rrauer@mitre.org) wrote on MMDCCXLVI September MCMXCIII in
<URL:news:3AA80D3F.3BD26F38@mitre.org>:
@@ Abigail,
@@
@@ Thanks for the rapid reply.
@@
@@ I am having problems making this work.
KERNEL PANIC!
Reply seen without encountering context.
Dumping core in /var/abigail/MCMXCIII-IX-MMDCCXLVI/
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................4194304 pages (double sided, three holes) dumped
Shutting down
Syncing file systems
Resetting
Hostid 0:0:0:0:0:6:6:6
/|\-/|\- Checking RAM
Jeopardy emergency shutdown detected; entering maintenance mode
Please give root password or control-d to continue: *************************
# fsck -j /dev/news
WOOOHAA!!!
Jeopardy posting found on spool, do you want to:
F) Format device
U) Unsubscribe
C) Continue
K) Killfile
?) Help
ESC) Abort
Your choice: K
Poster kill-filed.
# exit
Checking filesystems...
/dev/perl ok
/dev/news ok
/dev/warez ok
/dev/porn ok
/dev/more-porn ok
/dev/mp3 ok
/dev/movies ok
The system is coming up.
abigail login:
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 9 Mar 2001 01:03:44 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Quick script question - I'm lost
Message-Id: <slrn9agavn.412.damian@puma.qimr.edu.au>
Thus spake Ron Auer on Thu, 08 Mar 2001 15:52:47 -0700:
[top posting fixed. ]
[It is a convention in this newsgroup to post in context. Using a
newsreader that defaults to top posting does not override this ]
>Abigail wrote:
>> ...
>> Instead of doing $hits {$ip} ++, do
>
>> $hits {$ip} -> {$host} ++;
>
>> And print things as:
>
>> while (my ($ip, $hosts) =3D each %hits) {
>> local $" =3D ", ";
>> my @hosts =3D keys %$hosts;
>> my $sum;
>> map {$sum +=3D $_} @{$hosts}{@hosts};
>> print "$ip $sum @hosts\n";
>> }
>
>...
[You seem to be having some terrible problem with character encoding --
where are all these '='s and '3D's coming from? ]
>
> I am having problems making this work.
>
> I enter $hits{$ip} -> {$host}++
> =
>
> But, then directly underneath to check I enter:
>
> print "$hits{$ip} \n";
> =
>
> And I get HASH(0x>.......)
>
Yes, that's because the value is a reference to an anonymous hash. See
perlref, perldsc and/or perllol for details. In brief:
print "$_:\t$hits{$ip}->{$_}\n" for keys %{$hits{$ip}};
would print out the keys and values of the hashref.
> And, when the print loop is done, all that prints is the ip.
>
You need to assign to the $host variable with each iteration, the same way
you are assigning to the $ip variable. NB, you might want to pick more
explicit names -- to me, neither 'ip' nor 'host' mean anything wrt a
client/server distinction.
> I have looked over the code I entered, and I don't see a typo.
You should copy and paste code. That way you avoid typos :-).
>Since I
>am not real good with hashes, I would appreciate any explanation as to
>what I may be doing wring. Thank you very much for your time.
>
As above, you could also benefit from re-reading the perldata manpage. If
you are on a system where 'man perldata' doesn't work, try going to a
command prompt and typing 'perdoc perldata'.
HTH,
Cheers,
Damian
PS. One of my coworkers caught me ROTFLOL after reading Abigail's followup
to the post above. I am expecting men in white coats to turn up any
moment.
--
@;=0..23;@;{@;}=split//,<DATA>;while(1){for($;=@;;--$;;){next if($:=rand($;+
1))==0+$;;@;[$;,$:]=@;[$:,$;];print "\x"for 0..2*(@|*23)}print map{$;{$_}}(@|
,@;);push@|,shift@;if$;[0]==@|;last if!@;;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker
------------------------------
Date: Thu, 8 Mar 2001 18:15:41 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quick script question - I'm lost
Message-Id: <slrn9ag4kt.e2d.tadmc@tadmc26.august.net>
[ Jeopardectomy performed ]
Ron Auer <rrauer@mitre.org> wrote:
>Abigail wrote:
>>
>> Ron Auer (rrauer@mitre.org) wrote on MMDCCXLVI September MCMXCIII in
>> <URL:news:3AA7D271.93E103EF@mitre.org>:
>> `'
>> `' Now, I find the number of times an ip apprears in all the records so I
>> `' do:
>> `'
>> `' $hits{$ip}++
[snip]
>> `' Now, I need to add to the number of hits, the host associated with the
>> `' ip in the record where the ip was counted
[snip]
>> `' I only need to list a host name once.
>> `'
>> `' Any ideas on how to accomplish this efficiently (processing time is a
>> `' concern)?
>>
>> Instead of doing $hits {$ip} ++, do
>>
>> $hits {$ip} -> {$host} ++;
Note that the level of references got one deeper here.
Instead of the count for $ip, you have all of the individual
counts for $host at $ip.
You will need to add them up in your code if you want "by IP" totals.
>> And print things as:
>>
>> while (my ($ip, $hosts) = each %hits) {
>> local $" = ", ";
>> my @hosts = keys %$hosts;
>> my $sum;
>> map {$sum += $_} @{$hosts}{@hosts};
The line above is adding up the "by IP" total in $sum.
>> print "$ip $sum @hosts\n";
>> }
>>
>> Abigail
>> --
>> perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
You should never quote signatures.
>Abigail,
> I enter $hits{$ip} -> {$host}++
>
> But, then directly underneath to check I enter:
>
> print "$hits{$ip} \n";
>
> And I get HASH(0x>.......)
^^^^^^^^ that is what a reference looks like when
you print it. It usually means that you
didn't dereference something that you
meant to deref.
That is what you are supposed to get.
If you want some other output, then give perl some other instructions :-)
To see the newly incremented value:
print "$hits{$ip}{$host}\n";
> And, when the print loop is done, all that prints is the ip.
Can't troubleshoot unseen code, you're on your own with that one...
> I have looked over the code I entered, and I don't see a typo.
^^^^^^^^^^^^^^^^^^
Neither do we.
>Since I
>am not real good with hashes,
The problem is not with hashes. The problem is with references.
>I would appreciate any explanation as to
>what I may be doing wring.
Printing a reference instead of deref'ing then printing.
>Thank you very much for your time.
Invest some of yours by typing the below, then reading what it shows you:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
Good luck!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 9 Mar 2001 01:58:38 +0100
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Skilled discussion: Multiple inheritance (MI) of attributes in perl ?! [Invited to comment on this code]
Message-Id: <9899tn$vmfa$1@ID-71895.news.dfncis.de>
Hello perl-gods,
after intensiv study, i come to the point that currently perl has no
satisfying implementation for MULTIPLE INHERITANCE (MI) on object
attributes. After writing some modules with suffering under my
non-standard/flexible MI simulation, i just wanted to share this code -
which is - at least from my point of view - a overall good approach:
1. Assuming every package has a kind of 'init'-like method, which
initializes the class/object attributes (old story!).
2. The constructor (new) calls our 'mi' (appended) function, which correctly
calls the 'init' methods of his @ISA packages:
a) 'mi' should traverse the recursiv isa tree in a sequence starting
with the basest base-classes (reverse isa tree!).
b) the main child constructor (new) parameters should be eaten by
each call, to prevent unwanted multiple interpretation.
(Class::MethodMaker helps a lot !).
c) right blessing into their packages, when calling the 'init'-like
methods, because they may call other functions/methods of their
package/class.
Here comes my sample implementation, and i just wanted to hear intelligent
suggestions to rapidly mangle the code into a comprehensive CPAN-module:
sub mi
{
my $this = shift;
my $class = shift;
my %arghash = @_;
# inherit attributes (single/multiple)
# cookbook says in Recipe 13.10
# my $self = bless {}, $class;
#
# for my $class (@ISA) {
# my $meth = $class . "::_init";
# $self->$meth(@_) if $class->can("_init");
# }
for my $parent ( inheritance_isa($class) )
{
for my $initmethod ( qw( init initialize ) )
{
my $method = $parent . '::' . $initmethod;
# did the parent have this class method
#print( "Find $method ? " );
if( my $coderef = $parent->can( $initmethod ) )
{
#print( "found !\n" );
# This calls a parent method with our object/package.
# "This is very fragile code" as stated in the cookbook
# recipe 13.10, which breaks into unusability when we
# have following scenario:
#
# The "init" method of the parent class contains method calls
# of his own class and this method is overriden in this class.
#
# What happens is that within the init method of the foreign
# class the overriden method of the child class is called which
# in most cases leads to wrong initialization of our object.
#
# Further: The main problem is that we call a parent method
# with an object blessed in our current package !
#
# SOLUTION: Correctly create a parent object (which leads to
# the right blessing and therefore for correct package/object
# scenario) and simply copy the attributes of the parent
# to the child.
# store old package/class name
my $class = ref($this);
# bless $this instance to parent package
bless $this, $parent;
# call parent method with parent blessed instance
$this->$coderef( %arghash );
# restore our child package/class
bless $this, $class;
last;
}
}
}
return $this;
}
# functions
sub classISA
{
my $class = shift || die "classISA needs an argument <classname>";
no strict 'refs';
return @{$class.'::ISA'};
}
sub _isa_tree
{
my $list = shift;
my $level = shift;
for my $child ( @_ )
{
my @parents = classISA( $child );
if(1)# scalar @parents )
{
$level++;
push @{ $list->{$level} }, $child;
#ind $level;
#printfln "\@%s::ISA = qw(%s);\n",$child , join( ' ', @parents );
_isa_tree( $list, $level, @parents );
$level--;
}
}
}
# returns the isa tree sorted by level of recursion
# 5 -> Exporter
# 4 -> Object::Debugable
# 3 -> Person
# 2 -> Employee
# 1 -> Doctor
sub isa_tree
{
my $list = {};
_isa_tree( $list, 0, @_ );
return $list;
}
# returns the isa tree in a planar list (for con-/destructor queue's)
sub inheritance_isa
{
my @ALL;
my $construct_list = isa_tree( @_ );
foreach my $level ( sort { $b <=> $a } keys %$construct_list )
{
push @ALL, @{ $construct_list->{$level} };
}
return @ALL;
}
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V10 Issue 448
**************************************