[17419] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4839 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 21:15:35 2000

Date: Tue, 7 Nov 2000 18:15:23 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973649723-v9-i4839@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 7 Nov 2000     Volume: 9 Number: 4839

Today's topics:
    Re: Really stupid question: <wyzelli@yahoo.com>
    Re: Really stupid question: (Jon Ericson)
    Re: Really stupid question: (Mark-Jason Dominus)
    Re: Recursively delete directory on Windows (Mark-Jason Dominus)
    Re: Recursively delete directory on Windows <jeffp@crusoe.net>
        Send Mail - What am I missing here? <mesarch@ee.net>
    Re: Sorting hash of hashes by value <jeff@vpservices.com>
    Re: Split and clean data? (Jon Ericson)
    Re: strftime and Perl-Version problems <elephant@squirrelgroup.com>
    Re: strftime and Perl-Version problems (Jon Ericson)
    Re: Trying to subclass Net::LDAP and failing, any ideas (Marc Spitzer)
        Tutorial on strings in perl? <klimetschek@t-online.de>
    Re: Using Sendmail with CGI.pm <elephant@squirrelgroup.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 8 Nov 2000 08:55:59 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Really stupid question:
Message-Id: <E70O5.4$y5.1584@vic.nntp.telstra.net>

<coder3555@my-deja.com> wrote in message
news:8ua0s3$9jg$1@nnrp1.deja.com...
> Hello Perl Community,
>
> Can anyone tell me (a Perl newbie) what the scalar variable $? is.
>
> Say, in the context of a line of code:
>
>
>    $? == 0 || die "error...";
>
>
> It obviously checks if it has a value of zero, but where is the $?
> variable set?  Is it the return value of another instrinsic function?
>

From the documentation:

$CHILD_ERROR

$?

The status returned by the last pipe close, backtick (``) command,
successful call to wait() or waitpid(), or from the system() operator.
This is just the 16-bit status word returned by the wait() system call
(or else is made up to look like it). Thus, the exit value of the
subprocess is really ($? >> 8), and $? & 127 gives which signal, if any,
the process died from, and $? & 128 reports whether there was a core
dump. (Mnemonic: similar to sh and ksh.)
Additionally, if the h_errno variable is supported in C, its value is
returned via $? if any gethost*() function fails.

If you have installed a signal handler for SIGCHLD, the value of $? will
usually be wrong outside that handler.

Inside an END subroutine $? contains the value that is going to be given
to exit(). You can modify $? in an END subroutine to change the exit
status of your program. For example:

    END {
        $? = 1 if $? == 255;  # die would make it 255
    }
Under VMS, the pragma use vmsish 'status' makes $? reflect the actual
VMS exit status, instead of the default emulation of POSIX status.

Also see Error Indicators

check perlvar in the docs



Wyzelli

--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";






------------------------------

Date: 7 Nov 2000 23:21:32 GMT
From: Jonathan.L.Ericson@jpl.nasa.gov (Jon Ericson)
Subject: Re: Really stupid question:
Message-Id: <8FE5964A3JonathanLEricsonjpln@137.78.50.25>

coder3555@my-deja.com wrote:
>Can anyone tell me (a Perl newbie) what the scalar variable $? is.

This is documented in perlvar.  Generally it's quicker and easier to search 
the documentation (using grep, man or perldoc) then to ask the entire 
newsgroup.

Jon


------------------------------

Date: Wed, 08 Nov 2000 00:09:58 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Really stupid question:
Message-Id: <3a0899d5.7121$152@news.op.net>
Keywords: Laplace, Sylvania, Walden, submitting


In article <8ua0s3$9jg$1@nnrp1.deja.com>,  <coder3555@my-deja.com> wrot:e
>Hello Perl Community,
>
>Can anyone tell me (a Perl newbie) what the scalar variable $? is.

$? is the exit status of the last external command run by Perl.  It's
implictly set by the system() function, the qx{} and `...` operators,
and sometimes the close() operator.  It's normally zero if the last
command completed successfully, and nonzero otherwise.

Perl comes with an online manual which includes a section called
'perlvar' that has a description of every special Perl variable,
including $?.  You might try running the command

        perldoc perlvar

If that works, you should find the section about $?, which will
exaplin everything about $?  in detail.  If 'perldoc' doesn't work,
look for 'perlvar.pod' on your disk, or do a web search for it.

-- 
@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, 08 Nov 2000 00:14:01 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Recursively delete directory on Windows
Message-Id: <3a089ac8.7146$25c@news.op.net>
Keywords: Bradshaw, clothbound, lied, marital


In article <8u9p2t$2av$1@nnrp1.deja.com>,  <dave@andromeda.rutgers.edu> wrote:
>Is there a module or other simple solution
>that allows me to recursively delete
>a directory under Windows 2000?

File::Find comes standard with Perl.  Use the 'finddepth' function.
-- 
@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: Tue, 7 Nov 2000 20:38:13 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Recursively delete directory on Windows
Message-Id: <Pine.GSO.4.21.0011072037270.11113-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 7, dave@andromeda.rutgers.edu said:

