[19504] in Perl-Users-Digest
Perl-Users Digest, Issue: 1699 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 5 14:11:34 2001
Date: Wed, 5 Sep 2001 11:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999713413-v10-i1699@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 5 Sep 2001 Volume: 10 Number: 1699
Today's topics:
Multiple recipients to SMTP subroutine not working (Bryce Pursley)
Need libnet-1.0704.tar.gz installed, will pay. <jim@perlservices.com>
Newbie question re system() <scott@here.com>
Re: Newbie question re system() <peb@bms.umist.ac.uk>
Re: Newbie question re system() <scott@here.com>
Re: Newbie question re system() <mbudash@sonic.net>
object & fork <Steffen.Bachmann@t-online.de>
Re: object & fork (Mark Jason Dominus)
Re: Open 2 exes from Perl <nospam-abuse@ilyaz.org>
Re: OT: Re: Recommendations for a PERL editor (Jonadab the Unsightly One)
Re: Perl Commands Not Working (Helgi Briem)
Re: Perl Commands Not Working <Steffen.Bachmann@t-online.de>
perl regex to GNU C regex Gordon.Haverland@gov.ab.ca
perl training <bcaligari@fireforged.com>
Re: perl training (Malcolm Dew-Jones)
Re: perl training (Randal L. Schwartz)
Re: references, slices, voodoo <stumo@bigfoot.com>
Re: references, slices, voodoo <bart.lateur@skynet.be>
Re: Shell Scripts vs. Perl Scripts (Tad McClellan)
Re: Small Program - Delete douplicates in list <Laocoon@eudoramail.com>
Speedup by using a hash instead of grep <paul.johnston@dsvr.co.uk>
Re: Speedup by using a hash instead of grep (Rafael Garcia-Suarez)
Re: tr/// Problem (Tad McClellan)
Re: Undef'ing multiple variables <h.m.brand@hccnet.nl>
Re: Undef'ing multiple variables <Tassilo.Parseval@post.rwth-aachen.de>
Re: Undef'ing multiple variables <wuerz@yahoo.com>
Re: Undef'ing multiple variables (Mark Jason Dominus)
Re: Undef'ing multiple variables <Tassilo.Parseval@post.rwth-aachen.de>
Re: Win32 process list <john.pataki@sdrc.com>
Re: Win32 Socket Programming <lhswartw@ichips.intel.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 05 Sep 2001 16:31:56 GMT
From: hbpursle@duke-energy.com (Bryce Pursley)
Subject: Multiple recipients to SMTP subroutine not working
Message-Id: <3b96518d.17959544@news.infoave.net>
I've played around with this for way to long now so I'm asking for
help.
I need to send several reports, each with different distribution
lists, using SMTP. I have attempted to create a subroutine so I can
easily pass the necessary info for each report and distribution list
to it for the actual processing. The part that doesn't work is where
I try to pass the multiple email addresses to the subroutine. It
seems like the "smtp->recipient" statement doesn't see the individual
addresses. What am I doing wrong? If I'm going about this all wrong
to begin with please feel free to point me in the right direction and
thanks.
Bryce Pursley
#!/usr/bin/perl -w
use strict;
use Net::SMTP; # module to allow SMTP functions
###############################################################################
# Set up global variables
###############################################################################
my $subject;
my $recipients;
my $file1;
my $hbp = "hbp\@domain.com";
my $bph = "bph\@domain.com";
#==========================================================================
#==========================================================================
my $smtp = Net::SMTP->new('mysmtpsrvr.domain.com');
$file1 = "test.txt";
$subject = "Test Subject Line";
my @recipients = ($hbp,$bph);
sendsmtp ($file1, $subject, \@recipients);
$smtp->dataend();
$smtp->quit;
sub sendsmtp
{
my $file = shift;
my $subject = shift;
my $arrayref = shift;
my $recipients = (join ', ', @$arrayref);
$smtp->mail("Bryce Pursley <hbpursle\@duke-energy.com>");
if ($smtp->recipient($recipients)) {
print "Success with recipients.\n";
}
else
{
print "Recipients failed - \n";
}
$smtp->data();
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("To: $hbp, $bph\n");
$smtp->datasend("From: My Test Reports
<hbpursle\@duke-power.com>\n");
open TEST, "$file";
while (<TEST>) {
$smtp->datasend("$_");
}
close TEST;
}
------------------------------
Date: Wed, 5 Sep 2001 11:19:37 -0400
From: "Jim Melanson" <jim@perlservices.com>
Subject: Need libnet-1.0704.tar.gz installed, will pay.
Message-Id: <vnrl7.1966$fD2.74027@localhost>
Need someone who can install libnet-1.0704.tar.gz (the Net::* bundle) on a
virtual server (UNIX, bsdos). Will pay. Please respond to
jim@perlservices.com with your fee. I've tried myself and can't properly
modify the MakeFile according to the virtual hosts instructions.
Best Wishes,
Jim Melanson
--
President & Founder
Perl Services
www.perlservices.net
Director of Programming,
Robinson Internet Solutions
www.robinsoninternet.com
Founder of Charity Ware, 1997
www.charityware.ws
Owner and Developer
IconLink - Desktop to Website Integration
www.iconlink.ca
International Who's Who
of Information Technology
Member since 2000
jim@perlservices.net
jim@robinsoninternet.com
jim@charityware.ws
jim@iconlink.ca
ICQ# 116084898
1-877-751-5900 North America
1-760-249-3676 International
1-208-694-1613 FAX
"Do or do not. There is no try."
--- Yoda
===========================
"To do is to be" - Descartes
"To be is to do" - Voltaire
"Do be do be do" - Sinatra
------------------------------
Date: Wed, 05 Sep 2001 10:22:56 -0400
From: Scott <scott@here.com>
Subject: Newbie question re system()
Message-Id: <t9dcptcqlek766r89aca2gd80rmobsbp1u@4ax.com>
Trying to figure out how to assign the ouput from a system command to
a string variable. Simply put, I want to run the df -k command on the
system (or any other system command) and have the text output be
assigned to a string... Sort of like:
system("df -k") > $my_string;
(I know this doesn't work though)
Thanks for help.
-Scott
---< This article was posted through www.newzpig.com >---
------------------------------
Date: Wed, 05 Sep 2001 15:30:40 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Newbie question re system()
Message-Id: <3B963710.538C1E6@bms.umist.ac.uk>
Scott wrote:
>
> Trying to figure out how to assign the ouput from a system command to
> a string variable. Simply put, I want to run the df -k command on the
> system (or any other system command) and have the text output be
> assigned to a string... Sort of like:
> system("df -k") > $my_string;
> (I know this doesn't work though)
Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq8.pod
Why can't I get the output of a command with system()?
You're confusing the purpose of system() and backticks
(``). system() runs a command and returns exit status
information (as a 16 bit value: the low 7 bits are the
signal the process died from, if any, and the high 8 bits
are the actual exit value). Backticks (``) run a command
and return what it sent to STDOUT.
$exit_status = system("mail-users");
$output_string = `ls`;
HTH
Paul
------------------------------
Date: Wed, 05 Sep 2001 10:26:31 -0400
From: Scott <scott@here.com>
Subject: Re: Newbie question re system()
Message-Id: <nedcptsrtk6d0sb8t503310l137j6bg11n@4ax.com>
Ehhh, pehaps I found the answer.
$my_string = `df -k`;
So simple.. I spent an hour looking for the answer, then found it 15
seconds after I post to the group! :-P
On Wed, 05 Sep 2001 10:22:56 -0400, Scott <scott@here.com> wrote:
>Trying to figure out how to assign the ouput from a system command to
>a string variable. Simply put, I want to run the df -k command on the
>system (or any other system command) and have the text output be
>assigned to a string... Sort of like:
>system("df -k") > $my_string;
>(I know this doesn't work though)
>
>Thanks for help.
>-Scott
>
>---< This article was posted through www.newzpig.com >---
---< This article was posted through www.newzpig.com >---
------------------------------
Date: Wed, 05 Sep 2001 17:44:06 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Newbie question re system()
Message-Id: <mbudash-F46DE3.10440905092001@news.sonic.net>
In article <t9dcptcqlek766r89aca2gd80rmobsbp1u@4ax.com>, Scott
<scott@here.com> wrote:
> Trying to figure out how to assign the ouput from a system command to
> a string variable. Simply put, I want to run the df -k command on the
> system (or any other system command) and have the text output be
> assigned to a string... Sort of like:
> system("df -k") > $my_string;
> (I know this doesn't work though)
>
perldoc -f system
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 05 Sep 2001 20:01:41 +0200
From: Steffen Bachmann <Steffen.Bachmann@t-online.de>
Subject: object & fork
Message-Id: <3B966885.857BFBAC@t-online.de>
Hi Group,
I need your help with an object that forks and looses parameters.
The purpose is to execute commands in a multithredded way.
Here is my script:
As first the module:
###################################################################
package myProcess;
sub new{
my $class = shift;
my $self = {};
$self = {'result' => '?'};
bless($self, $class);
};
sub start{
my ($self,$cmd) = @_;
$SIG{'CHLD'} = sub{wait;};
$self->{'pid'} = fork();
if(!defined $self->{'pid'}){
print "Can't fork: $!\n";
exit(0);
}elsif($self->{'pid'}){
return($self->{'pid'});
}else{
$self->{'result'} = `$cmd`;
exit(0);
};
};
sub result{
my $self = shift;
my $r = $self->{'result'};
return($r);
};
sub cleanup{
my $self = shift;
my $r = $self->{'pid'};
kill('SIGTERM',$self->{'pid'});
delete $self->{'pid'};
return($r);
};
1;
#################################################################
Now the script to test it:
##################################################################
!/usr/bin/perl -w
if($0 =~ /^(.+\/).+$/){$path = $1;}else{$path = `pwd`;};
push(@INC,$path);
use myProcess;
$cmd = 'pwd';
$p = myProcess -> new();
$pid = $p->start($cmd);
$res = $p->result();
$delpid = $p->cleanup();
print "Object Reference: $p\n";
print "Child created: $pid\n";
print "Result:\n$res\n";
print "Child killed: $delpid\n";
##############################################################
And this is the output:
##############################################################
Object Reference: myProcess=HASH(0x80f37f0)
Child created: 478
Result:
?
Child killed: 478
##############################################################
As you can see, the assignment of the process-id works (in myProcess.pm
start-method), also the assignment of the '?' as result is working ( in
myProcess.pm new-method) but the assignment of the command output
doesn't work at all (in myProcess.pm start-method). I also checke the
hash reference ($self) in all methods, and it's really the same.
What's wrong here?
Thanks for help
Steffen Bachmann
------------------------------
Date: Wed, 05 Sep 2001 17:31:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: object & fork
Message-Id: <3b96615e.5433$10c@news.op.net>
You misunderstand fork(). fork() makes a new process which is a
*copy* of the old process. No memory is shared between the two processes.
Consider this:
my $VAR = 0;
my $pid = fork;
if ($pid == 0) {
# child
$VAR = 1;
exit;
} else {
# parent
while ($VAR == 0) {
sleep 1;
}
print "Child finished.\n";
exit;
}
Try this. It never finishes. The child sets $VAR to 1, but that is
the child's private copy of $VAR. The parent has a different $VAR,
which is always 0.
Your program has the same problem. After fork(), there are *two*
$self->{result} variables, one in the parent and one in the child.
The child sets its $self->{result} and then exits, and its memory is
destroyed. The parent's $self->{result} is always '?'.
To communicate between two processes after fork(), you need to use an
interprocess communication mechanism. For example, you may use a
'shared memory segment', which is managed by the shmget, smhctl,
shmread, and shmwrite functions, or you can get the IPC::Shareable
module from CPAN, which provides a simpler interface.
Another thing you can do is have the two processes communicate with a
file. Have the child process deposit its result into a file; the
parent can see when the file appears, and pick up the result.
>As you can see, the assignment of the process-id works (in myProcess.pm
>start-method), also the assignment of the '?' as result is working ( in
>myProcess.pm new-method) but the assignment of the command output
>doesn't work at all (in myProcess.pm start-method). I also checke the
>hash reference ($self) in all methods, and it's really the same.
It's not the same. Two data objects in different prcesses are *never*
the same.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Wed, 5 Sep 2001 15:45:12 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Open 2 exes from Perl
Message-Id: <9n5ha8$2eug$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Helgi Briem
<helgi@NOSPAMdecode.is>], who wrote in article <3b949cc6.492862739@news.isholf.is>:
> >>With the exception of legacy systems, you can put 1 as the first
> >>argument to system() to start a program asyncroneously (retval is the PID).
> >I can't find any mention in the docs (perldoc -f system). Is this one of
> >those undocumented features, one that may disappear some time in the
> >near future?
>
> That's because it has nothing to do with perl.
> It is a feature of the cmd.exe shell.
B******t.
Hope this helps,
Ilya
------------------------------
Date: Wed, 05 Sep 2001 15:33:40 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: OT: Re: Recommendations for a PERL editor
Message-Id: <3b963f1d.58440164@news.bright.net>
tim@vegeta.ath.cx (Tim Hammerquist) wrote:
> One word: mutt.
Err, no. A lot of the same people who recommend mutt
also suggest pine and slrn...
[Looks at mutt website anyway.]
In particular, mutt appears to leave filtering to the mail
transfer system (procmail or whatever), which doesn't allow
for enough flexibility. I need messages from some sources
to show up in my inbox the first time I check my mail but
then be moved to certain folders when I close my client.
I need certain kinds of messages to be highlighted in
certain colours based on the content of the headers and
displayed that way in the message list. I need messages
from some sources to be filtered from my inbox to another
folder only after I've read them, or only after I've
replied to them, or only if I've tagged them with a
certain colour. (Admittedly, this last feature only
has been in Pegasus since very recently (version 4), but
now that I have it, I'm not letting it go.) I need
messages from myself that come back over majordomos to
be marked as read. The list of my filtering needs goes
on and on... and with version 4, Pegasus now handles
them all. (Well, all the ones that aren't AI-complete.)
regexp searching would be nice, but it's not as valuable
as the filtering capabilities. And, if I need to, I can
grep my pmail folders from outside the mail client.
(pmail's internal searching is almost always sufficient,
however. I've only resorted to searching the folders
externally perhaps a dozen times since 1995. I use the
filtering capabilities every time I receive mail.)
*If* I were going to switch from Pegasus, it would have
to be to Gnus, that's the only other thing with all the
features I need. Problem is, Gnus is a serious pain to
get configured, not to mention learning to use it. I
want to learn to use Gnus for usenet anyway, but I'm
waiting for Emacs 21... and I wouldn't trust it with
my mail until I'd been using it for usenet for months
and *know* I understand how its storage and filtering
work.
> Forget WINE.
That's pretty much what I'm doing.
What I may end up with is a KVM and two PCs. The one I
use for Pegasus could be fairly old.
> Never got into Pegasus (though I did use
> it for a bit). Used Netscape on Win98 and Linux until I worked out
> config on mutt, and (with any luck) will never, ever, ever have to go
> back.
FWIW, mutt appears, from the feature list on the website, to be
so much better than NS Messenger that there's no comparison.
But it's also not a replacement for Pegasus, not for me.
- jonadab
------------------------------
Date: Wed, 05 Sep 2001 15:44:48 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Perl Commands Not Working
Message-Id: <3b964679.601850695@news.isholf.is>
On Wed, 05 Sep 2001 02:48:19 GMT, "What A Man !"
<whataman@home.com> wrote:
>Can anyone tell me why the following perl commands will not work in a
>script on my webserver?
>
>unlink
>chmod
>open
>close
>
>I've asked my webhost, and they don't know. These are running on a Linux
>server with Apache and Perl version 2.6. I have my files chmodded to
>755, but I don't think it's a permissions problem (could be wrong
>though). I'm wondering since they use SSH telnet, if that could be
>what's messing up these commands.
>
Well there are a lot of different reasons why
they might not work, i.e.
You don't have permission to ...
The file does not exist (usually the path is missing) ...
and probably other reasons.
The solution is to ask Perl to tell you why the command
failed using the built in variable $! (also known as
$OS_ERROR or $ERRNO ), using warn or die
depending on the seriousness of the error like so:
unlink $file or warn "Cannot unlink $file :$!\n";
chmod 0755, $file or die "Cannot chmod $file:$!\n";
open $file, ">$file" or die "Cannot open $file:$!\n!;
close $file or warn "Cannot close $file:#!\n";
Having no code to look at I can't be sure, but I
find it very likely that you are forgetting to add the
path to the filename. This will give you a $!
of "No such file or directory".
Regards,
Helgi Briem
Regards
------------------------------
Date: Wed, 05 Sep 2001 20:40:24 +0200
From: Steffen Bachmann <Steffen.Bachmann@t-online.de>
Subject: Re: Perl Commands Not Working
Message-Id: <3B967198.43561237@t-online.de>
"What A Man !" wrote:
>
> Can anyone tell me why the following perl commands will not work in a
> script on my webserver?
>
> unlink
> chmod
> open
> close
>
> I've asked my webhost, and they don't know. These are running on a Linux
> server with Apache and Perl version 2.6. I have my files chmodded to
> 755, but I don't think it's a permissions problem (could be wrong
> though). I'm wondering since they use SSH telnet, if that could be
> what's messing up these commands.
>
> Any ideas would really be appreciated. I've spent 3 days trying to
> figure this out.
>
> Regards,
> Dennis
Under wich user-id:group-id your web-server is running? Apache is often
running as nobody:nobody by default. So change the parameters 'User' and
'Group' within the httpd.conf file or change the access rights of the
files you want touch to the apropriate ones.
Steffen Bachmann
------------------------------
Date: Wed, 05 Sep 2001 13:28:29 GMT
From: Gordon.Haverland@gov.ab.ca
Subject: perl regex to GNU C regex
Message-Id: <3b962821.6112750@news.gov.ab.ca>
Hi,
Is there a reference somewhere, on how one can convert perl pattern
searches and matching into code in C using the GNU regex functions?
Thanks,
Gord
------------------------------
Date: Wed, 5 Sep 2001 16:48:35 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: perl training
Message-Id: <9n5dnf011t1@enews3.newsguy.com>
Is there any perl community accepted (as compared to frowned upon) online
perl training, etc?
Most 'good quality' perl training programmes, etc involve travelling and
blasphemous amounts of money. Such may be acceptable and accessible in
countries like the US or mainland europe, but there are people who would
like to be progress in their knowledge/careers but are hindered by the
economies they happen to be living in.
Schemes such as microsoft and cisco certs may be nothing more than a load of
bovine feaces but they open opportunities for people moving into IT to get
started, have something to work at, and then have something to show for the
effort.
B
------------------------------
Date: 5 Sep 2001 09:53:23 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: perl training
Message-Id: <3b965883@news.victoria.tc.ca>
B. Caligari (bcaligari@fireforged.com) wrote:
: Is there any perl community accepted (as compared to frowned upon) online
: perl training, etc?
A place to start...
google: [perl tutorial]
a name I have seen (but not read myself) might lead one to using
google: [perl tutorial savage]
--
Want to access the command line of your CGI account? Need to debug your
installed CGI scripts? Transfer and edit files right from your browser?
What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi
------------------------------
Date: 05 Sep 2001 11:04:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perl training
Message-Id: <m1g0a1bjjo.fsf@halfdome.holdit.com>
>>>>> "Malcolm" == Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> writes:
Malcolm> a name I have seen (but not read myself) might lead one to using
Malcolm> google: [perl tutorial savage]
You can skip the google part and go to
http://www.stonehenge.com/merlyn/UnixReview/
and the nearby pages. In the 137 magazine columns I've written so
far, I've covered a pretty broad base of topics. Yeah, it's not
linear, but if you've read "Learning Perl", you can eventually make
sense of all of this text.
print "Just another Perl [column] hacker,"
--
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, 5 Sep 2001 15:27:11 +0100
From: "Stuart Moore" <stumo@bigfoot.com>
Subject: Re: references, slices, voodoo
Message-Id: <UAql7.6872$sA2.373451@news2-win.server.ntlworld.com>
Jasper McCrea <jasper@guideguide.com> wrote in message
news:3B950E31.3CB06C68@guideguide.com...
> I was going to include your code, Stuart, but it seemed slightly b0rked
> ($j was out of scope in places, and when I put it in scope, the results
> were whacko).
Had too long a coding break whilst on holiday I guess <g>
Your code makes far more sense too, with mine if there were 2000 elements, it
could take a (relatively) long time to find the last one as the right random
number has to come up. (In theory, it could take for ever, which isn't the kind
of thing you'd want to see as a comment in code ;-)
Don't pretend to fully understand why the other one is as random as yours, but
I'll accept that someone does so it must be true and maybe even come back to
look at it once I've started my mathematics degree.
Cheers
------------------------------
Date: Wed, 05 Sep 2001 17:52:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: references, slices, voodoo
Message-Id: <5hpcptca2hoh2t36ktg8ma2tu5itvr54bt@4ax.com>
Jasper McCrea wrote:
>Benchmark: running mine, yate, each for at least 3 CPU seconds...
> mine: 5 wallclock secs ( 3.85 usr + 0.01 sys = 3.86 CPU) @
>18.91/s (n=73)
> yate: 6 wallclock secs ( 3.64 usr + 0.03 sys = 3.67 CPU) @
>19.89/s (n=73)
>
>was with 4000.
>
>Benchmark: running mine, yate, each for at least 3 CPU seconds...
> mine: 6 wallclock secs ( 3.77 usr + 0.00 sys = 3.77 CPU) @
>6.63/s (n=25)
> yate: 5 wallclock secs ( 3.67 usr + 0.00 sys = 3.67 CPU) @
>9.81/s (n=36)
>
>with 8000
>
>so obviously there's a crossover in speed.
Eh ,no. Yours is a bit slower all the time.
--
Bart.
------------------------------
Date: Wed, 05 Sep 2001 13:20:26 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <slrn9pc61j.v2s.tadmc@tadmc26.august.net>
[ Please do not send "stealth Cc"s. That can quickly earn you
a real *plonk*.
A stealth Cc is when you email AND post without stating
*in the body* of your message that you are doing so.
]
Heiko Wolf <wolfh@master.sm.go.dlr.de> wrote:
>> >I want to execute a bs script from a perl script.
>> ^^
>>
>> Eh? Did you mean "bash" instead?
>
>No sorry, I meant "sh" -> UNIX-newbie *plonk*
^^^^^^^
You are killfiling me because _you_ made a mistake?
You should not use terms if you do not know what they mean,
you might earn a (real) reciprocal which would affect your
ability to get answers to Perl questions in the future.
http://www.tuxedo.org/~esr/jargon/html/entry/plonk.html
>> >How can I do this? Is there a kind of "run"-command?
>>
>> perldoc -f system
>> perldoc -f qx
Those are a shorthand for "read about the 'system' and 'qx'
functions in the 'perlfunc.pod' standard Perl doc".
Whether you use perldoc, emacs, vi or a web page to access
the docs makes no difference.
Your answer is there, it is up to you to be able to access
your answer whether easy or hard.
>> perldoc -q external
That is shorthand for "search for the word 'external' in the
question text of Perl's Frequently Asked Questions".
I was trying to get you to read:
"How can I capture STDERR from an external command?"
Which outlines the 3 usual ways of running external programs,
regardless of what language the programs are written in.
>So I tried to enter those commands at the command line, and I only got
>error messages like the following:
>
>perldoc -f system
>
> Unknown option: f
If you use a Perl of merely historical interest (ie. an "old" perl)
then it will be harder to look things up in Perl's standard docs,
but it does not exempt you from looking things up nonetheless.
>Any suggestions?
Get a modern version of perl, you appear to have a really old one.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Sep 2001 16:35:15 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Small Program - Delete douplicates in list
Message-Id: <Xns9113AA277A400Laocooneudoramail@62.153.159.134>
nobull@mail.com wrote in news:u9g0a1j2ec.fsf@wcl-l.bham.ac.uk:
*snip*
> Side note on formatting - omiting the semicolon before a the closing
> brace of a block is usually only considered good style if the whole
> block is on one line.
It was all on one line :)
>
>> i'm still new (1 month) so help would be greatly appreciated.
>
> Get into good habits now: strict, warnings, meaningful variable names,
> error checking and so on an so forth.
>
Ok i will remember that but i only tried to make up something quick and
i didn't think this would really produce much errors :)
> Working without the safety devices because you are new is like saying
> "I'm new to mountain climbing, so I can't be bothered with all these
> ropes and helmets, perhaps once I've climbed a few small mountains
> I'll take the time to learn how to use them." The time you spend
> recovering from even a few 12ft falls will soon outwiegh the time you
> saved by not using the safety devices.
>
> BTW see also:
> FAQ: What's wrong with always quoting "$vars"?
> FAQ: How can I remove duplicate elements from a list or array?
>
------------------------------
Date: Wed, 05 Sep 2001 16:18:31 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Speedup by using a hash instead of grep
Message-Id: <3B964247.3E1052CB@dsvr.co.uk>
Hi,
While you could turn that into a somewhat obfuscated one-liner, a better
way to develop it is to get rid of the overhead of running grep for each
word. Instead, load the dictionary into a hash at the beginning.
open(DICT, '/usr/share/dict/words') or die("open dict: $!");
while(<DICT>)
{
chomp;
$words{$_} = 1;
}
close(DICT);
open IN, "dis" or die "nope";
while (<IN>) {
chomp;
$grepwithme = substr($_, 3);
# @output = `grep ^${grepwithme}\$ /usr/share/dict/words`;
# print "$grepwithme " unless (@output);
print "$grepwithme " unless ($words{$grepwithme});
}
Paul
------------------------------
Date: 5 Sep 2001 15:33:53 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Speedup by using a hash instead of grep
Message-Id: <slrn9pchf9.a23.rgarciasuarez@rafael.kazibao.net>
Paul Johnston wrote in comp.lang.perl.misc:
}
} While you could turn that into a somewhat obfuscated one-liner, a better
} way to develop it is to get rid of the overhead of running grep for each
} word. Instead, load the dictionary into a hash at the beginning.
The _whole_ _entire_ dictionary ? into memory ?
OK, I've posted a somewhat obfuscated one-liner, but the hash it uses
never reaches an element count bigger than the number of lines in the
file 'dis'. In short: load 'dis' in a hash first, and delete elements
from this hash while reading the dictionary.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 05 Sep 2001 13:20:28 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: tr/// Problem
Message-Id: <slrn9pc6pi.v2s.tadmc@tadmc26.august.net>
Donald Crowhurst <lb@postmaster.co.uk> wrote:
>tr/"/ /; #strip the quotes out
^^^^^
You are lying to yourself with that comment.
tr/"//d; #strip the quotes out
or
tr/"/ /; #replace the quotes with spaces
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 05 Sep 2001 15:29:01 +0200
From: "H. Merijn Brand" <h.m.brand@hccnet.nl>
To: comp.lang.perl.misc
Subject: Re: Undef'ing multiple variables
Message-Id: <Xns91139D8243AC4Merijn@192.0.1.90>
damian@cs.monash.edu.au (Damian Conway) wrote in news:9n4q4a$e2a$1
@towncrier.cc.monash.edu.au:
> Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
>
> >> So is there, or isn't there, a way to undef multiple variables
> >> at once?
>
> > Don't know any such built-in function. You can do:
>
> > map { undef $_ } ($a, $b, @c);
>
> Some people don't like to use C<map> in a void context.
> An alternative would be:
>
> undef $_ for $a, $b, @c;
what's wrong with
($a, $b, @c) = ();
--
H.Merijn Brand Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.7.1 & 628 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
------------------------------
Date: Wed, 05 Sep 2001 18:49:01 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <3B96577D.5030900@post.rwth-aachen.de>
Rafael Garcia-Suarez wrote:
> Damian Conway wrote in comp.lang.perl.misc:
> } Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
> } > map { undef $_ } ($a, $b, @c);
> }
> } Some people don't like to use C<map> in a void context.
> } An alternative would be:
> }
> } undef $_ for $a, $b, @c;
>
> Both solutions don't undef @c; they only undef @c elements.
>
>
I don't see why they should not undef @c:
ethan@ethan:~$ perl
@a = wq(1 2 3);
undef @a;
if (! defined @a) { print 'not defined' }
^D
not definedethan@ethan:~$
So according to Perl, the array @a has been undefed.
As for the deprecation: this has been already mentioned.
But (! @a) is still true after undefing the array.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 05 Sep 2001 13:09:07 -0400
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: Undef'ing multiple variables
Message-Id: <3d61muoc.fsf@yahoo.com>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:
> Rafael Garcia-Suarez wrote:
> > Damian Conway wrote in comp.lang.perl.misc:
> >
> > } } undef $_ for $a, $b, @c;
>
> > Both solutions don't undef @c; they only undef @c elements.
>
>
> I don't see why they should not undef @c:
>
> ethan@ethan:~$ perl
> @a = wq(1 2 3);
> undef @a;
^^
> if (! defined @a) { print 'not defined' }
> ^D
> not definedethan@ethan:~$
now try the same thing with
undef $_ for @a;
and you'll see the difference. To go from @a to ($a, $b, @c) is left
as an exercise for the reader.
-mona
------------------------------
Date: Wed, 05 Sep 2001 17:08:05 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Undef'ing multiple variables
Message-Id: <3b965bf5.53b5$209@news.op.net>
In article <3B95E505.1040405@post.rwth-aachen.de>,
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>aL wrote:
>
>> Arrrghh!
>>
>> So is there, or isn't there, a way to undef multiple variables at once?
>
>Don't know any such built-in function. You can do:
>
>map { undef $_ } ($a, $b, @c);
That doesn't work either:
my ($a, $b, @c) = (1..20);
map {undef $_} ($a, $b, @c);
print "\@c still has ", scalar(@c), " elements.\n";
aL, the most correct answer to your question may be that if you need
to 'undef' a lot of variables, you are probably doing something wrong.
Normally, the best way to build the program is to declare the
variables with 'my' in the scope in which they are used. For example,
instead of this:
while (something) {
undef $a; undef $b; undef @c;
# do something with $a, $b, @c...
}
You can use this:
while (something) {
my ($a, $b, @c);
# do something with $a, $b, @c...
}
The 'my' arranges that each time the loop executes, new, fresh
versions of $a, $b, and @c are used, and they are always automatically
'undef'.
Does that help?
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Wed, 05 Sep 2001 19:38:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Undef'ing multiple variables
Message-Id: <3B9662FF.9040804@post.rwth-aachen.de>
Mona Wuerz wrote:
> now try the same thing with
>
> undef $_ for @a;
>
> and you'll see the difference. To go from @a to ($a, $b, @c) is left
> as an exercise for the reader.
Ah, shit, indeed. ($a, $b, @c) of course becomes a flat list
($a, $c, $c[0], $c[1], ...)
I totally overlooked this.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Wed, 05 Sep 2001 09:15:02 -0400
From: John Pataki <john.pataki@sdrc.com>
To: Swanthog <lhswartw@ichips.intel.com>
Subject: Re: Win32 process list
Message-Id: <3B962556.13EAC67D@sdrc.com>
Larry,
Try using the IProcess.pm module ... I can't find it on CPAN or
ActiveState, but it is available from the developer at
http://www.generation.net/~aminer/Perl/ . Also you will need the API
module installed as well. Then you can use the EnumProcesses functions
documented at
http://www.generation.net/~aminer/Perl/IProcess.html#EnumProcesses()
Hope this helps,
John
Swanthog wrote:
> Hi,
>
> Is there a way to obtain a list of running processes within my script
> without resorting to a shell command? I am running on a win2k box. The
> method I am using now that I want to get away from is this:
>
> $proc_list = `ps`;
>
> Thanks,
> Larry S.
------------------------------
Date: Wed, 5 Sep 2001 07:56:55 -0700
From: "Swanthog" <lhswartw@ichips.intel.com>
Subject: Re: Win32 Socket Programming
Message-Id: <9n5efp$9up@news.or.intel.com>
All,
It seems I have answered my own question once again. In the event that this
is interesting to anyone (which it doesn't appear to be) I'll provide an
explanation of my workaround.
Instead of configuring the socket descriptor for non-blocking operation, I
check the socket for data and then call accept when data is found waiting.
All of this is occurrs within a large loop so that the server will go back
to looking for a connection after finishing processing the prior. Example of
how this is done:
my $rin = '';
my $rout = '';
vec( $rin, fileno( SERVER), 1) = 1;
while( $not_done)
{
if( select( $rout=$rin, undef, undef, $update_interval))
{
$sd_iaddr = accept( CLIENT, SERVER);
...
}
}
Larry S.
"Swanthog" <lhswartw@ichips.intel.com> wrote in message
news:9me0se$1cg@news.or.intel.com...
> Hi,
>
> Can anyone tell me the method for configuring a Win32 tcp server so that
> accept() will not block? I've tried:
>
> $flags = fcntl( SERVER, F_GETFL, 0)
> or &err_msg_and_die("Can't get flags for socket: " .
> Win32::FormatMessage( Win32::GetLastError()));
>
> $flags = fcntl( SERVER, F_SETFL, $flags | O_NONBLOCK)
> or &err_msg_and_die("Can't set flags for socket: " .
> Win32::FormatMessage( Win32::GetLastError()));
>
> Which resulted in this error message from the compiler:
>
> Uncaught exception from user code:
> Your vendor has not defined Fcntl macro F_GETFL, used at
> H:\projects\sendem\legoRCs.pl line
> 648.
> Fcntl::AUTOLOAD() called at H:\projects\sendem\legoRCs.pl line
> 648
> main::start_server() called at H:\projects\sendem\legoRCs.pl
line
> 125
>
> Thanks,
> Larry S.
>
>
------------------------------
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 1699
***************************************