[10049] in Perl-Users-Digest
Perl-Users Digest, Issue: 3642 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 5 09:06:12 1998
Date: Sat, 5 Sep 98 06:00:18 -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 Sat, 5 Sep 1998 Volume: 8 Number: 3642
Today's topics:
A short question <cisterni@di.unipi.it>
Re: Beginner need help with sendmail-t (j)
Config causing core dumps in threads (Roberto)
Does any one have a news gatherer script? <anands@hk.super.net>
Error message???? <sales@madm.com>
Re: Error message???? (Sam Holden)
Re: exit value lost by system? (Michael Wang)
Re: Hats off to Tom Phoenix (Ronald J Kimball)
Re: Hats off to Tom Phoenix (Chip Salzenberg)
Re: Hats off to Tom Phoenix (Michael J Gebis)
INSERT .PL in .HTML <cristo@consotech.se>
Newbie OO question <awrobinson@amoco.com>
Re: Newbie OO question (Jonathan Stowe)
Re: or vs || with open function (Ronald J Kimball)
Re: or vs || with open function (Ronald J Kimball)
Re: Parsing XML and HTML (was: Re: Better Regular Expre cicero_n@my-dejanews.com
Re: Problem with If (Ronald J Kimball)
Reading file names but not directories <mhanson@prtel.com>
Re: Reading file names but not directories (Awrobinson)
Re: Regexp to toggle a part of a string (David A. Black)
Re: trouble getting df output on remote boxes <mhc@Eng.Sun.COM>
Re: trouble getting df output on remote boxes <mhc@Eng.Sun.COM>
Re: Use Perl to sendmail: open once, send multiple time (Wotan)
Re: WE MASS E-MAIL YOUR EXCLUSIVE AD TO 900k - $99 (Jonathan Stowe)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 05 Sep 1998 11:30:53 +0200
From: Antonio Cisternino <cisterni@di.unipi.it>
Subject: A short question
Message-Id: <35F104CD.43A0AF6A@di.unipi.it>
I wrote this program (that must be stored in a file called 't'):
open(I,"<t");print<I>
There is a shortest program that print itself? I'm a novice Perl
programmer and I don't know all the required tricks?
Another question: anyone has written the shortest Perl program that
writes itself?
-- Antonio
______________________________________________________
Antonio Cisternino
WWW address: http://www.di.unipi.it/~cisterni/
E-Mail: cisterni@di.unipi.it
"Knuth mi ha insegnato le risposte. Dijkstra mi ha insegnato le
domande."
Alexander Stepanov
------------------------------
Date: Sat, 05 Sep 1998 03:48:55 GMT
From: mocat@best.com (j)
Subject: Re: Beginner need help with sendmail-t
Message-Id: <35f1b3a1.151855874@nntp.best.com>
On Fri, 4 Sep 1998 20:26:24 -0400, "Soft Science" <softsci@eagle.ca>
wrote:
>Hi:
>
>OPEN (MAIL, "|$mailprogram -t") || die "can't open $mailprogram";
>What does -t in the above line do?
Here's a real answer. "man sendmail"
kidding.
cant stand it when i see that.
the -t extracts information from the header of the mail to send it to
the correct recipient, cc's, subjects, and um i'm sure you can do
attachments with it. but i've never tried.
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL <<"EOT";
From: me@me.net
To: you@you.net
Cc: someotherguy@someguy.net
Subject: something
Just saying hi. nooch.
EOT
close(MAIL);
hope this helps!
------------------------------
Date: 5 Sep 1998 12:27:44 GMT
From: roberto@toutatis.net (Roberto)
Subject: Config causing core dumps in threads
Message-Id: <roberto-ya02408000R0509981428440001@news.euronet.nl>
In perl 5.005_2, on my Linux 2.0 Redhat 5.2, I encounter
the following problem when using Config in a thread:
#/usr/bin/perl -w
use strict;
use Config;
use Thread;
do_it(); #unthreaded
Thread->new(\&do_it)->detach; #threaded
sub do_it {
print $Config{d_alarm},"\n";
}
prints on my machine:
define
Segmentation fault (core dumped)
I found it when I was investigating core dumps using
IO::Socket, and pinpointed the problem on line 210, which says:
if($timeout) {
defined $Config{d_alarm} && defined alarm($timeout) or
$timeout = 0;
I changed that into:
if($timeout) {
defined (1 || $Config{d_alarm}) && defined alarm($timeout) or
$timeout = 0;
And then my application worked fine for the moment.
But I would prefer a neater solution.
--
roberto@toutatis.net
------------------------------
Date: Sat, 05 Sep 1998 12:26:53 +0800
From: Anand Aiyer <anands@hk.super.net>
Subject: Does any one have a news gatherer script?
Message-Id: <35F0BD8D.3A09D94C@hk.super.net>
Does any one have a news gatherer script?, if so please mail me.
Thanks,
Anand Aiyer
------------------------------
Date: Fri, 4 Sep 1998 21:00:46 -0700
From: "Doyle Johnson" <sales@madm.com>
Subject: Error message????
Message-Id: <6sr34a$lef$1@nnrp02.primenet.com>
Ok does anyone have the meaning of this......
Illegal division by zero at
/usr/local/etc/httpd/htdocs/madmzone/cgi-bin/zone/testcopy.pl line 29.
I have scoured the line but I see nothing......
This is line 29.....
copy($mzuserfiles/cgi-lib.pl, $mzusercgi/cgi-lib.pl) || die ();
------------------------------
Date: 5 Sep 1998 10:31:55 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Error message????
Message-Id: <slrn6v24or.lgq.sholden@pgrad.cs.usyd.edu.au>
On Fri, 4 Sep 1998 21:00:46 -0700, Doyle Johnson <sales@madm.com> wrote:
> Ok does anyone have the meaning of this......
>
>Illegal division by zero at
>/usr/local/etc/httpd/htdocs/madmzone/cgi-bin/zone/testcopy.pl line 29.
>
> I have scoured the line but I see nothing......
>
>This is line 29.....
>
>copy($mzuserfiles/cgi-lib.pl, $mzusercgi/cgi-lib.pl) || die ();
*^* *^*
sure looks like a division to me...
; perl -le 'print int(cgi-lib.pl)'
0
And a division by 0 as well...
Now how about :
; perl -w -le 'print cgi-lib.pl'
Unquoted string "cgi" may clash with future reserved word at -e line 1.
Unquoted string "pl" may clash with future reserved word at -e line 1.
Identifier "main::cgi" used only once: possible typo at -e line 1.
Filehandle main::cgi never opened at -e line 1.
Maybe you want to quote strings instead of performing a division, a subtraction,
and a concat on them...
But I've already been much to nice seeing you obviously haven't read the docs,
since then you would have tried -w which should have told you the answer.
In case I haven't been clear RTFM.
Sam
PS. I hope you've written copy or slurped it from a module...
------------------------------
Date: 5 Sep 1998 03:54:45 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: exit value lost by system?
Message-Id: <6sqcm5$o5j$1@news.ml.com>
>I have to be doing something foolish here but I don't see what. I have
>a perl function called by another perl function and $? doesn't contain the
>right value upon return.
The return value from the system is not the return value you
would expect from wait(2) call. [Camel book 230]. You need
to convert it to the "return value" you expect from shell. The
example code in Camel book 230 contain errors. I have a function
in Perl to do the conversion. It is part of "submit" program which
can be browsed from the URL in my signature.
--
unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog
Michael Wang, mwang@ml.com, Merrill Lynch, World Financial Center, 212-449-4414
------------------------------
Date: Sat, 5 Sep 1998 00:04:24 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Hats off to Tom Phoenix
Message-Id: <1deujjs.6whuxw14x5vk0N@bay1-104.quincy.ziplink.net>
Alastair <alastair@calliope.demon.co.uk> wrote:
> Larry Rosler <lr@hpl.hp.com> wrote:
> >
> ><SNIPPED> an outrageous, disgusting, off-topic response to someone who is
>
> Please. That was neither 'outrageous' or 'disgusting'. 'Offtopic' yes.
> Chip mentioned his religious preference first.
Chip merely mentioned his religious preference; he did not attacking
anyone else's religious preference. Daniel Adam, on the other hand,
wrote "Quite frankly, Christianity sucks."
> >Please can your bigotry, or peddle it elsewhere.
>
> No bigotry either. Atheism appears to upset you.
Larry was not upset by Daniel Adam's atheism; he was upset by the
negative comments Daniel posted regarding Christianity and other
religions.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 5 Sep 1998 04:25:50 -0400
From: chip@pobox.com (Chip Salzenberg)
Subject: Re: Hats off to Tom Phoenix
Message-Id: <6sqsie$hgn$1@cyprus.atlantic.net>
According to "Daniel Adams" <dan@fearsome.net>:
>Chip Salzenberg wrote in message <6spgbt$ghg$1@cyprus.atlantic.net>...
>>"Hence when you go making gifts of mercy, do not blow a trumpet ahead
>>of you [...]
>
>"Know ye that the friendship of the world is emnity with God? whosoever
>therefore will be a friend of the world is the enemy of God" - James 4:4
>(Its there, check it for yourself)
Heh, I could have quoted it to you from memory.
But your application of it is religious, not even tangenitally
Perlian, thus off-topic for this newsgroup.
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"I brought the atom bomb. I think it's a good time to use it." //MST3K
-> Ask me about Perl training and consulting <-
Like Perl? Want to help out? The Perl Institute: www.perl.org
------------------------------
Date: 5 Sep 1998 06:26:47 GMT
From: gebis@welsh.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Hats off to Tom Phoenix
Message-Id: <6sqlj7$dk4@mozo.cc.purdue.edu>
"Daniel Adams" <dan@fearsome.net> writes:
}If you don't like atheism, say so. Just
}spare us the sickening moral outbursts of dubious integrity.
I don't like evangelical atheism, that's for sure.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Sat, 05 Sep 1998 11:26:02 +0100
From: Cristsbal Hormazabal <cristo@consotech.se>
Subject: INSERT .PL in .HTML
Message-Id: <35F111BA.14C0@consotech.se>
Hi!
I've made a voting script and I want to show the results in
the middle of a HTML page... I need the HTML page to call
the CGI script in some way. I've tried the EXEC in SSI but
my web administrator said that that function is disabled.
Is there another way to do this than using SSI? A friend of
mine says that one can use something like:
<VOTESTART YES>56</VOTESTART>
Is it possible?
please send me your tips to: cristo@consotech.se
/Best Regards Cristo
------------------------------
Date: Fri, 04 Sep 1998 23:28:29 -0500
From: Andrew Robinson <awrobinson@amoco.com>
Subject: Newbie OO question
Message-Id: <35F0BDE9.DF6215D3@amoco.com>
I am trying to build my first package/class, mainly as a convenient way to
pass parameters around. Among the parameters is an array of subroutine
references. Using these subroutines works fine if the subroutine is defined in
the package. However, if the subroutine is defined outside the package, I get
this message:
Undefined subroutine &SubStuff::subtwo called at
trysubstuff.pl line 14.
(Sample code is included below.)
My question is, is there a way to define the list in the package and define
the subroutines elsewhere? That would be the best way for what I'm doing. I'm
hoping this falls into the category of stuff I don't know yet.
Thanks!
Andrew Robinson
#!/usr/bin/perl
# File SubStuff.pm
package SubStuff;
sub new() {
my $class = shift;
my $self = {};
bless $self, $class;
$self->initialize();
return $self;
}
sub initialize() {
my $self = shift;
$self->{'sublist'} = $self->setSubs();
}
sub setSubs() {
my @list = (
\&subzero,
\&subone,
\&subtwo
);
return \@list;
}
sub getSubs() {
my $self = shift;
return $self->{'sublist'};
}
sub subone() {
print "I am subroutine number one\n";
}
1;
#!/usr/bin/perl -w
# File trysubstuff.pl
use SubStuff;
my $s = SubStuff->new();
my $sublist = $s->getSubs();
my $subref1 = @{$sublist)[1];
&{$subref1}();
my $subref2 = @{$sublist}[2];
&($subref2}();
sub subzero() {
print "I am subroutine number zero\n";
}
sub subtwo() {
print "I am subroutine number two\n";
}
------------------------------
Date: Sat, 05 Sep 1998 11:22:38 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Newbie OO question
Message-Id: <35f10c46.1161004@news.btinternet.com>
On Fri, 04 Sep 1998 23:28:29 -0500, Andrew Robinson wrote :
>I am trying to build my first package/class, mainly as a convenient way to
>pass parameters around. Among the parameters is an array of subroutine
>references. Using these subroutines works fine if the subroutine is defined in
>the package. However, if the subroutine is defined outside the package, I get
>this message:
>
> Undefined subroutine &SubStuff::subtwo called at
> trysubstuff.pl line 14.
>
>(Sample code is included below.)
>
>My question is, is there a way to define the list in the package and define
>the subroutines elsewhere? That would be the best way for what I'm doing. I'm
>hoping this falls into the category of stuff I don't know yet.
>
As it stands you will need to define SubStuff thus:
sub setSubs() {
my @list = (
\&subzero,
\&subone,
\&main::subtwo
);
return \@list;
}
That is that you need to, for any subs external to your module, give
them an explicit package name - in the case of subtwo this is package
main:: .
/J\
--
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 5 Sep 1998 00:04:26 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: or vs || with open function
Message-Id: <1deuk8y.kr83irr1p0kvN@bay1-104.quincy.ziplink.net>
[posted and mailed]
I R A Aggie <fl_aggie@thepentagon.com> wrote:
> I'm not sure what you're asking. I think the following might shed some
> light for you...
Actually, it will probably put her further in the dark, because you've
got precedence backwards.
> open HANDLE, "some_file" || die $!; # right
Nope, that does the wrong thing.
> open(HANDLE, "some_file") or die $!; # note the use of () on open, also ok
Yes, that works.
> open HANDLE, "some_file" or die $!; # doesn't do what you think it should
Actually, it does do what is intended.
> Because of the precedence, the last example is evaluated as:
> A B
> (open HANDLE) ("some_file" or die $!)
No, it's evaluated as
(open HANDLE "some_file") or (die $!)
> because "or" is weaker than "||",
Yes, 'or' does have lower precedence than '||'. But the important
factor is that 'or' has lower precedence than 'open'. 'open' grabs
everything it can, and then the 'or' gets its turn.
> and it tries to evaluate part B as a
> conditional statement -- "some_file" or die!
> The first example gets evaluated as:
>
> (open HANDLE, "some_file) || ( die $!)
Nope, this is backwards too. The first example gets evaluated as
open HANDLE ("some_file" || die $!)
This is because '||' has higher precedence than 'open'. '||' grabs
everything it can, and then the 'open' gets its turn.
> while the second example works because the evaluation order is explicitly
> set with the use of the parens.
This also works, but only because of the parentheses:
open(HANDLE, "some_file") || die $!;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 5 Sep 1998 00:31:04 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: or vs || with open function
Message-Id: <1deux2m.1nhsn981wbicbwN@bay1-104.quincy.ziplink.net>
Andrew M. Langmead <aml@world.std.com> wrote:
> open FILE, 'filename' || die "Can't open file: $!\n";
>
> only works in perl 4. In perl 5, it evaluates "'filename' || die ..."
> first and passes the result to open as the second argument.
The precedence of '||' changed between perl4 and perl5???
~> perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the GNU General Public License, which may be found in the Perl 4.0
source kit.
~> perl
open FILE, 'filename' || die "Can't open file: $!\n";
~> perl
open(FILE, 'filename') || die "Can't open file: $!\n";
Can't open file: No such file or directory
~>
I thought not.
open FILE, 'filename' || die "Can't open file: $!\n";
does the same thing in perl4 as it does in perl5, and in neither case is
it what you'd want.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 05 Sep 1998 05:15:58 GMT
From: cicero_n@my-dejanews.com
Subject: Re: Parsing XML and HTML (was: Re: Better Regular Expressions)
Message-Id: <6sqhee$4fp$1@nnrp1.dejanews.com>
>>--------------------------
After the fiasco that has been HTML, I think most people will
be sticking to the strict XML spec and properly blowing chunks
on bad code.
--------------------------<<
I do not think so.
The cat is already out of the bag. Meaning, now that mere
mortals can and do create Web pages, anyone trying to
impose harsh new rules is guaranteed to fail miserably.
C.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sat, 5 Sep 1998 00:04:27 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Problem with If
Message-Id: <1deukpk.1gtuapv1wu4wdpN@bay1-104.quincy.ziplink.net>
plateforme <plateforme@wanadoo.fr> wrote:
> I would like to make a programm but I have a problem with a condition :
> I must say: " If find toto then save toto and words until titi in $a.
>
> A friend says me :
>
> $a = $1 if /\b(toto\b.*)/; but I dont think that is right.
That's a good start, but it leaves out the part dealing with titi.
Perhaps this will work for you:
$a = $1 if /\b(toto\b.*?)titi/;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 04 Sep 1998 23:42:22 -0500
From: Mike <mhanson@prtel.com>
Subject: Reading file names but not directories
Message-Id: <35F0C12E.59FE@prtel.com>
I have been using the following code to retrieve the name of the files
in my directory and its sub directories but how do you PREVENT it from
listing the sub directory names in their too? I just want it to list all
the file names in the directory and sub directories.
$files = "";
$dir = "$ads_dir/$INPUT{'login'}";
chdir($dir);
$ls = `ls $files`;
@ls = split(/\s+/,$ls);
------------------------------
Date: 5 Sep 1998 04:48:35 GMT
From: awrobinson@aol.com (Awrobinson)
Subject: Re: Reading file names but not directories
Message-Id: <1998090504483500.AAA20083@ladder01.news.aol.com>
# How about:
$dir = "$ads_dir/$INPUT{'login'}";
chdir($dir);
foreach $file ( glob(*) ) {
push( @filelist, $file ) if ( ! -d $file );
}
# Then if you need the list of files in a string
# the way you started out:
$files = join( " ", @filelist );
Hope this helps...
Andrew Robinson
---
Disclaimer: The opinions expressed are mine alone and do not represent the
views of America Online
------------------------------
Date: Fri, 4 Sep 1998 17:18:16 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Regexp to toggle a part of a string
Message-Id: <6spleo$qp7$1@earth.superlink.net>
Hello -
aml@world.std.com (Andrew M. Langmead) writes:
>"Joerg Wagner" <jwagner@digilog.de> writes:
>>I want to change a line of text which looks like /Status = (ON|OFF)/
>>where I want to toggle ON to OFF and vice versa. In other words I want to
>>replace ON by OFF and OFF by ON.
>>Can I do that in just _one_ regexp???
[snip]
>%toggle = ( OFF => 'ON', ON => 'OFF');
> while(<>) {
> s/(Status = )(ON|OFF)/${1}$toggle{$2}/;
> print;
>}
>If the auxiliary hash is against the "only in a regex" requirement,
>then take a look at that the /e modifier can do for you.
> s/(Status = )(ON|OFF)/$1 . (($2 eq 'ON') ? 'OFF' : 'ON')/e;
Or - just to round out the permutations -
$str =~ s/(Status: O)(N|FF)/$1${{qw(N FF FF N)}}{$2}/;
How fulfilling :-)
David Black
dblack@saturn.superlink.net
------------------------------
Date: 04 Sep 1998 22:02:05 -0700
From: Mike Coffin <mhc@Eng.Sun.COM>
Subject: Re: trouble getting df output on remote boxes
Message-Id: <8p64sundueq.fsf@Eng.Sun.COM>
Try adding "chomp($host);" before "&getdf". When you get a line from a
file with <>, the line includes the terminating newline. So the
system function passes "rsh whatever\n df -kl" to the shell, which
has the effect you have observed.
(Better yet, get the Expect package from CPAN. This gives you much
better control over processes you spawn.)
-mike
(Speaking for myself, not Sun, of course.)
Jim Loucks <jloucks@shell6.ba.best.com> writes:
> I've been trying to get perl to run the df command on remote
> machines without success. I'm new to perl. Here's what I'm doing:
>
> First I open a file with about 10 hostnames in it. Put each
> hostname in the variable "hosts" and call the getdf subroutine.
> This works so easily in ksh it can't be that difficult in perl...
> The error checking was pulled from the camel book on page 230
> where it defines the perl system function.
>
> What happens is the system function call works, but it logs me
> into the remote machine instead of executing a remote df command.
> When I exit the login, the df command executes - not what I want!
>
> Here's the part that ain't working, I'd appreciate any help:
>
> #!/usr/bin/perl
>
> open(hosts, "/usr/local/etc/hosts") || die "Cannot open /usr/local/etc/hosts\n";
>
> while (<hosts>) {
> $host=$_;
> &getdf;
> }
>
> sub getdf {
>
> @args = ("rsh $host df -kl");
> $rc = 0xffff & system @args;
> printf "system(%s) returned %#04x: \n", "@args", $rc;
> if ($rc == 0) {
> print "Ran with normal exit\n";
> }
> elsif ($rc == 0xff00) {
> print "Command failed: $!\n";
> }
> elsif ($rc > 0x80) {
> $rc >>= ~0x80;
> print "Ran with non-zero exit status $rc\n";
> else { }f ($rc print "Core dump from ";
> print "signal $rc\n";
> }
> }
------------------------------
Date: 04 Sep 1998 22:02:24 -0700
From: Mike Coffin <mhc@Eng.Sun.COM>
Subject: Re: trouble getting df output on remote boxes
Message-Id: <8p63ea7due7.fsf@Eng.Sun.COM>
Try adding "chomp($host);" before "&getdf". When you get a line from a
file with <>, the line includes the terminating newline. So the
system function passes "rsh whatever\n df -kl" to the shell, which
has the effect you have observed.
(Better yet, get the Expect package from CPAN. This gives you much
better control over processes you spawn.)
-mike
(Speaking for myself, not Sun, of course.)
Jim Loucks <jloucks@shell6.ba.best.com> writes:
> I've been trying to get perl to run the df command on remote
> machines without success. I'm new to perl. Here's what I'm doing:
>
> First I open a file with about 10 hostnames in it. Put each
> hostname in the variable "hosts" and call the getdf subroutine.
> This works so easily in ksh it can't be that difficult in perl...
> The error checking was pulled from the camel book on page 230
> where it defines the perl system function.
>
> What happens is the system function call works, but it logs me
> into the remote machine instead of executing a remote df command.
> When I exit the login, the df command executes - not what I want!
>
> Here's the part that ain't working, I'd appreciate any help:
>
> #!/usr/bin/perl
>
> open(hosts, "/usr/local/etc/hosts") || die "Cannot open /usr/local/etc/hosts\n";
>
> while (<hosts>) {
> $host=$_;
> &getdf;
> }
>
> sub getdf {
>
> @args = ("rsh $host df -kl");
> $rc = 0xffff & system @args;
> printf "system(%s) returned %#04x: \n", "@args", $rc;
> if ($rc == 0) {
> print "Ran with normal exit\n";
> }
> elsif ($rc == 0xff00) {
> print "Command failed: $!\n";
> }
> elsif ($rc > 0x80) {
> $rc >>= ~0x80;
> print "Ran with non-zero exit status $rc\n";
> else { }f ($rc print "Core dump from ";
> print "signal $rc\n";
> }
> }
------------------------------
Date: Sat, 05 Sep 1998 06:42:56 GMT
From: wotan@databasix.co (Wotan)
Subject: Re: Use Perl to sendmail: open once, send multiple times?
Message-Id: <3602dc65.16211520@nntpd.databasix.com>
For some reason on 4 Sep 1998 18:42:57 GMT,
mwang@tech.cicg.ml.com (Michael Wang) babbled:
>How do I use Perl to sendmail but I want to open once, send multiple times?
>The following example does not work. Should I directly connect to the
>sendmail port, or do mutilple open/close? Thanks.
>
> open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
> print SENDMAIL "From: <me\@me.com>\n";
> print SENDMAIL "To: <$someone\@some.site>\n";
> print SENDMAIL "$some_message\n";
> print SENDMAIL ".\n";
>#
> print SENDMAIL "From: <me\@me.com>\n";
> print SENDMAIL "To: <$someoneELSE\@some.site.ELSE>\n";
> print SENDMAIL "$some_message_ELSE\n";
> print SENDMAIL ".\n";
> close(SENDMAIL) or warn "sendmail didn't close nicely";
Its becuase you are piping each line to sendmail, instead of the
entire thing at once. As well as a slight formating error. Try
something more like this:
open(SENDMAIL, "|/usr/lib/sendmail -oi -t");
$a="From: <me\@me.com>\n";
$b="To: <$someone\@some.site>\n\n";
$c="$some_message\n";
print SENDMAIL "$a$b$c";
Just shoot me instead of pointing out my syntax errors. :-D
--
The best book on programming for the layman is
"Alice in Wonderland"; but that's because it's
the best book on anything for the layman.
------------------------------
Date: Sat, 05 Sep 1998 11:22:41 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: WE MASS E-MAIL YOUR EXCLUSIVE AD TO 900k - $99
Message-Id: <35f10f09.1867999@news.btinternet.com>
On 5 Sep 1998 05:32:16 GMT, massmail@aol.com wrote :
>
>An unregistered version of Newsgroup AutoPoster PRO
>posted this article!
Cheap skate
>---
>
>We will mass e-mail your exclusive ad to 900,000 recipients on the internet! Talk about $$$$$!
>Our satisified clients agree... mass e-mails are effective and profitable! For more info:
>
Can someone tell me why that more than 50% of spam is to do with
creating more spam ?
/J\
--
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3642
**************************************