>Is there a module or other simple solution
>that allows me to recursively delete
>a directory under Windows 2000?

File::Path has an rmtree() function.  It might be of some use.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



------------------------------

Date: Tue, 7 Nov 2000 19:50:21 -0500
From: "Mike Mesarch" <mesarch@ee.net>
Subject: Send Mail - What am I missing here?
Message-Id: <8ua848$4qn$1@sshuraab-i-1.production.compuserve.com>

Why does this work?  Am I missing some other piece?  I included the snipet
of code causing the problem and the entire script.  The machine in question
is a NT 4 workstation.  This is the error I get:
Error closing mail: Bad file descriptor at hoststatus.pl line 79
Thanks!
Mike
After reviewing the code if you know of something that would simplify what I
am doing please let me know...

<---------- snip ---------->
$body = "test";

$from_address = 'mmesarch@wcom.net';
$to_address = 'mmesarch@wcom.net';
$subject = 'test';

$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
  To => $to_address,
  Subject => $subject,
       })
 or die "Can't open: $!\n";
print $mailer $body  || die "Error: $!\n";
$mailer->close() || die "Error closing mail: $! $_\n";
<---------- snip ---------->

<---------- all code ---------->
use strict;
use Mail::Mailer;

my $ip;
my $status;
my %machines;
my $body;

my $mailer;

%machines = (
  "1.2.3.4"  => "a",
                "1.2.3.4" => "b",
                "1.2.3.4" => "c"
  );


foreach $ip (sort keys %machines)
{
 $status = `ping -w 50 -n 1 $ip`;
 if ($status =~ "bytes=32")
 {
  $status = `ping -w 50 -n 1 $machines{$ip}`;
  if ($status =~ "bytes=32")
  {
   $body = "Machine is alive by IP ($ip) and NetBIOS Name
($machines{$ip})\n";
   next;
  }
  $body = "Machine is alive by IP ($ip) but not NetBIOS Name
($machines{$ip})\n";
 }
 else
 {
  $status = `ping -w 50 -n 1 $machines{$ip}`;
  if ($status =~ "bytes=32")
  {
   $body = "Machine is dead by IP ($ip) but up by NetBIOS Name
($machines{$ip})\n";
   next;
  }
  $body = "$ip is dead\n";
 }
}

my $from_address = 'mmesarch@wcom.net';
my $to_address = 'mmesarch@wcom.net';
my $subject = 'host status';

#Send errors to owner
$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
  To => $to_address,
  Subject => $subject,
       })
 or die "Can't open: $!\n";
print $mailer $body  || die "Error: $!\n";
$mailer->close() || die "Error closing mail: $! $_\n";

<---------- all code ---------->




------------------------------

Date: Tue, 07 Nov 2000 15:14:40 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Sorting hash of hashes by value
Message-Id: <3A088CE0.FE16C74D@vpservices.com>

Gwyn Judd wrote:
> 
> I was shocked! How could Jeff Zucker <jeff@vpservices.com>
> say such a terrible thing:
> 
> >my %cmpd_hash;
> >while (my($country,$vals)=each %hash) {
> >    while (my($color,$num)=each %{$vals}) {
> >        $cmpd_hash{$num} = {country=>$country,color=>$color};
> >    }
> >}
>
> Of course, that only works as long as there are no duplicate number
> values. This version should guarantee unique hash keys:

Doh!  Good point.

-- 
Jeff


------------------------------

Date: 8 Nov 2000 00:33:46 GMT
From: Jonathan.L.Ericson@jpl.nasa.gov (Jon Ericson)
Subject: Re: Split and clean data?
Message-Id: <8FE5A9769JonathanLEricsonjpln@137.78.50.25>

On 05 Nov 2000, vivekvp@spliced.com (vivekvp) wrote:
>I have data in the format of:
>
>1|Name|Phone|screwed up formatted data|screwed up formatted
>data|spouse|address|date|open|
>
>
>The problem is the screwed up fields have multiple lines - but each line
>is appearing as a separate line.

Problem #1 - Can't parse records because of embeded newlines.  (I assume 
newlines are record separators and the "screwed up fields" are not quoted).

You will need to find some other way to identify records.  For instance, 
you appear to have 9 fields per record, so the first 9 fields belong to 
record 1 and the next 9 to record 2.  I would use pattern matching to 
verify fields like 'Phone'.

>I am trying to load this data into a database - but the 2 'screwed up'
>fields have odd characters in them.  How do I strip out all characters
>except text and number from those 2 fields? That inludes tabs, line
>feeds etx?

Problem #2 - Odd characters (besides the newlines) in the screwed up 
fields. 

Have you read about the tr operator documented in perlop?

What have you tried?

Jon


------------------------------

Date: Wed, 8 Nov 2000 10:32:49 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: strftime and Perl-Version problems
Message-Id: <MPG.14733c30e8aba2bb989880@localhost>

  [ posted to comp.lang.perl.misc and CCed to pelle1970@my-deja.com ]

