[12394] in Perl-Users-Digest
Perl-Users Digest, Issue: 5994 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 14 19:07:17 1999
Date: Mon, 14 Jun 99 16:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Jun 1999 Volume: 8 Number: 5994
Today's topics:
Re: a simple search and replace (Hasanuddin Tamir)
Re: a thread on threads <uri@sysarch.com>
Re: a thread on threads <tchrist@mox.perl.com>
Re: Box Plots using Perl & GD? <rootbeer@redcat.com>
Re: can't send large-ish udp packets? <uri@sysarch.com>
Re: examples (Marcel Grunauer)
Re: Extracting PIDs from a 'ps aux' <jbc@shell2.la.best.com>
Re: Extracting PIDs from a 'ps aux' <nolanj00@mh.us.sbphrd.com>
Re: From Perl, Getting Dates from Sysbase. <cassell@mail.cor.epa.gov>
Re: help with WIN32::OLE <cassell@mail.cor.epa.gov>
Increment counter by Decials? <trent@jps.net>
Re: Increment counter by Decials? <uri@sysarch.com>
Re: Mime...Perl...MS Outlook...and HTML <rootbeer@redcat.com>
Re: MS Visual SourceSafe Automation in PERL ? (Jan Dubois)
Re: MS Visual SourceSafe Automation in PERL ? (Jan Dubois)
Re: overwrite "print" ? <info@java.seite.net>
Re: Parellel operation (Hasanuddin Tamir)
Re: Perl class and constructor (Damian Conway)
Re: Perl class and constructor <tchrist@mox.perl.com>
Re: Perl tuning/speed question: all subsets of a set of (Larry Rosler)
Re: pipe question (Hasanuddin Tamir)
Re: Q: listing all currently installed modules <uri@sysarch.com>
search entries whose attribute name start with special bing-du@tamu.edu
Re: Sorting Arrays of Arrays, Thanks! (Completed script (Marcel Grunauer)
Re: taint checking setuid error message <rootbeer@redcat.com>
Re: using perl scripts in VC++'s post-build step <rootbeer@redcat.com>
What can and should not be done in Perl <neil@pacifier.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Jun 1999 12:13:55 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: a simple search and replace
Message-Id: <slrn7masfs.7f8.hasant@borg.intern.trabas.co.id>
On Tue, 8 Jun 1999 19:40:14 +0500, Faisal Nasim <swiftkid@bigfoot.com> wrote:
> try
>
> open FILE , "bond.html";
> $content = join '' , <FILE>;
> close FILE;
>
> $content =~ s/<p><strong>/<p>/gi;
>
> open FILE , ">bond.html";
> print FILE $content;
> close FILE;
Could be in once file opening...
and you didn't check the return value.
open FILE, "+<bond.html" or die "can't open: $!";
my @content; # of course there
while (<FILE>) { # are many better
s/<p><strong>/<p>/gi; # and more efficient
push @content, $_; # ways in this part
} #
seek FILE, 0, 0 or die "can't seek: $!";
truncate FILE, 0 or die "can't truncate: $!";
print FILE @content;
close FILE or die "can't close: $!";
Or how about this:
% perl -pi.bak -e 's/<p><strong>/<p>/gi' *.html
HTH,
--
-hasan-
uhm, no more sig(h)
------------------------------
Date: 14 Jun 1999 18:24:47 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a thread on threads
Message-Id: <x7k8t6h13k.fsf@home.sysarch.com>
>>>>> "GB" == Greg Bartels <gbartels@xli.com> writes:
GB> the requirements are:
GB> 1) simultaneous subroutine execution control
GB> (multiple subroutines executing at same time
GB> and being able to start stop subroutines via subroutine call.)
fork processes do this just fine.
GB> 2) completely shared data
GB> (all threads uses exactly the same data space)
multiple processes can share data using sys V shared memory ops in perl.
GB> 3) low overhead, I'll be doing lots of forking or threading,
GB> or whatever I end up using.
are you goiing to fork for each call or fork a bunch and then start/stop
them? if all the forking is done first, then the overhead is
gone. context switching among processes is not that heavy compared to
creating a new process. why are so worried about efficiency? your
example simulation doesn't seem to care.
GB> 4) win32 compatibility would be nice, since half the machines
GB> here at work run NT. Not my decision, but I'm stuck with it.
sorry to hear that. winblows only likes threads.
GB> sub first_sub
GB> {
GB> $string .= "Abott";
GB> MySleep(5);
GB> $string .= "costello \n";
GB> }
GB> sub second_sub
GB> {
GB> MySleep(1); #make sure first_sub actually goes first
GB> $string .= " and ";
GB> MySleep(20);
GB> print $a ;
GB> }
that is not guaranteed to execute sequentially. without mutex locks
no sequencing is ever guaranteed in a multi-process/thread environment.
GB> $a = '';
GB> Schedule(\&first_sub, 'now');
GB> Schedule(\&second_sub, 'now');
GB> EventHandler(); # executes all schedule events,
GB> # wont return until all events are finished.
easy to do with forked processes. it's about as easy as with threads and
if you use pipes you won't have the mutex issues.
GB> Schedule causes a fork or a process or a thread to be created
GB> It sets up the thread to call the subroutine
GB> but nothing is executed.
why not have many processes forked off first and then just
trigger/schedule ones as you need them. much simpler than forking on the
fly. stop thinking in threads but in parallel execution. how that
happens is not affected by the parallel logic you need.
GB> EventHandler causes all processes to execute.
GB> MySleep causes its process to stop execution and schedule
GB> restart at some point in the future.
that is easily done with kill and signal handling. SIGSTOP shoul dbe
just the ticket.
GB> I dont know how to do this with fork in a clean manner.
GB> I also read that fork has a lot of overhead, and I'll
GB> be doing a _LOT_ of forking for a hardware simulator.
GB> every piece of hardware will simulate with its own process.
as i said, the forking can be done first so that part of the overhead is not
counted.
GB> All I need is execution control, all the data is shared.
you haven't shown why you have to share the data. and i have shown you
can with pipes or shared memory.
GB> threads were supposed to be "lightweight" which implied
GB> low overhead, so I can have a lot of threads without sucking
GB> up resources, etc.
that is a misconception. and in perl thread carry a large overhead due
to locks. multiple perl processes are actually faster.
BTW there is no need to quote my entire post. and it is better
netiquette to interlace you replies with the quoted posts.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 14 Jun 1999 16:45:20 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a thread on threads
Message-Id: <37658600@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, Greg Bartels <gbartels@xli.com> writes:
:threads were supposed to be "lightweight" which implied
:low overhead, so I can have a lot of threads without sucking
:up resources, etc.
Threads are not lightweight, least of all in Perl. Your Perl program
will probably take twice the time to run if compiled with threading than
it would otherwise. Remember also that processes in Unix are much faster
than are threads in Microsoft. Yes, that's comparing apples with apple
trees, but that's how inept Microsoft is at operating system design.
I'm afraid that threads are often a problem looking for a solution,
not the other way around.
--tom
--
"Umm, square root of two? Ouch!"
--The guy who blew a hole in the Pythagoreans' assertion that all numbers can
be represented as a ratio of two integers, so they killed him
------------------------------
Date: Mon, 14 Jun 1999 15:01:17 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Box Plots using Perl & GD?
Message-Id: <Pine.GSO.4.02A.9906141501020.6999-100000@user2.teleport.com>
On Mon, 14 Jun 1999, Snehanshu Shah wrote:
> Does anyone have a package that can generate Box Plots
> using Perl and GD?
If there's a module which does what you want, it should be listed in
the module list on CPAN. If you don't find one to your liking, you're
welcome and encouraged to submit one! :-) Hope this helps!
http://www.perl.org/CPAN/
http://www.perl.com/CPAN/
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Jun 1999 18:32:57 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: can't send large-ish udp packets?
Message-Id: <x7emjeh0py.fsf@home.sysarch.com>
followups set to misc since c.l.p is defunct and there was no module
content here.
>>>>> "NM" == Nicholas Marino <nmarino@home.com> writes:
NM> My perl script can't seem to send udp packets beyond a certain size.
NM> For example, in the following code:
NM> $fpicname = "image.gif";
NM> open(FPIC, $fpicname);
NM> binmode(FPIC);
NM> $bytesread = read(FPIC, $picdata, 8192);
NM> close(FPIC);
NM> $rc = send(TTMD, $picdata, 0, $ipaddr);
NM> If image.gif is 648 bytes, the packet is received fine at the other end.
NM> However when I attempt to send a 2236 byte image, the other end
NM> never sees the packet.
NM> I've tried calling setsockopt(SOCK, SOL_SOCK, SO_SNDBUF, 8192)
NM> thinking a larger send buffer might help, but it doesn't.
NM> Is there a limit on UDP packet size? I'm running RedHat Linux, v 5.2.
do you know anything about the tcp/ip protocol suite? why are you
sending a file using a single udp packet? what server are you sending it
to? does it expect that size packet? do you realize that udp is a
datagram protocol that does not guarantee delivery nor sequential
receipt of your data? in fact your server mey never see any data, let
alone good data. when you have answered all these questions, you will
either write a proper TFTP clone over udp or switch to using tcp which
does all of that for you.
and finally, what is your perl question?
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 14 Jun 1999 21:54:45 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: examples
Message-Id: <3772789c.9922698@enews.newsguy.com>
On Mon, 14 Jun 1999 14:36:28 -0400, "Lucas Hernandez"
<hernal@champint.com> wrote:
>Is it there an example source of cgi code for windows platform..?
>I'm trying to find out how to create a html code able to call a pearl script
Please! "Perl programs"
>under windows platform.. any help or hints will be appreciated.
>
>Lucas
>
You should use CGI.pm; the module's documentation contains examples of
its usage. If that's not enough, the module's author, Lincoln Stein,
has also published a book: Official Guide to Programming with CGI.pm.
If you are looking for complete programs, have a look at
www.cgi-resources.com, although the programs there are of varying
quality. A lot of CGI scripts will work equally well under Win9x or NT
as they would under Unix.
There are many script archives on the Web, just don't take everything
you see there as gospel, as many other people in this newsgroups will
doubtlessly tell you.
Generally, to call a Perl program from your Web browser, you can
either call it directly, like
"http://myserver.com/cgi-bin/myprogram.pl" or invoke it when you press
the submit button on an HTML form. This is more of a CGI issue, and
there are some CGI primers out there. URLs, anyone?
HTH
Marcel
------------------------------
Date: 14 Jun 1999 22:02:26 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Extracting PIDs from a 'ps aux'
Message-Id: <37657bf2$0$222@nntp1.ba.best.com>
John Jones <jjones@paracom.com> wrote:
> > ps aux | grep radius
> Which should generate this sort of output:
> root 16099 0.0 0.1 404 192 p5 S 9:02AM 0:17.82
> What I need to do is generate a 'kill -9 XXXXX' command to the command line,
> where XXXXX is the pid of the processes running, which in the output is the
> second field (16099 and 16101).
> I have tried a few approaches, the most recent being something along the
> lines of:
> @grep = 'ps aux | grep radius';
You mean
@grep = `ps aux | grep radius`;
right?
> @line1 = $grep[0];
> @line2 = $grep[1]; # these two lines work, verified by a 'print
> @line1' and such.
Uh, I guess. But you're just putting a single entry into each array,
since the stuff on the right side of the equal sign in each case is
just a single element from the @grep array.
> The problem I am running into, is that when using backquotes, multiple line
> output is assigned an array as one line per element. What do I need to do
> to then extract the pids (second 'word' in each 'element') into an array
> called @pids?
You would probably want to use the split function, say like this:
@line1 = split /\s+/, $grep[0];
at which point $line1[1] is going to be your PID.
But this is clunky enough that even an idiot like me can see a cleaner
way to do it:
foreach $line (@grep) {
push @pids, (split /\s+/, $line)[1];
}
or, more tersely, using $_, and the default behavior of split:
foreach (@grep) {
push @pids, (split)[1];
}
or even more tersely, eliminating the assignment to @grep:
foreach (`ps aux | grep radius`) {
push @pids, (split)[1];
}
> I can then do a:
> > kill 9, @pids;
> at the end of the script.
Or, to take this to extremes, it can all go on one line:
foreach (`ps aux | grep radius`) { kill 9, (split)[1] }
I'm sure there are any number of obvious issues I've missed here, but
one thing I wonder about is the fact that the process ID of the grep
command you ran in the backticks will be included in the list of PIDs
to kill (since 'grep radius' will catch the 'radius' in its own ps
listing). I'm guessing that will not be a big deal, since that process
will be finished by the time the kill is issued anyway, but it's only a
guess, and I clearly don't know what I'm talking about here.
Someone with vastly more wisdom will doubtless address that point if it
merits addressing...
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: Mon, 14 Jun 1999 17:32:58 -0400
From: John Nolan <nolanj00@mh.us.sbphrd.com>
Subject: Re: Extracting PIDs from a 'ps aux'
Message-Id: <3765750A.13F89D93@mh.us.sbphrd.com>
John Jones wrote:
>
> I am needing to create a script in UNIX that can be run from a cron job.
> What this needs to do is:
>
> > ps aux | grep radius
>
There is also a module, Proc::ProcessTable, which
might be helpful for you.
--John Nolan
------------------------------
Date: Mon, 14 Jun 1999 15:18:05 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: quanlay@my-deja.com
Subject: Re: From Perl, Getting Dates from Sysbase.
Message-Id: <37657F9D.C9E478DC@mail.cor.epa.gov>
[courtesy cc to poster]
quanlay@my-deja.com wrote:
>
> I'm using sybperl to read table data from Sybase. However, when I get
> data from a date field it seems to convert it.
>
> In Sybase: 1998-12-09 08:13:43.936
> Retrieved: Dec 9 1998 8:13:43:936AM
>
> How do I stop this from converting or at least let me convert it back
> to the original form when I'm writing it to another table.
It looks like *you* are doing the actual transformation. The data
are still preserved in some sort of 'seconds since Epoch' variable,
but the way you are printing it is the issue. It looks like you
are using Sybase's native output, and Perl's localtime() in
scalar context.
If you want the date in a different format, consider working
with the results of localtime in list context, or with the
POSIX module's strftime() function, or with one of the Perl
date modules.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 14 Jun 1999 15:37:14 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Jim Barnes <jdbcpamcsd@hotmail.com>
Subject: Re: help with WIN32::OLE
Message-Id: <3765841A.6706351C@mail.cor.epa.gov>
[courtesy cc to poster]
Jim Barnes wrote:
>
> Hello -
> Today was my first day with PERL, and I have a question (actually lots of
> questions, but I'll only ask this one now). I am able to create and save an
> item in an Outlook folder (a contacts folder to be precise), however, I
> can't seem to see the value I entered in a standard outlook field. Am I not
> setting the property value correctly? Some code follows:
> [code snipped]
Well, that looks pretty good for your first day with Perl [not 'PERL'].
But, since I saw that no one had answered your question, I thought I
would intervene.
First, when you have questions that are this Win32-specific, you'll
generally do better by subscribing to the Perl-Win32-users listserv
[go to http://www.activestate.com/support/mailing_lists.htm to sub-
scribe] and submitting a question to the list.
Second, always put a -w in your first line of your program. Like this:
#!/usr/bin/perl -w
The path doesn't have to be right when working from win32, but it does
let Perl read the -w flag this way to give you helpful error messages.
If you go to Unix, the path *does* have to be right, since the unix
shell really does what you want here and actually determines what
program to run, and where it is located, and what options to use.
And if you go to a CGI script, you *might* have to have the right path,
since some webservers care while others don't.
Then add these lines right below your top line:
use strict;
use diagnostics;
The 'strict' will help you program effectively (you'll want to read
the docs on this to know why it's giving you the error messages it
does), and the 'diagnostics' will expand the error messages to something
more helpful.
Also, make sure to read the helpful e-mail you got from gnat's autobot.
It has a lot of assistance in it.
ActiveState Perl comes with an entire HTML tree of documentation in
addition to the standard Perl docs in POD format, so make sure to
look them over. Especially the ActivePerl FAQ and the core Perl FAQ.
In the ActivePerl FAQ you'll find an entire section on OLE with Perl.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 14 Jun 1999 15:35:58 -0700
From: "Trent" <trent@jps.net>
Subject: Increment counter by Decials?
Message-Id: <3765f095@news1.jps.net>
Nothing in Deja,
Nothing found in FAQ.
Is it possible to increment a counter
by anything other than 1?
if (($customerdata[25] =~ /sold/i) && ($customerdata[4] =~ /$salesperson/i)
|| ($customerdata[24] =~ /$salesperson/i)){
$saw_sold{$salesperson}++;
}
I need to increment the counters by (.5) for each match found, instead
of just by (1).
Manipulating the count after sorting the keys doesen't work in this case.
Is there a way?
Thanks for any pointers,
Trent
------------------------------
Date: 14 Jun 1999 18:54:55 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Increment counter by Decials?
Message-Id: <x74skagzpc.fsf@home.sysarch.com>
>>>>> "T" == Trent <trent@jps.net> writes:
T> Nothing in Deja,
T> Nothing found in FAQ.
T> Is it possible to increment a counter
T> by anything other than 1?
ever try looking in perlop for += ?
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 14 Jun 1999 15:15:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Mime...Perl...MS Outlook...and HTML
Message-Id: <Pine.GSO.4.02A.9906141512181.6999-100000@user2.teleport.com>
On Mon, 14 Jun 1999, Tim Clark wrote:
> the email displays in HTML fine in Outlook Express but NOT in
> microsoft outlook.
If you're following the proper protocol but some other program doesn't
cooperate, then it's the other program's fault. If you're not following
the protocol, then it's your fault. If you aren't sure about the protocol,
you should read the protocol specification. If you've read it and you're
still not sure, you should ask in a newsgroup about the protocol.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 15 Jun 1999 00:17:28 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: MS Visual SourceSafe Automation in PERL ?
Message-Id: <376e7d73.15380445@news3.ibm.net>
[mailed & posted]
Jens Rock <Jens.Rock@genius.de> wrote:
>The Opening of the database works fine, and I can set the startpoint
>of the search. Now the next lines are these:
>
> if ($item->Type == 0) {
> my $feld = $item->Items();
> ...
>
>This returns a hash with a Count entry $feld->{"Count"} (the number of
>subitems) which is correct, and an Item entry $feld->{"Item"}, which
>is IMHO a simple pointer to the Nowhere.
Did you try something like this:
use Win32::OLE qw(in);
# ...
if ($item->Type == 0) {
foreach my $VSSItem (in $item->Items) {
# ...
}
# ...
}
>In VB this object returns an array of VSSItem objects. I think this
>should work in PERL too, but how to reference the subobjects ?
You should be able to reference individual subobjects by indexing with the
name or index number:
my $vssitem = $item->Items->Item('MyItemName');
I wonder who designed the object model. Some more descriptive names sure
wouldn't hurt.
>Does this work at all ?
I think it does, you'll have to experiment.
-Jan
------------------------------
Date: Tue, 15 Jun 1999 00:17:32 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: MS Visual SourceSafe Automation in PERL ?
Message-Id: <376f7eb8.15705733@news3.ibm.net>
[mailed & posted]
Jonathan Feinberg <jdf@pobox.com> wrote:
>Jens Rock <Jens.Rock@genius.de> writes:
>
>> This returns a hash with a Count entry $feld->{"Count"} (the number of
>> subitems) which is correct, and an Item entry $feld->{"Item"}, which
>> is IMHO a simple pointer to the Nowhere.
>
>If you're trying to crack open the black box, you might try
>
> use Data::Dumper;
> print Dumper($feld);
Won't work. Win32::OLE objects are blessed references to a tied hash.
Everything is potentially translated to remote procedure calls under the
hood. People shouldn't try to crack the black box. They should consult the
documentation of the object model. :-)
-Jan
------------------------------
Date: Tue, 15 Jun 1999 00:23:11 +0200
From: Christoph Bergmann <info@java.seite.net>
Subject: Re: overwrite "print" ?
Message-Id: <376580CF.3ABC@java.seite.net>
Tom Christiansen wrote:
>
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc, info@java.seite.net writes:
> :Is "print" something special and if so is there another way
> :to overwrite it?
>
> In English, we generally use the term "override", not "overwrite". Have
> you been reading the German translation of the Camel? The translators
> chose |berschrieben not |bergehen, which while understandable, leads to
> phrasing such as yours.
yes, i read the german translation of the camel book and my bad english
leads to reverse translations like this. but most of the times most
people do understand me and thats what important (it is a little bit
like programming perl ;-)
sprichst du deutsch? weil du das mit "|berschreiben/|bergehen" weisst...
larry wall spricht ja auch deutsch, weil seine mutter aus deutschland
kam... sprechen alle perl-gurus deutsch? ist das eine wichtige grundlage
um perl weiter zu entwickeln? ;-)
"|berschreiben" is the correct expression in german, "uebergehen" means
something slightly different (to ignore somebody), the direct
translation of "override" would be "|berreiten" which is not really a
german expression (maybe it could be used when a horse rides over
somebody..... !?)
>
> Anyway, the answer is that yes, print() is special and may not be
> overridden. Here are the keywords that are not overridable:
>
> __DATA__ defined foreach m printf return
> __END__ END grep my package s
> AUTOLOAD else goto map prototype scalar
> BEGIN eval glob next q shift
> chop each INIT no qr sort
> chomp elsif if pop qq split
> DESTROY exists keys pos qw splice
> do for last push qx study
> delete format local print redo sub
>
> Note the presence of "print" in the preceding table.
>
is there a reason why it can't be overridden?
i can see a reason why it should not be possible to override "if",
"else" and this, because they control the flow of the program (but if i
think more about it, i can't see a reason there too - something goes in
and something will be returned - why not give the control to the user if
he wants to - as i know, one of the basic perl philosophies) but i can't
see a reason for "print" - it definitely behaves like any other
function, doesn't it?
and: is there any trick to simulate the overriding of "print"?
> And here are those keywords that *are* able to be overridden--at least
> in theory. In practice, some of these make no sense, like the named
> boolean operators, CORE, and a few others. The three double-underscore
> tokens are certainly odd to contemplate.
>
> CORE ge lt setservent
mhh, if i can override "CORE" then i should be able to override
"CORE::print"..!?
i tried the following (i am not very experienced with "symbol hashes"
-sorry i don't know the correct word- and hope that the following code
is not completely nonsense):
foreach $sname (keys %main::CORE::)
{
$myhash{$sname}=$main::CORE::{$sname};
}
$memcore=\%main::CORE::;
$main::CORE::=\%myhash;
$myhash::{print}=\&mprint;
sub mprint { join $,, @_ }
$x=print"blabla"."urx".(3*7) , "blubber", "jaja";
$main::CORE::=$memcore;
print "\nx=$x\n";
but -surprise!- it doesn't work.....
>
> --tom
thanks for your help,
best regards,
christoph bergmann
------------------------------
Date: 15 Jun 1999 12:13:59 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: Parellel operation
Message-Id: <slrn7mav87.7f8.hasant@borg.intern.trabas.co.id>
On Mon, 14 Jun 1999 13:58:08 GMT,
sherifhanna@my-deja.com <sherifhanna@my-deja.com> wrote:
> So if I am in process 1, and I spawn process 2 from process 1 at x
> seconds after execution, I want process 1 and process 2 to run in
> parallel.
If you can fork(),
perldoc -f fork
perldoc perlipc
also check on CPAN for modules Proc::*
HTH,
--
-hasan-
uhm, no more sig(h)
------------------------------
Date: 14 Jun 1999 22:26:02 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Perl class and constructor
Message-Id: <7k3vhq$7me$1@towncrier.cc.monash.edu.au>
David Cassell <cassell@mail.cor.epa.gov> writes:
>> Of course you can do this. But this defeats the whole idea of
>> object-oriented programming. Unlike a real OO language (like C++),
>> Perl doesn't have private and public data. You can go ahead and access
>I disagree. Perl is a real OO language if you want it. Just
>because it does things differently [i.e. better] than C++ doesn't
>make it non-OO. But maybe we should ask one of the real OO
>gurus around here.
Not claiming guru status, but I *do* know a thing or two about OO. :-)
Don't access object data directly. Just don't. It will only bring you
pain and suffering later in life. Always use a method to access an
object. Always. Even when it's blindingly obvious that you don't need
to. Maybe especially then.
The perltoot and perltootc documentation explain why, as have some of
the other posts in this thread. My forthcoming book beats the same
drum very hard and gives numerous examples of what can go wrong when
you don't use the appropriate (method-based) interface to OO data.
As to the question: can you return something other than the raw hash
reference, and thereby prevent direct access: the answer is "yes". In
fact, there are several good options. perltoot describes the use of
subroutine references to put a protective layer around object data.
One of my papers in this year's Perl Conference ("Object Encapsulation
Made Easy") describes another two approaches to ensuring the correct
interface is used.
Perhaps the simplest solution is the Tie::SecureHash module (on the CPAN).
Instead of writing:
package MyClass;
sub new
{
bless {
name => $_[1],
rank => $_[2],
snum => $_[3],
}, ref($_[0]) || $_[0];
}
you write:
package MyClass;
use Tie::SecureHash;
sub new
{
Tie::SecureHash->new($_[0],
__name => $_[1],
__rank => $_[2],
__snum => $_[3],
);
}
The resulting object looks just like a hash, except that it's various entries
are only accessible within the package and file in which the object was
created. That means your accessor subroutines within MyClass can access the
object data directly:
package MyClass;
sub name
{
my ($self, $newval) = @_;
$self->{__name} = $newval if @_ > 1;
return $self->{__name};
}
but code outside the package can't directly access the entries:
package main;
my $obj = MyClass->new("Patton", "General", "US000001");
print $obj->{__name}; // THROWS AN EXCEPTION
The Perl Conference paper also explains how the module works.
Damian
------------------------------
Date: 14 Jun 1999 16:46:35 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl class and constructor
Message-Id: <3765864b@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, damian@cs.monash.edu.au (Damian Conway) writes:
: print $obj->{__name}; // THROWS AN EXCEPTION
So does that Perl statement, but at compile time. :-)
--tom
--
signal(i, SIG_DFL); /* crunch, crunch, crunch */
--Larry Wall in doarg.c from the perl source code
------------------------------
Date: Mon, 14 Jun 1999 15:30:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl tuning/speed question: all subsets of a set of length k -- keeping the inital order
Message-Id: <MPG.11cf2252eef9cbf0989bde@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <37654531.82D5878C@epfl.ch> on Mon, 14 Jun 1999 20:08:49
+0200, Armin S. A. Roehrl <Armin.Roehrl@epfl.ch> says...
> I got some problem, and I wonder how close to the speed of C I can get
> with the following problem. I appreciate all your input a lot.
I have a solution, not tuned for speed, and certainly not compared to
the speed of C.
> Given an array @file, which looks sth. like
> @file=("This", "is","a", "sample", "and", "nothing", "else")
> On average @file has some 100 to 10 000 items.
>
> k is an integer between 1 and 25.
> I want all ordered subsets of @file, of length k.
> (e.g. keep the original order of the words)
> So if k=2, e.g. the result would ne
> This is
> This a
> This sample
> This and
> This nothing
> This else
> is a
> is sample
> is and
> .... etc. ..
> nothing else
#!/usr/local/bin/perl -w
use strict;
my @file = qw(This is a sample and nothing else);
print map "@file[@$_]\n" => combs(2, scalar @file);
# Return an ordered list of the ordered combinations of $k
# integers out of $n integers, starting from 0.
sub combs {
my ($k, $n) = (shift, shift);
my @a = @_ ? @_ : map [ $_ ] => 0 .. $n - $k;
$k < 1 ? () : $k == 1 ? @a :
combs($k - 1, $n,
map { my $ref = $_; map [ @$ref, $_ ] =>
$ref->[-1] + 1 .. $n - 1 } @a);
}
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 15 Jun 1999 12:13:57 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: pipe question
Message-Id: <slrn7mask8.7f8.hasant@borg.intern.trabas.co.id>
On Wed, 9 Jun 1999 13:10:53 +0500, Faisal Nasim <swiftkid@bigfoot.com> wrote:
> Is it possible that I call any application by pipe and some
> text to it (via pipe) and read its output to stdout in a variable?
Yes.
manpage: perlop, perlipc, perlfunc ( open() fuction )
HTH,
--
-hasan-
uhm, no more sig(h)
------------------------------
Date: 14 Jun 1999 18:47:27 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Q: listing all currently installed modules
Message-Id: <x7bteih01s.fsf@home.sysarch.com>
>>>>> "u0" == umask 077 <serge@panix.com> writes:
u0> Hi there!
u0> How can I get a list of all Perl modules installed on a particular
u0> machine? I have Perl 5.004_04 on HP-UX 10.20 and need to submit a
u0> list of Perl modules to our S/A so that he can install exactly
u0> the same set on another machine. Seeing module version numbers
u0> in the installed modules list would be a great help too.
check out the pmtools written by tom c. find them at www.perl.com or
search dejanews for the url in this group.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 14 Jun 1999 20:29:35 GMT
From: bing-du@tamu.edu
Subject: search entries whose attribute name start with special character?
Message-Id: <7k3on1$2rk$1@nnrp1.deja.com>
Hello there,
I use Perl 5.005 to do LDAP programming.
The 'cn' of several of the directory entries start with "*". How should
I create a filter for searching these entry?
$filter = "(cn=**)";
or $filter = "(cn=\**)" ....
Note: filter's format $filter = "(...)"
'cn' is a system defined attribute name.
Any idea?
Thanks in advance for your help.
Bing
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 14 Jun 1999 21:54:44 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: Sorting Arrays of Arrays, Thanks! (Completed script included)
Message-Id: <377172f4.8474535@enews.newsguy.com>
On Mon, 14 Jun 1999 19:16:56 GMT, dragnet@internalysis.com (Marc
Bissonnette) wrote:
I haven't been following the thread from the beginning (sorry), but I
saw the script and wanted to make a few comments.
>For anyone who's interested, the completed script follows.
>
>What it does: Reads in from a text file pipe-separated data, sorts
>alphabetically based on last name, prints an html file for each letter of the
>alphabet in a simple table format.
>
>Thanks again for everyone's help. I now know a *ton* more about sorting and
>array/hash referances than before :) :) :)
>
>#!/usr/bin/perl5
#!/usr/bin/perl5 -w
use strict;
>require 'cgi-lib.pl';
use CGI qw(:standard);
CGI.pm is the successor of cgi-lib.pl and is superior, IMHO.
>$indata="icd.txt";
my $indata ... etc.
use strict; (see above) requires you to define variable names, but
this is A Good Thing when it comes to typos in those names.
>open (DATA, $indata) || &CgiError("Unable to open database for reading
>$indata");
$! contains the error message, so you should output that as well in
case of an error.
>my (%data, @names, $hash, $line, $data, @printed, $temp, $blarg);
>
>while (<DATA>) {
I may be wrong here, but is it a good idea to call the filehandle
DATA? I thought that had a special meaning.
> chop $_;
chop operates on $_ by default, so you could just say:
chop;
But chop removes the last character indiscriminatingly. It maybe safer
to use chomp, which only removes the line ending (or whatever is in
the input record separator).
> my @line = split /\|/;
> $blarg="$line[1]"."$line[0]";
$blarg = "$line[1]$line[0]";
> $data{$blarg} = {
> fname => $line[0],
> lname => $line[1],
> title => $line[2],
> company => $line[3],
> address1 => $line[4],
> address2 => $line[5],
> city => $line[6],
> province => $line[7],
> postal => $line[8],
> country => $line[9],
> work_phone=> $line[10],
> work_fax => $line[11],
> email => $line[12],
Isn't there a more elegant way? Anyone?
> };
>
> push @names, $blarg;
>
>}
>
>my ($last_letter, @printed, $temp);
>
>$last_letter eq 'a';
This line confuses me. Should it be an assignment?
>
>foreach (@names) {
> $temp=(substr $_, 0, 1);
Should probably read
$temp = substr($_,0,1);
> $temp=~ tr/A-Z/a-z/;
> if ($temp ne $last_letter) {
> $last_letter = $temp;
> push @$temp, $_;
Shouldn't you use a hash instead of this variable-constructing thing?
>
> } else {
> push @$temp, $_;
> }
>}
Sorry, but I don't get what the $last_letter is for. You remember the
last letter, but don't use it anywhere, since you do the push command
regardless of whether the if-condition comes true or not.
>
>@printed =
>('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t
>','u','v','w','x','y','z');
@printed = ('a'..'z');
>
>foreach (@printed) {
Or rather, foreach ('a'..'z') {
then there is no need for @printed at all.
> $writefile="../members/"."$_".".htm";
$writefile = "../members/$_.htm";
> open (WPUBLISH, ">>$writefile") || die "Couldnt open ";
open (WPUBLISH, ">>$writefile") || &CgiError "Couldn't open
$writefile: $!";
>print WPUBLISH<<EOF;
><!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
><html>
><head>
>
>(bunch of HTML header stuff here)
>
><TABLE BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\">
>EOF
>
> foreach (@$_) {
>print WPUBLISH<<EOF;
I'm not sure, does this need a space between the filehandle and the
"<<"?
><TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>First Name</TD>
><TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{fname}</TD></TR>
> [deletia]
><TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Email</TD>
><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><A
>HREF=\"mailto:$data{$_}{email}\">$data{$_}{email}</A></TD></TR>
><TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"> </TD></TR>
The whole thing is a bit ugly, IMHO. What happens if you change the
HTML layout? Then you have to go back and change the script. It might
be ok in this case, but do have a look at modules that provide the
functionality to fill in templates that contain variables. E.g.,
Text::Template, HTML::Template.
Also, within a here document you don't need to escape the double
quotes.
I'm sure you could simplfy this if you used the functions that CGI.pm
offers you.
>EOF
> }
> print WPUBLISH "</TABLE>\n</BODY>\n</HTML>";
>}
>$test="test.txt";
Huh? You assign it here but never use it. Unless it's used in
PrintHeader. Don't think so, though.
>print &PrintHeader;
>print "Done!\n";
If you have a lot of data, this could take quite a while. Hopefully
your web server request doesn't time out. If it does, you should fork,
send a message back to the client, and do the real work in the child,
but that's another story altogether.
There's probably more that could be improved here. Sorry about the
nit-picking.
HTH
Marcel
------------------------------
Date: Mon, 14 Jun 1999 15:31:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: taint checking setuid error message
Message-Id: <Pine.GSO.4.02A.9906141526060.6999-100000@user2.teleport.com>
On Mon, 14 Jun 1999, John wrote:
> I'm running perl v4
When that version of Perl was current, OJ Simpson was best known for being
a Heisman trophy winner. He still can't seem to find the real killer, but
you can (and should) find the real Perl.
http://www.cpan.org/
There are even CERT advisories telling why such old software isn't safe to
use. Please upgrade.
> (actually ingperl v4).
Well, you can probably do whatever it is that was special about ingperl
with a module (a database module, perhaps?). And your code will be more
reliable for no extra cost.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 14 Jun 1999 15:35:48 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: using perl scripts in VC++'s post-build step
Message-Id: <Pine.GSO.4.02A.9906141532170.6999-100000@user2.teleport.com>
On Mon, 14 Jun 1999, Dominik wrote:
> > > @files = < @ARGV >;
> but it works in shell, why wouldn't work from VC++?
It still "works", but it's not doing what you thought it was doing, and it
never really was.
As a general rule, don't use a feature without knowing what it is. Remeber
the urban legend of the "broken cupholder" on the PC? This is the same
thing, in a way.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Jun 1999 15:02:30 PST
From: Neil <neil@pacifier.com>
Subject: What can and should not be done in Perl
Message-Id: <37657bf6.0@news.pacifier.com>
I am interested in hearing what things -- small and large -- that people have done in Perl. And I am
interested in what things should not be done in Perl and why. Thank you.
Neil
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5994
**************************************