[21930] in Perl-Users-Digest
Perl-Users Digest, Issue: 4152 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 21 03:06:26 2002
Date: Thu, 21 Nov 2002 00:05:13 -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 Thu, 21 Nov 2002 Volume: 10 Number: 4152
Today's topics:
Re: 'Burning' memory in perl <tassilo.parseval@post.rwth-aachen.de>
Re: 'Burning' memory in perl <nospam-abuse@ilyaz.org>
Re: Access a Hash with $a{...} AND $a{...}[0] the same <goldbb2@earthlink.net>
Re: Can someone recommend a beginner's book on Perl? (Randal L. Schwartz)
Re: Can someone recommend a beginner's book on Perl? <jeff@vpservices.com>
Error while executing a program (Yogen)
Re: Error while executing a program <ak@freeshell.org.REMOVE>
Help ..interpret this ?? (Jay)
Re: Help ..interpret this ?? <ak@freeshell.org.REMOVE>
Re: help this Newbie in Distress <doris@chris.com>
Re: help this Newbie in Distress (Jay Tilton)
Re: help this Newbie in Distress <doris@chris.com>
Re: help this Newbie in Distress (Damian James)
Re: help this Newbie in Distress (Jay Tilton)
Re: implementing a self() method for classes (Bryan Castillo)
Re: nslookup and perl <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Pass params to subrotuine printf?? <joe+usenet@sunstarsys.com>
Re: passing address between classes - OO type question <tassilo.parseval@post.rwth-aachen.de>
Re: passing address between classes - OO type question <uri@stemsystems.com>
Re: passing address between classes - OO type question (kit)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Nov 2002 09:37:02 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: 'Burning' memory in perl
Message-Id: <arfl3u$co5$1@nets3.rz.RWTH-Aachen.DE>
Also sprach MB:
> I'm writing a program that prompts for passwords, and I'd like to make
> sure that the password is gone from memory once I've finished with it
> (so it doesn't appear in a core dump or something). In C I'd use
> memset(...), but since memory management is not right on the surface of
> perl I'm not sure of the exact procedure.
>
> Would something like
>
> $passwd = ' ' x length($passwd);
>
> work? Or would that just allocate another bit of memory and leave the
> old chunk still containing the password?
>
> What about:
> {
> my $passwd = get_passwd();
> do_something_with_passwd($passwd);
> }
>
> Will going out of scope scrub the memory as well? I'm guessing not, but
> you never know...
Speaking about core dumps, this wont help since a corefile is actually
a backtrace. I just tried the following:
ethan@ethan:~$ perl
my $password = "hallo";
$password = ' ' x length($password);
<STDIN>;
__END__
And on another console
ethan@ethan:~$ kill -11 `pidof perl`
Running 'strings' on the corefile, I see for instance:
main
$password
hallo
and later:
= '' x length($password);
If you absolutely want to avoid corefiles, you could add a signal
handler for sigsegv:
$SIG{SEGV} = sub { warn "segfaulted"; exit 1 };
As for really clearing or overwriting a string, you could probably do it
with a small xsub:
void
clear (var)
PREINIT:
STRLEN len;
INPUT:
SV *var;
char *string = SvPV(var, len);
PPCODE:
memset(string, 0, strlen(string));
Wrap that into your own little XS module and do a 'clear($password)'.
But then I think you are just a little too paranoid here.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 21 Nov 2002 06:25:13 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: 'Burning' memory in perl
Message-Id: <arhu89$1ik9$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
MB
<mb@uq.not.au>], who wrote in article <3DDB0CFB.3030805@uq.not.au>:
> I'm writing a program that prompts for passwords, and I'd like to make
> sure that the password is gone from memory once I've finished with it
> (so it doesn't appear in a core dump or something). In C I'd use
> memset(...), but since memory management is not right on the surface of
> perl I'm not sure of the exact procedure.
>
> Would something like
>
> $passwd = ' ' x length($passwd);
>
> work?
Yes, it would overwrite the current contents of $passwd (unless it was
in utf-8) with the current implementations. However,
> my $passwd = get_passwd();
Now the contents password is not only in $passwd, but possibly in many
other locations (return value of get_passwd(), the variables and
temporaries used by get_passwd(), the STDIO buffers etc). There is no
way to overwrite all *these* locations...
Hope this helps,
Ilya
------------------------------
Date: Thu, 21 Nov 2002 02:26:58 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Access a Hash with $a{...} AND $a{...}[0] the same way... / use of tie
Message-Id: <3DDC8AC2.8C7C4B1A@earthlink.net>
Christoph Bergmann wrote:
>
> Given a subroutine which returns a hash of arrays, something like:
>
> $result{Name}[0]
> $result{Street}[0]
> $result{Name}[1]
> ...etc.
>
> Sometimes it returns only one result, thus there would be
>
> $result{Name}[0]
> $result{Street}[0]
>
> only. For convenience I would like to access the resulting hash with
>
> $result{Name}
> $result{Street}
The simplest way of doing this is to make $result{Name} return a blessed
arrayref, with an overloaded "" operator in that class, which simply
returns the first element of the array. Something like:
package AutoDereference;
use overload '""' => sub { $_[0][0] };
1;
__END__
Then your subroutine would return a hash of arrayrefs with all those
arrayrefs blessed into this class.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 20 Nov 2002 19:33:09 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: tadmc@augustmail.com
Subject: Re: Can someone recommend a beginner's book on Perl?
Message-Id: <86zns3lhqi.fsf@red.stonehenge.com>
>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:
Tad> The Llama book on the other hand, is the usual recommendation
Tad> for a "Perl tutorial for programmers".[1]
Tad> The Preface in the Llama (3rd edition) even says so:
Tad> Although you don't need to know a single bit about Perl to
Tad> begin reading this book, we do recommend that you already have
Tad> familiarity with basic programming concepts such as variables,
Tad> loops, subroutines, and arrays, ...
Tad> I dunno AppleScript and HyperCard, so I don't know if the OP
Tad> has that knowledge or not.
Yes, AppleScript and HyperCard are both serious programming
languages, on the order with Perl4 or so.
print "Just another Perl hacker," # and someone who had to learn "before the book came out"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 20 Nov 2002 19:49:34 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Can someone recommend a beginner's book on Perl?
Message-Id: <3DDC57CE.90904@vpservices.com>
Randal L. Schwartz wrote:
>>>>>>"Tad" == Tad McClellan <tadmc@augustmail.com> writes:
>>>>>>
>
> Tad> The Llama book on the other hand, is the usual recommendation
>
> print "Just another Perl hacker," # and someone who had to learn "before the book came out"
Hmm, maybe you should have waited until the book came out to learn. It
would have been so much easier to learn then. But writing the book
might have been a bit more difficult if you'd done it in that order.
--
Jeff
------------------------------
Date: 20 Nov 2002 22:40:50 -0800
From: yogen_vk@yahoo.com (Yogen)
Subject: Error while executing a program
Message-Id: <336caaad.0211202240.35197927@posting.google.com>
Hi
I have just joined the group & just started learning Perl.
I am facing the following problems.Can anybody help me ?
I.
When I execute this program, I get the error.
#! /bin/sh
#! /usr/local/bin/perl -w
echo " Echo ";
$input=<STDIN> ;
echo $input;
The error is
./echo.pl
Echo
./echo.pl: syntax error at line 6: `;' unexpected
and the other is
II . When I run
#!/bin/sh
#!/usr/local/bin/perl -w
$cookie = " ";
while($cookie ne "cookie")
{
echo " Give me a cookie: ";
chomp($cookie = <STDIN>);
}
echo "End of cookie \n ";
I get the error
./cookie.pl
./cookie.pl: =: not found
./cookie.pl: syntax error at line 9: `chomp' unexpected
------------------------------
Date: Thu, 21 Nov 2002 06:48:03 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: Error while executing a program
Message-Id: <slrnato91e.7ks.ak@otaku.freeshell.org>
Submitted by "Yogen" to comp.lang.perl.misc:
> Hi
> I have just joined the group & just started learning Perl.
> I am facing the following problems.Can anybody help me ?
>
> I.
> When I execute this program, I get the error.
> #! /bin/sh
> #! /usr/local/bin/perl -w
The first of the above two line makes the text in the file be
interpreted by the /bin/sh shell, not by Perl at all.
>
> echo " Echo ";
There is no 'echo' function in Perl. See "perldoc -f print" and
similarly for 'printf'.
> $input=<STDIN> ;
The shell interpreting this script will cope ok with the echo
line, but the above line will cause an error as it's not a shell
script construct.
> echo $input;
>
> The error is
>
> ./echo.pl
> Echo
> ./echo.pl: syntax error at line 6: `;' unexpected
>
> and the other is
>
> II . When I run
>
> #!/bin/sh
> #!/usr/local/bin/perl -w
Again, remove the first line. With it, the file will be run as a
schell scipt, not as a Perl program.
>
> $cookie = " ";
This is invalid shell script syntax.
(etc.)
>
> while($cookie ne "cookie")
> {
> echo " Give me a cookie: ";
> chomp($cookie = <STDIN>);
> }
>
> echo "End of cookie \n ";
>
> I get the error
>
> ./cookie.pl
>
> ./cookie.pl: =: not found
> ./cookie.pl: syntax error at line 9: `chomp' unexpected
--
Andreas Kähäri --==::{ Have a Unix: netbsd.org
--==::{ This post ends with :wq
------------------------------
Date: 20 Nov 2002 22:43:04 -0800
From: jamni@inorbit.com (Jay)
Subject: Help ..interpret this ??
Message-Id: <7d9182e9.0211202243.1d502ff5@posting.google.com>
I am just a beginner to Perl. I have come across this search string
but unable to understand what it exactly searches.
Can anyone tell me what this expression means ??
/\S+\/([^\/]+)\/$ARCH/
Thanks
Jamni
------------------------------
Date: Thu, 21 Nov 2002 06:54:53 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: Help ..interpret this ??
Message-Id: <slrnato9e8.7ks.ak@otaku.freeshell.org>
Submitted by "Jay" to comp.lang.perl.misc:
> I am just a beginner to Perl. I have come across this search string
> but unable to understand what it exactly searches.
>
> Can anyone tell me what this expression means ??
>
> /\S+\/([^\/]+)\/$ARCH/
It's a regular expression, see the perlre manual.
It matches a non-zero number of non-whitespace characters, followed by
'/', followed by a non-zero number of characters that are not
'/', followed by '/', followed by whatever is in the variable
$ARCH.
If the regex matches, the variable $1 will hold the text matched
by "a non-zero number of characters that are not '/'" ([^\/]).
Hmmm...does [^\/] mean "a character, not '/'", or "a character,
not '/' nor '\'"?
--
Andreas Kähäri --==::{ Have a Unix: netbsd.org
--==::{ This post ends with :wq
------------------------------
Date: Thu, 21 Nov 2002 02:22:49 GMT
From: D <doris@chris.com>
Subject: Re: help this Newbie in Distress
Message-Id: <3DDC4360.F2601E93@chris.com>
No, I just wanted a suggestion to add to my code, which currently is:
$_ = lc,
s/\b(\w)/\u$1/g,
s/('S|\bOf| And| The)\b/\L$1/g,
s/\(P\b/(paperback/,
for $list_of_titles[2];
"David K. Wall" wrote:
> D <doris@chris.com> wrote:
>
> > My goal is to take a book title, which starts out in all upper case,
> > and then make the whole thing lower case, except for the first letter
> > of each word.
> >
> > EXAMPLE:
> > "THE STORY OF THE CAT AND DOG"
> > will turns into this:
> > "The Story of the Cat and Dog"
> >
> > ...However....let's say that the title has either the word "CD" or
> > "CD-ROM" in it. In that case, I want to leave the "CD" or "CD-ROM" in
> > it's original uppercase.
>
> Text::Autoformat will do most of this for you if you use the headline
> option. When I tried a short test it turned CD-ROM into Cd-rom, but
> you can always change it back.
>
> There's an FAQ entry on capitalization (perldoc -q capitalization)
> which you seem to have read or independently came up with a similar
> solution.
>
> --
> David Wall - me@dwall.fastmail.fm
> "Oook."
------------------------------
Date: Thu, 21 Nov 2002 02:21:52 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: help this Newbie in Distress
Message-Id: <3ddc3a3a.334735413@news.erols.com>
D <doris@chris.com> wrote:
: My goal is to take a book title, which starts out in all upper case, and
: then make the whole thing lower case, except for the first letter of
: each word.
:
: EXAMPLE:
: "THE STORY OF THE CAT AND DOG"
: will turns into this:
: "The Story of the Cat and Dog"
:
: ...However....let's say that the title has either the word "CD" or
: "CD-ROM" in it. In that case, I want to leave the "CD" or "CD-ROM" in
: it's original uppercase.
:
: EXAMPLE:
: "THE STORY OF THE CAT AND DOG (WITH CD-ROM)"
: should turn into this:
: "The Story of the Cat and Dog (With CD-ROM)"
[minor edits to original article for better flow]
: Here's the code that I've been using.
:
: $_ = lc,
: s/\b(\w)/\u$1/g,
: s/('S|\bOf| And| The)\b/\L$1/g,
: s/\(P\b/(paperback/,
: for $list_of_titles[2];
:
: I am wanting to avoid ADDING an extra line of code that will switch the
: lowercase back to uppercase.
Why is that? It seems like an artificial restriction that excludes the
most obvious, least intrusive modification to existing code. After all,
the code already uses s/// to handle a few special cases. What's one
more?
------------------------------
Date: Thu, 21 Nov 2002 03:21:10 GMT
From: D <doris@chris.com>
Subject: Re: help this Newbie in Distress
Message-Id: <3DDC510E.A29C2AC3@chris.com>
Well, because I'm thinking that "plan A" would be "more efficient" (faster)
than "plan B," um....from a "benchmarking" point of view :-)
Plan A (consists of 2 steps)
1.) Take book title except CD or CD-ROM
2.) Do stuff to it
Plan B (consists of 3 steps)
1.) Take book title
2.) Do stuff to it
3.) Undo some stuff
---------------------------
p.s. I am intrigued by the way you quoted my message in your reply. It's
cool!
Jay Tilton wrote:
> D <doris@chris.com> wrote:
>
> : My goal is to take a book title, which starts out in all upper case, and
> : then make the whole thing lower case, except for the first letter of
> : each word.
> :
> : EXAMPLE:
> : "THE STORY OF THE CAT AND DOG"
> : will turns into this:
> : "The Story of the Cat and Dog"
> :
> : ...However....let's say that the title has either the word "CD" or
> : "CD-ROM" in it. In that case, I want to leave the "CD" or "CD-ROM" in
> : it's original uppercase.
> :
> : EXAMPLE:
> : "THE STORY OF THE CAT AND DOG (WITH CD-ROM)"
> : should turn into this:
> : "The Story of the Cat and Dog (With CD-ROM)"
>
> [minor edits to original article for better flow]
>
> : Here's the code that I've been using.
> :
> : $_ = lc,
> : s/\b(\w)/\u$1/g,
> : s/('S|\bOf| And| The)\b/\L$1/g,
> : s/\(P\b/(paperback/,
> : for $list_of_titles[2];
> :
> : I am wanting to avoid ADDING an extra line of code that will switch the
> : lowercase back to uppercase.
>
> Why is that? It seems like an artificial restriction that excludes the
> most obvious, least intrusive modification to existing code. After all,
> the code already uses s/// to handle a few special cases. What's one
> more?
------------------------------
Date: 21 Nov 2002 03:22:51 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: help this Newbie in Distress
Message-Id: <slrnatokca.lv6.damian@puma.qimr.edu.au>
On Wed, 20 Nov 2002 22:09:34 GMT, D said:
>...
>EXAMPLE:
>"THE STORY OF THE CAT AND DOG (WITH CD-ROM)"
>should turn into this:
>"The Story of the Cat and Dog (With CD-ROM)"
>...
>//heres my code:
>
>$_ = lc,
>s/\b(\w)/\u$1/g,
>s/('S|\bOf| And| The)\b/\L$1/g,
>s/\(P\b/(paperback/,
>for $list_of_titles[2];
Here's the way that I would do it, FWIW:
#!perl
use warnings;
use strict;
my $text = 'THE STORY OF THE CAT AND DOG (WITH CD-ROM)';
my %lowerc = map { $_ => 1 } qw/the of and with/;
my %ALLCAP = map { $_ => 1 } qw/CD ROM/;
my %cache;
sub convert {
my $word = $_[0];
$cache{ $word } ||= # the orcish manoeuvre
$ALLCAP{ uc $word }? uc $word
: $lowerc{ lc $word }? lc $word
: ucfirst lc $word;
}
$text =~ s/\b\w+\b/convert($&)/eg;
$text =~ s/^\w/\U$&/; # first word is a special case
print "$text\n";
__END__
HTH
--damian
------------------------------
Date: Thu, 21 Nov 2002 05:03:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: help this Newbie in Distress
Message-Id: <3ddc52ee.341060025@news.erols.com>
[ Please do not top-post replies. Please trim reply-quoted text to the
minimum necessary to establish context. Please read the posting
guidelines at http://mail.augustmail.com/~tadmc/clpmisc.shtml . Posting
chronology restored. ]
D <doris@chris.com> wrote:
: Jay Tilton wrote:
: > D <doris@chris.com> wrote:
: >
: > : Here's the code that I've been using.
: > :
: > : $_ = lc,
: > : s/\b(\w)/\u$1/g,
: > : s/('S|\bOf| And| The)\b/\L$1/g,
: > : s/\(P\b/(paperback/,
: > : for $list_of_titles[2];
: > :
: > : I am wanting to avoid ADDING an extra line of code that will switch the
: > : lowercase back to uppercase.
: >
: > Why is that? It seems like an artificial restriction that excludes the
: > most obvious, least intrusive modification to existing code. After all,
: > the code already uses s/// to handle a few special cases. What's one
: > more?
:
: Well, because I'm thinking that "plan A" would be "more efficient" (faster)
: than "plan B," um....from a "benchmarking" point of view :-)
Well, in the original post, you admit to spending days trying to find
the technique, and in this post you are unsure that run-time will be
significantly changed.
Can you see where this plan has gone off the rails?
Perl's strength compared to other languages is that it enables a
programmer to transform an idea into a working program rapidly. The
price of this development facility is that the Perl program may not run
as quickly as a program written in another language.
Micro-optimization like this during the development stage is a poor use
of time. The first step should be to get the program working as
intended. Identify and optimize the most intensive portions of code
only if the run-time of the completed program is judged to be excessive.
A single s/// operation adds microseconds to the program's overall
run-time. It would need to be executed billions of times to compensate
for the days spent pursuing an alternative technique, and there's no
evidence an alternative would give any significant speed benefit. If,
for example, the program performs even a couple of file or database
operations (depends on external factors, slow), the addition of a s///
operation (internal, very fast) is completely inconsequential.
If run-time is an important issue, a one-time alteration of the data at
its source would be better than altering it on the fly during
presentation. If run-time is the _most_ important issue, consider
migrating the program to C.
Not trying to proselytize or anything. Just summing up a few practical
realities of development time and execution time.
: Plan A (consists of 2 steps)
: 1.) Take book title except CD or CD-ROM
: 2.) Do stuff to it
: Plan B (consists of 3 steps)
: 1.) Take book title
: 2.) Do stuff to it
: 3.) Undo some stuff
Plan A is dramatically oversimplified. As it is, the first step of "do
stuff" is to lower-case the entire string. Altering that step not to
lower-case an arbitrary substring would require bursting it into smaller
steps. As you have most likely figured, a big difficulty is in
concocting a mechanism that correctly identifies word boundaries, but
does not consider the hyphen in "CD-ROM" to be one. A regex with that
capability would likely need some wiggy lookahead/lookbehind assertions
or some /e modifier clumsiness. It would be painful to write (read,
even).
And it will probably increase run-time.
Yuck. Take the easy exit on this one and enjoy a long lunch. :)
: p.s. I am intrigued by the way you quoted my message in your reply. It's
: cool!
Thanks, but what did you like about it?
------------------------------
Date: 20 Nov 2002 20:38:42 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: implementing a self() method for classes
Message-Id: <1bff1830.0211202038.1f9c3802@posting.google.com>
Eric Anderson <eric.anderson@cordata.net> wrote in message news:<pan.2002.11.21.00.02.56.260486.21494@cordata.net>...
> On Mon, 18 Nov 2002 15:26:36 -0500, Bryan Castillo wrote:
> > I don't quite understand what you want. The 2nd paragraph says you don't
> > want the object passed as the first argument of the method, but here in
> > the 3rd paragraph you say you will be using it. Do you mean that you
> > will only use the object passed as the first argument on the first
> > method call?
>
> Perhaps an example would help:
>
> # The user creates this
> sub my_method {
> print self->attribute1;
> }
I still don't see that much value in it over
---------
my $self = shift;
and I think it is silly, yet strangely interesting. But........
You can do this. Look at the code for Carp::Heavy. You can retrieve
the values for arguments on the previous subroutines (stack? right
word?). I don't understand why it puts itself in the DB package to do
it though. But this works for me.
package ThisClass;
use DB;
sub new { bless {} }
sub self {
my @call;
do { { package DB; @call = caller(1) } };
if ($call[4]) {
return @DB::args[0];
}
}
sub test {
self->print_args(@_); # problem here is that I will end up
# with 2 "selfs" on next subs arg list
}
sub print_args {
print join("|", @_);
}
package main;
ThisClass->new->test('bryan', 'castillo');
I wasn't able to modify the array for the previous sub, and
interestingly enough if you try to modify a value in @DB::args you get
the error:
Modification of a read-only value attempted at callem.pl line 11.
Another interesting thing is that you can shift all the args out of
the argument stack, call self and still get the object reference back!
------------------------------
Date: Thu, 21 Nov 2002 08:37:28 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: nslookup and perl
Message-Id: <newscache$g61x5h$0y7$1@news.emea.compuware.com>
Oliver Gruskovnjak wrote (Tuesday 19 November 2002 10:14):
> Hey guys,
>
> I have a question about nslookup and perl.
> I try to make a script which lists all cnames off a node and write it to a
> file, but I can't handle the nslookup commands.
>
> in the shell it's easy just type nslookup wait and then
> ls -t CNAME domain, but you can't figure out this command to put that on
> one line or how to code it in perl,
> can someone help me please I'm really confiused.
>
> thanks in advanced
Would gethostbyname() suffice?
--
KP
------------------------------
Date: 21 Nov 2002 02:33:21 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Pass params to subrotuine printf??
Message-Id: <m3smxve5ry.fsf@mumonkan.sunstarsys.com>
Brian McCauley <nobull@mail.com> writes:
[...]
> The prototype of printf is ($@). This means that you are calling
> printf() with a single argument which is the result of
> commify_series(@A) evaluated in a scalar context.
For the third and last time in this thread,
_NO_.
*PLEASE READ*
% perldoc -f sprintf
Unlike "printf",
"sprintf" does not do what you probably mean ...
^
^
^
^
^
^
SPOT THE s.
HAND.
--
Joe Schaefer "Bad artists always admire each others work."
-- Oscar Wilde
------------------------------
Date: 20 Nov 2002 09:51:39 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: passing address between classes - OO type question
Message-Id: <arflvb$hb7$1@nets3.rz.RWTH-Aachen.DE>
Also sprach kit:
> I have an object / class called "Mum" and another object / class
> called "Kid",
> Mum can control her Kid
> ---------------------------------------
> Let's assume that the implementation of class "Kid" is as follow:
> in Kid.pm
>
> package Kid;
> use strict;
> use warning;
>
> sub new {
> my $self = {
> name => ["Kit"],
> age => [20]
> };
You are aware that you are creating references to anonymous arrays here?
If the attributes are meant to be single elements, then this should
read:
my $self = {
name => "Kit",
age => 20,
};
> bless $self;
> return $self;
> }
While this is not wrong and will work in your case, you should consider
the two argument form of bless(). Yours wont work with inheritance for
example. Also, you must return the return value of bless. Otherwise you
return just a simple non-blessed hash-referenceTherefore I'd change the
constructor:
sub new {
my $class = shift; # will be 'Kit' in your case
my $self = {
name => "Kit",
age => 20,
};
return bless $self, $class;
}
> sub doHomeWork {
> print "$self->{name} is doing homework.";
> }
$self is unknown here:
sub doHomeWork {
my $self = shift;
...
}
> sub doDishes {
my $self = shift; #likewise
> print "$self->{name} is doing dishes";
> }
> 1;
> ---------------------------------------
> Let's assume that the implementation of class "Mum" is as follow:
> in Mum.pm
>
> package Mum;
> use strict;
> use warning;
>
> sub new {
> my $self = {
> name => ["Kit'sMum"],
> age => [40]
> };
> bless $self;
> return $self;
> }
Same problem here. Rewrite to:
sub new {
my $class = shift;
my $self = {
name => "Kit's Mum",
age => 40,
}
return bless $self, $class;
}
> sub control {
> #what should I put if I want to call the doHomeWork subroutine from
> class Kid?
> }
control() gets two parameters: the self object and the object of the
Kid:
sub control {
my ($self, $kid) = @_;
$kid->doHomeWork;
}
> 1;
> ---------------------------------------
> Actually I have two different ideas in mind:
>
> 1) including <use Kid;> in Mun.pm
> then initialize a Kid object globally in Mum class by,
> < my $me = Kid->new(); >
> after that put, this in the control subroutine
> < $me->doDishes(); >
> Am I doing it correct?
No. This is both misleading and wrong. A variable named $me within the
Mum namespace implies that $me is referring to a mother and not to a
child. So it shouldn't hold an instance of Kid.
And it's wrong because a static approach like the above only allows for
one single child. That's the fundamental difference between class data
(that is, static data) and instance data. Instance data are the data
that each instance of an object has. You can create two different
mothers with two different children. If you make it static, then a child
only exists for the class which would mean that any mother in the world
(or any mother you create) could only have the same identical child.
Hmmh, child sharing.
> 2) pass the address of Kid object to class Mum
> However, I don't know the way to do that, could you please take a
> look at it and help me out?
That's the way to go and it's actually what the control() method I wrote
above does. In Perl, objects are passed by reference. So the method
receiving an object gets a reference to the original object....nothing
is duplicated or so. It's still the same child. Think of it as an alias.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 21 Nov 2002 05:24:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: passing address between classes - OO type question
Message-Id: <x7fztvh4vb.fsf@mail.sysarch.com>
>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@post.rwth-aachen.de> writes:
>> bless $self, $class;
>> return $self;
>> }
TvP> The above is not correct. bless() does not change its first argument in
TvP> place. Instead, the blessed reference is what is returned by bless.
TvP> Therefore replace the last two or your lines with:
TvP> return bless $self, $class;
sorry tassilo but you have that wrong and it is a common
misunderstanding about perl objects. bless affects the *referent* which
is what the reference points to. otherwise how would this work:
$foo = Bar->new() ;
$bar = $foo();
$bar->method();
the object is the referent that $foo has a reference too. it must be
blessed or bar would not refer to a blessed object.
bless REF,CLASSNAME
bless REF
This function tells the thingy referenced by REF
that it is now an object in the CLASSNAME package.
If CLASSNAME is omitted, the current package is
used. Because a "bless" is often the last thing in
a constructor, it returns the reference for
convenience. A
notice the convenience return value and that it blesses the thingy and
not the reference.
'thingy' eq 'referent'.
damian invented the use of the term referent.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 20 Nov 2002 21:59:44 -0800
From: manutd_kit@yahoo.com (kit)
Subject: Re: passing address between classes - OO type question
Message-Id: <1751b2b5.0211202159.4c19061d@posting.google.com>
Thanks for your help again, but I probably made some mistake somewhere
so that there is a problem in the output. Could you take a look at it
please?
----<Kid.pm>----
package Kid;
use strict;
use warnings;
sub new {
my $class = shift;
my $self = {
name => 'Kit',
age => 20
};
return bless $self, $class;
}
sub doHomeWork {
my ($self, $name) = @_;
print "$self->{name} is doing homework.";
}
sub doDishes {
my ($self, $name) = @_;
print "$self->{name} is doing dishes";
}
sub rename {
my ($self, $newname) = @_;
$self->{name} = $newname;
}
sub printName {
my ($self, $name) = @_;
print $self->{name};
}
1;
----<Mum.pm>----
package Mum;
use strict;
use warnings;
use Kid;
sub new {
my $class = shift;
my $self = {
name => 'myMum',
age => 40,
kid => {}
};
return bless $self, $class;
}
sub giveBirth {
my ($self, $name, $kid) = @_;
${$self->{kid}}{$name} = Kid->new(name => $name);
# $self->{kid}{$kid}->printName;
}
sub orderUp {
my ($self, $kid) = @_;
$self->{kid}{$kid}->doHomeWork;
# $self->{kid}{}->doHomework;
}
1;
----<driver.pl>----
use strict;
use warnings;
use Mum;
my $aMother = Mum -> new();
$aMother -> giveBirth("perl");
$aMother -> orderUp("perl");
-----result-----
[kit@cs family]$ perl driver.pl
Kit is doing homework
^^^ <===== #not in the original output
----------------
Q1)
it seems that the code
< ${$self->{kid}}{$name} = Kid->new(name => $name); > in Mum.pm
it doesn't change the name of Kid from kit to perl.
Or probably I did have some mistake somewhere in the driver when I
call
the < orderUp > subroutine. Could you mind help me again?
Q2)
There is no way to directly access the Kid's datamembers from any
functions in Mum class, am I correct?
because, I did try that, in Mum.pm
sub giveBirth {
my ($self, $name, $kid) = @_;
${$self->{kid}}{$name} = Kid->new(name => $name);
print $self->{kid}{$kid}->name; #What I want is the print out the
} #Kid's name.
Of course, it didn't work. That's why I make that assumption.
Thank you for the help,
Kit
ps: Thank you Paul and Tassilo, I've learnt alot from you guys. =)
------------------------------
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.
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 4152
***************************************