pelle1970@my-deja.com wrote ..
>Hi everyone,
>I had posted this to alt.perl without an answer. Maybe someone here can
>comment?
>
>Hi there,
>
> I've got two (or more) LINUX-machines. Perl installations are:
> This is perl, version 5.005_03 built for i386-linux
> This is perl, version 5.004_04 built for i586-linux
>
> And I have something like this:
>   use POSIX qw(strftime);
>
>   my @mytime1 = localtime();
>   my @mytime2 = @mytime1;
>   if( $mytime1[4]==1 )
>     { $mytime1[4]=11; }  # change of year
>   else
>     { $mytime1[4]--; }
>   print "\nBareTime1: $mytime1[4] -- BareTime2: $mytime2[4]";   my
>$datestr1 = strftime("%Y%m01",@mytime1);
>   my $datestr2 = strftime("%Y%m01",@mytime2);
>   print "\nDateString1: $datestr1 -- DateString2: $datestr2";
>
> When I run this on Perl 5.004..., everythings works fine.
> But on 5.005, if mytime[4]==8 or mytime[4]==9, I always get month 10,
>that is october. Well, for mytime[4]==9 that is what I'd expect, but for
>mytime[4]==8 that is
> definately not what I expect!!!
> Every other month works fine!!! (Well, I haven't tested EVERY month,
>but a couple of them)
>
> In other words: My output is something like this:
>
> BareTime1: 8 -- BareTime2: 9
> DateString1: 20001001 -- DateString2: 20001001

ok .. to start with .. I don't know how you're getting those values - by 
artificially setting $mytime1[4] to 8 or to 9 I get the expected results 
of 20000901 and 20001001 for time1

however .. I don't really think that you know what you're doing with 
those 'if' clauses .. in the first one your comment says 'change of 
year' .. but element 4 has nothing to do with the year

I wonder if you realise that your DateString output is as simple as the 
following

  my @time = localtime;
  printf 'DateString: %d%d01' => $time[5]+1900, $time[4]+1;

works everytime .. doesn't need to import POSIX .. and seems pretty 
simple to me

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: 7 Nov 2000 23:47:58 GMT
From: Jonathan.L.Ericson@jpl.nasa.gov (Jon Ericson)
Subject: Re: strftime and Perl-Version problems
Message-Id: <8FE5A9A80JonathanLEricsonjpln@137.78.50.25>

pelle1970@my-deja.com wrote:
>I had posted this to alt.perl without an answer. Maybe someone here can
>comment?

> And I have something like this:

<snip code>

I don't think anyone wants to debug code that is only "something like"
what is causing the problem.  I suggest using strict and warnings,
posting a self-contained example that shows the problem (cut and paste
please), sample input, and expected and actual outputs.  That way others
can duplicate your problem and suggest solutions. 

Jon


------------------------------

Date: Tue, 07 Nov 2000 23:13:15 GMT
From: marc@oscar.noc.cv.net (Marc Spitzer)
Subject: Re: Trying to subclass Net::LDAP and failing, any ideas what I an doing wrong?
Message-Id: <slrn90h2b0.2af8.marc@oscar.noc.cv.net>

In article <slrn90h1eu.b6.kag@kag.citysource.com>, Kenneth Graves wrote:
>In article <slrn90gvro.2af8.marc@oscar.noc.cv.net>, Marc Spitzer wrote:
>>#use Net::LDAP;
>
>Uncomment this.  If perl has never read the Net::LDAP package, then it
>can't find its methods.
>
>--kag

Thanks,

It worked.

marc


------------------------------

Date: Wed, 8 Nov 2000 02:17:05 +0100
From: "Alex" <klimetschek@t-online.de>
Subject: Tutorial on strings in perl?
Message-Id: <8ua9is$ssb$00$1@news.t-online.com>

Hello!

Where can I find a good and comprehensive tutorial or faq for the handling
and working with strings in perl?

Thanks in advance!!!

alex




------------------------------

Date: Wed, 8 Nov 2000 10:47:13 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: Using Sendmail with CGI.pm
Message-Id: <MPG.14733f8b3db89cfe989881@localhost>

John Beckwith wrote ..
>Hi there,
>
>I am quite new to perl, but am aware that it is the best way forward, when
>dealing with CGI and web constructs.
>
>I have set up a cgi script using cgi.pm library.
>
>I would like to be able to receive the query from the previous 'query
>form' - which is currently fine and I can display the query items to the web
>page.
>
>Now I would like to (via sendmail) email the results to the webmaster
>account.
>
>Has anybody got a good procedure for this operation?

yes .. the easiest is to use one of the many mailing modules available 
from CPAN .. something like Mail::Mailer

  http://search.cpan.org/

then you can either output each CGI parameter by name - or iterate 
through them using the parameterless CGI::param call .. see the 
documentation for more information (type the following at the command 
prompt)

  perldoc CGI

for more information on the perldoc utility type

  perldoc perldoc

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4839
**************************************


home help back first fref pref prev next nref lref last post