[12768] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 178 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 17 19:07:16 1999

Date: Sat, 17 Jul 1999 16:05:08 -0700 (PDT)
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, 17 Jul 1999     Volume: 9 Number: 178

Today's topics:
    Re: dbase 4 <gellyfish@gellyfish.com>
    Re: DBM problem: very weird! (Anno Siegel)
    Re: howto generate tunnel packet <gellyfish@gellyfish.com>
        Http 500 Error running CGI scripts on PWS 4.0 [win98] <pdavis@erols.com>
        Learing Perl Question: What Gives with this RegEx ??? <pdavis@erols.com>
    Re: LWP:Simple "get" command -- Is there a Javascript e <gellyfish@gellyfish.com>
        Need input on web hosting(with CGI) w/out telnet access <jmorty@my-deja.com>
        NOT operator syntax error <mark@appal.com>
    Re: NOT operator syntax error <uri@sysarch.com>
    Re: NOT operator syntax error <rra@stanford.edu>
    Re: NOT operator syntax error <aperrin@mcmahon.qal.berkeley.edu>
        Perl probs on Red Hat 5.1 <bigpun@mindspring.com>
        Problems implementing RobotUA <deep_dt@yahoo.com>
    Re: Question: optimized method for finding the maximum  <dgris@moiraine.dimensional.com>
    Re: Question: optimized method for finding the maximum  <aperrin@mcmahon.qal.berkeley.edu>
    Re: Question: optimized method for finding the maximum  <libertarian@mindspring.com.com>
    Re: Question: optimized method for finding the maximum  <aperrin@mcmahon.qal.berkeley.edu>
    Re: Remove leading zeros from a string (Alan Barclay)
    Re: sending mail with perl on WinNT/95? <rgonzalez@csus.edu>
        Sending mail with SMTP! <rgonzalez@csus.edu>
        Some more benchmark results: <libertarian@mindspring.com.com>
        subroutine in eval with broken pipe (Danny Aldham)
    Re: subroutine in eval with broken pipe <rra@stanford.edu>
    Re: Where to start with perl programming ? <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 17 Jul 1999 20:56:25 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: dbase 4
Message-Id: <7mqqlp$af$1@gellyfish.btinternet.com>

On Fri, 16 Jul 1999 08:47:17 -0700 TravisC wrote:
> I am looking for a module to convert text files to dbase (.dbf) format
> so far I haven't found anything. Any help would be greatly appreciated.
> 

There is a module that will do this - you will need DBI and DBD::XBase.
Here is a short example:


#!/usr/bin/perl -w

use strict;

use DBI;
my $dbh = DBI->connect("DBI:XBase:.") or die $DBI::errstr;

my $create_statement = <<EOQUERY;
CREATE TABLE phonebook 
(
   surname  CHAR(20),
   forename CHAR(30),
   title    CHAR(30),
   number   CHAR(15),
   location CHAR(10),
   dept     CHAR(5)
)
EOQUERY

$dbh->do($create_statement);

my $sth = $dbh->prepare("INSERT INTO phonebook VALUES (?,?,?,?,?,?)")
                                       or die $dbh->errstr();

open(PHONE,"phonebook.txt") or die "Couldnt open - $!\n";

while(<PHONE>)
{
  my ( $surname,
       $forename,
       $title,
       $number,
       $location,
       $dept ) = split /,/,$_ ;

$sth->execute($surname,
              $forename,
              $title,
              $number,
              $location,
              $dept) or die $sth->errstr();
}

close(PHONE);

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 17 Jul 1999 21:17:48 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: DBM problem: very weird!
Message-Id: <7mqrts$k57$1@lublin.zrz.tu-berlin.de>

Zeng  <zeng@haas.Berkeley.EDU> wrote in comp.lang.perl.misc:
>The following looks a simple algorithm but the %tmp is a bit complex.
>Notice I put two identical print statements in the middle? The weird
>thing, at least to me, is that those two printout for @Keys don't always
>produce the same results. The second (KEY2) always is longer if they are

[snip]

>    dbmopen %tmp,  "tmp",  0644 || die "Can't open file ";
>    dbmopen %rmp,  "rmp",  0644 || die "Can't open file ";
>
>    while (($y, $a) = each %rmp) {
>        ($n, $t, $g) = split($y);
>
>        $u = &some_subroutine;
>
>	@Keys = keys %{$tmp{$u}};
>	print "KEY1,  @Keys \n";
>	@Keys = keys %{$tmp{$u}};
>	print "KEY2,  @Keys \n";

Well, since %tmp is tied to a file $tmp{$u} can't be a regular hash
reference.  But you treat it as a hashref in %{$tmp{$u}}, which means
it it resolved as a symbolic reference and can point to just about
anything.  Since we don't know what $tmp{$u} contains we are left to
speculation, but one remote possibility is that it contains the name
of the symbol table where @Keys resides.  In that case, the difference
you observe would have to be expected.

Anno


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

Date: 17 Jul 1999 21:49:19 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: howto generate tunnel packet
Message-Id: <7mqtov$bg$1@gellyfish.btinternet.com>

On Sat, 17 Jul 1999 15:28:51 +0000 Joseph Mack wrote:
> Is it possible/not_possible or how do I generate
> a tunnel/IPIP/encapulated packet on machine A that
> has source=A, dest=C and send it out eth0 on A to machine B?
> 

There *are* modules that will enable you to write programs that do this
but you are going to have to do most of the work yourself ... look at the
Net::* modules again.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 17 Jul 1999 19:00:58 -0400
From: "Preston Davis" <pdavis@erols.com>
Subject: Http 500 Error running CGI scripts on PWS 4.0 [win98]
Message-Id: <7mr1vr$g8j$1@autumn.news.rcn.net>

Greetings,

Getting a wierd error [http 500 ] message when calling a cgi script
located in cgi-bin directory of root web. I'm on win98, Personal
Web Server 4.0.. Note** My web server [advanced properties] states
that "read | scripts | execute" permission all enabled!?! What gives?

Any help would be greatly appreciated!
Thanks in advance, Preston

The html [ form portion only]:

=======================
<form action="cgi-bin/hello.cgi" name="form1">
<p>Welcome to the STI Log-in Page</p>
<table bgcolor="tan">
<tr>
<td>Name:</td><td colspan="2"><input type="text" name="name" value=" "
size="20" maxlength="20"></td>
</tr>
<tr>
<td>Password:</td><td><input type="password" name="password" size="7"
maxlength="7"></td><td><input type="submit" name="hello_pl" value="submit"
width="20" width="10"></td>
</tr>
</table>
</form>
=======================

The cgi script [ in perl ]

#!/usr/bin/perl
print "Content-type:text/html\n\n";

print "<html>\n";
print "<title>testing perl</title>\n";
print "<style type='text/css'>\n";
print "<!-- p{font-family:verdana;font-size:12pt} -->\n";
print "</style>\n";
print "<body bgcolor=#000000><p><font color='green'>this is a
test</font></p></body>\n";
print "</html>\n";

=========================

any clues would be extremely helpful




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

Date: Sat, 17 Jul 1999 17:54:41 -0400
From: "Preston Davis" <pdavis@erols.com>
Subject: Learing Perl Question: What Gives with this RegEx ???
Message-Id: <7mqucq$jvp$1@autumn.news.rcn.net>

Greeting Perl Wizards,

Tis I, the GreenHorn, scratchin my head, swattin flies, and
perplexed. More issues with "Learning Perl [ Schwartz]" book.

This time concerning the regular expresion example [below],
If I enter Randall [**note two "L"'s] i get thrown into some
loop which I am unable to break out of....

Question 1.)  What's wrong with this regular expression!?! I cannot find it
:-(
Question 2.)  How can I break out of a runaway process such as what results
from
                       entering "Randall"?

Here is the code..Thanks in advance, Preston :-}
===========================================================
#!/usr/bin/perl
%words =qw(
fred camel
barney llama
betty alpaca
wilma alpaca
);
print "what is your name?";
$name=<STDIN>;
chomp ($name);
if ($name =~
al\b/i){    
    print "Hello randal, how good of you to be here!\n";
} else {      # open not randall
    print "Hello $name!\n";   # Default greeting
    $secretWord = $words{$name};  # get the secret word
    if ($secretWord eq "") {   # Open is null
        $secretWord = "groucho";  # ????
        }
    print "What is the secret word?";
    $guess = <STDIN>;
    chomp $guess;
    while ($guess ne $secretWord) {
      print "Wrong, try again. What is the secret word? ";
      $guess = <STDIN>;
      chomp $guess;
   }
}
==================================================================






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

Date: 17 Jul 1999 21:28:39 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: LWP:Simple "get" command -- Is there a Javascript equivalent
Message-Id: <7mqsi7$al$1@gellyfish.btinternet.com>

On Sat, 17 Jul 1999 11:18:42 -0400 Ken Mead wrote:
> I usually use Perl and CGI to fetch a document via WWW and include parts
> of it in another HTML file.  I was just wondering if anyone knew of a
> Javascript (or Java)  way of doing the same thing?  I need to do this on
> a server where I don't have CGI capabilities.  Thanks.
> 

I would recommend asking this question in the appropriate group.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 17 Jul 1999 22:17:21 GMT
From: jmorty <jmorty@my-deja.com>
Subject: Need input on web hosting(with CGI) w/out telnet access
Message-Id: <7mqvda$kf9$1@nnrp1.deja.com>

Hello All,
Hopefuly someone out there can help me with this one.
I have spent sometime looking at the cheaper alternatives for web
hosting (allowing custom CGI's) and have found several cheap or even
free services that will meet my needs.  However, none of these solutions
offers telnet access.  I am used to telnet for cgi script installing and
"debugging".  How do you accomplish this when using web hosts that only
allow FTP access?

Thanks in advance,
Jan
P.S. I know I could install run tests on my computer, but a lot of times
I need to debug on the server because of differences in directory names,
libraries, etc.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Sat, 17 Jul 1999 17:03:08 -0500
From: Mark Bannister <mark@appal.com>
Subject: NOT operator syntax error
Message-Id: <3790FD9C.6ECB9607@appal.com>

perl version 5.003_07
How come most the lines I have with NOT operators no longer work?
I get a syntax error on the lines they are on.  I was working on a
script, made some changes and now I get this error everywhere.  I
started from scratch and wrote just these lines:

#!/usr/bin/perl -w
$mydir .= "/" if !("$mydir" =~ m|/$|);  # <<<<<no error here   example A

if  !($myvar) {  #<<<<<<<syntax error here    example B
 print "hi";
}

Other scripts compile just fine.  I included example A because in my
other script this was what was causing the error.  It no longer seems to
be a problem.  Just example B gives a:   syntax error line 3, near "if
!"
I compiled it on my hosting service it got the same thing.
If I remove the ! from example B no errors occur

What obviously stupid thing am I missing here?

mark



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

Date: 17 Jul 1999 18:33:37 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: NOT operator syntax error
Message-Id: <x7hfn2j48u.fsf@home.sysarch.com>

>>>>> "MB" == Mark Bannister <mark@appal.com> writes:

  MB> #!/usr/bin/perl -w
  MB> $mydir .= "/" if !("$mydir" =~ m|/$|);  # <<<<<no error here   example A

simple statement with if modifier

  MB> if  !($myvar) {  #<<<<<<<syntax error here    example B
  MB>  print "hi";
  MB> }

if statement

  MB> What obviously stupid thing am I missing here?

read perlsyn for the correct syntax of an if statement. then you will
learn the true depths of your stupidity.

:-) in case some luser lurker couldn't tell.

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
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 17 Jul 1999 15:44:01 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: NOT operator syntax error
Message-Id: <ylr9m6nbgu.fsf@windlord.stanford.edu>

Mark Bannister <mark@appal.com> writes:

> perl version 5.003_07

Upgrade when you get a chance; that's an extremely old development
version.

> if  !($myvar) {  #<<<<<<<syntax error here    example B
>  print "hi";
> }

The full conditional expression, including negation if used, that goes
with an if statement in that form must be inside the parentheses.  This
restriction is relaxed for if statement modifiers (ones at the end of
regular statements), which is why the other statement wasn't producing an
error.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 17 Jul 1999 15:58:15 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: NOT operator syntax error
Message-Id: <37910A87.8A4B446F@mcmahon.qal.berkeley.edu>

Uri Guttman wrote:

> >>>>> "MB" == Mark Bannister <mark@appal.com> writes:
>
>   MB> $mydir .= "/" if !("$mydir" =~ m|/$|);  # <<<<<no error here   example A

Also, by the way, why the "" around $mydir? Unnecessary.--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting - aperrin@mcmahon.qal.berkeley.edu
            I'M LOOKING FOR ANOTHER EXPERIENCED ACCESS
               DEVELOPER - CONTACT ME IF INTERESTED.
        http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------




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

Date: Sat, 17 Jul 1999 18:09:04 -0400
From: "Big Poppa" <bigpun@mindspring.com>
Subject: Perl probs on Red Hat 5.1
Message-Id: <pd7k3.766$ST5.56286@typ32b.nn.bcandid.com>

Hello,

I am running Red Hat 5.1 with the Apache webserver and Perl 5.004.  The
problem is whenever I make a call the a cgi or pl from a web browser, it
tries to d/l it as a file, instead of showing it.  Any ideas?  Please email
me at bigpun@mindspring.com

Thanx
Jim




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

Date: Sat, 17 Jul 1999 23:08:31 +0000
From: blob <deep_dt@yahoo.com>
Subject: Problems implementing RobotUA
Message-Id: <37910CEF.1B43C9F4@yahoo.com>

Hi, I'm writing a web retrieval bot. The bot works well with
LWP::UserAgent, but it seems to refuse to do anything when I try to use
RbotUA instead. It could be complying witrh the robot.txt, of course,
but this does not seem to be the problem.

Does anyone know of some obvious problem that I've overlooked?

ThanX



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

Date: 17 Jul 1999 15:37:49 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <m3n1wvhs9e.fsf@moiraine.dimensional.com>

Rick Delaney <rick.delaney@home.com> writes:

> While you're at CPAN, look for the builtin module.  

I'd like to nominate builtin.pm as the worst abuse of
the namespace that I've ever seen.

dgris
-- 
A hacker is a machine that turns caffeine into code.


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

Date: Sat, 17 Jul 1999 14:29:20 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <3790F5AF.6D68FFD6@mcmahon.qal.berkeley.edu>

Larry Rosler wrote:

> Here are two trivial solutions, one as in-line code and one as a
> subroutine.

<snip>

Here are some benchmarks - including what I would probably have done in the
situation. Guess that makes me a devastatingly inefficient programmer, at least in
this instance.... I assume this is because sort() has to produce a fully-ordered
list, not just check against the currently highest value?

ap

#!/usr/local/bin/perl -w

use strict;
use Benchmark;

sub randarray {
  my $count = shift;
  my $limit = shift;
  my @output;
  while ($#output <= $count) {
    push(@output, rand($limit));
  }
  return @output;
}

sub larry1 {
  my $longest = $_[0];
  $longest < $_ and $longest = $_ for @_;
  return $longest;
}

sub max (\@) {
  my $max = $_[0][0];
  $max < $_ and $max = $_ for @{$_[0]};
  $max
}

sub larry2 {
  return max my @lengths;
}

sub usesort {
  my @sorted = sort(@_);
  return $sorted[$#sorted];
}

timethese (
  10000,
    {
     'Larry1' => sub { larry1(randarray(100,100)) } ,
     'Larry2' => sub { larry2(randarray(100,100)) },
     'UseSort' => sub { usesort(randarray(100,100)) }
    }
);

perl timemax.pl
Benchmark: timing 10000 iterations of Larry1, Larry2, UseSort...
    Larry1: 31 wallclock secs (29.53 usr +  0.00 sys = 29.53 CPU)
    Larry2: 25 wallclock secs (24.19 usr +  0.00 sys = 24.19 CPU)
   UseSort: 145 wallclock secs (138.85 usr +  0.01 sys = 138.86 CPU)


--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting - aperrin@mcmahon.qal.berkeley.edu
        http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------




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

Date: Sat, 17 Jul 1999 18:06:41 -0400
From: "Lee Clemmer" <libertarian@mindspring.com.com>
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <r87k3.12320$FD6.50936@news2.atl>

Thanks for your response.

I asked the question because I wanted to learn something. I've never
formally studied algorithms, or, for that matter, programming. Perl is a
"get it done" language for me. Your assertion that a linear scan is the most
efficient seems probable, but *I* don't *know* that it's true. Again, that's
why I asked. The "builtin" module mentioned by Rick demonstrated another
method of implementing these functions.  I would never have tried coding the
function the way you did because of my (limited) understanding of how the
expression you used is evaluated. If you can condesend, perhaps you could
explain it, as I still don't see how:

    $longest < $_ and $longest = $_ for @lengths;

provides the maximum value.
There's also a new nugget for me here with this use of 'for'. I'm sure it's
blindingly obvious to you, but the 'for' examples I've learned from don't
show it used this way, so again, I likely wouldn't have ever tried it. Now
that I've seen it, I will. (Knowing the fastest/easiest way to put screws in
wood or other material might be a problem for you if you don't know about
drills and power screwdrivers!)

Also, if I may ask, what's that lone '$max' doing in the subroutine?
>sub max (\@) {
>    my $max = $_[0][0];
>    $max < $_ and $max = $_ for @{$_[0]};
>    $max
      ^^^^^^
>}
You may be thinking, "what a neophyte!" or "What a simpleton!" but that just
*looks* wrong to me. (Because I don't comrehend the utility and function of
placing a scalar "by itself" in a block.) What does it do, and why does it
work, please?

Thanks,
Lee Clemmer

--with apologies for my lack of programming savvy




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

Date: Sat, 17 Jul 1999 15:55:06 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <379109CA.4A943309@mcmahon.qal.berkeley.edu>

Lee Clemmer wrote:

> Thanks for your response.
>     $longest < $_ and $longest = $_ for @lengths;

The trailing for creates a loop, much like (but far prettier than):

    foreach (@lengths) { }

The other part of the statement tests whether the current value of $longest
(which can change over the life of the loop) is less than the value of the
currently-being-tested element of @lengths, which is stored in $_.  Thus, on
each iteration, $longest is evaluated in relation to the current element; if
$longest is already >= that element, the rest of the line is not evaluated.

However, if $longest < $_ evaluates true, the second half of the statement is
evaluated, $longest is set to the value of the current element of @lengths, and
the loop continues.

How's that?


> Also, if I may ask, what's that lone '$max' doing in the subroutine?
>

Perl subroutines return the last-assigned value, so simply stating it is as good
as return()ing it from the sub.

> Thanks,
> Lee Clemmer
>
> --with apologies for my lack of programming savvy



--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting - aperrin@mcmahon.qal.berkeley.edu
        http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------




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

Date: 17 Jul 1999 22:10:33 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Remove leading zeros from a string
Message-Id: <932249430.301484@elaine.drink.com>

In article <slrn7ov3hj.c9j.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>The FAQ explains how to remove leading spaces. You'd think you can read
>that part of the FAQ, and figure out the difference between a space and
>a 0?

One bit.


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

Date: Sat, 17 Jul 1999 15:40:27 -0700
From: Ruben <rgonzalez@csus.edu>
To: Tony Rice <trice@americasm01.nt.com>
Subject: Re: sending mail with perl on WinNT/95?
Message-Id: <3791065B.D8FFCF77@csus.edu>

Tony Rice wrote:

> Without a "sendmail" application, how do I send mail with Perl on Win95?

I good way would be to use the SMTP protocol. That is a client application
rather than a server application, as "sendmail."

Regards,
Ruben E. Gonzalez



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

Date: Sat, 17 Jul 1999 15:37:08 -0700
From: Ruben <rgonzalez@csus.edu>
Subject: Sending mail with SMTP!
Message-Id: <37910594.955308EB@csus.edu>

Hello everyone,
    I have been going through the "Perl Cookbook", and I found what may
be a possible bug in Chapter 18 (or perhaps something I overlooked). Why
am I posting this on this news group? Please read on. At any rate here
it is:
 I wrote a script to be able to send e-mail through my ISP (a dial up
account). At any rate, I follow the recipe closely, and this is what I
wrote:
*********************************************************
#!/usr/bin/perl -w
use Mail::Mailer;
use DB_File;
use Fcntl;

eval {
$mailer = Mail::Mailer->new("smtp","mail.myisp.net");
};
if ($@)
{
        #the eval failed
        print "Couldn't send mail: $@\n";
}
else
{
        #the eval succeded
        print "The authorities have been notified.\n";
}

$mailer->open(  'From'        =>      'Cisco<ciscokid35@myisp.net>',
                             'To'            =>      'Afriend
<myfriend@anyisp.net>',
                             'Subject'    =>      'What is up?'
             );
print $mailer <<EO_SIG;
This is the body of the book.
If you can read this, it works!

Cisco
EO_SIG

close($mailer)  or die "can't close mailer: $!";

*********************************************************
Where myisp means my real ISP, and anyisp means any ISP I am trying to
send the e-mail. At any rate, the code above seems to be fine. However I
get the following error while compiling, or should I say executing:

% ./smtp_mail.pl
The authorities have been notified.
Can't use string ("From") as a HASH ref while "strict refs" in use at
/usr/lib/perl5/site_perl/5.005/Mail/Mailer.pm line 291.

I just recently upgraded to perl 5.005, and this appears to be a bug.
Has anybody experience this, or does anybody has a solution?

I am kind of new at perl, and as some of you may have found out, this is
an ongoing learning experience! Thanks again,

Sincerely,
Ruben E. Gonzalez






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

Date: Sat, 17 Jul 1999 18:30:28 -0400
From: "Lee Clemmer" <libertarian@mindspring.com.com>
Subject: Some more benchmark results:
Message-Id: <Ku7k3.12355$FD6.50905@news2.atl>

Adding my code and the use of the Statistics::Descriptive module, we find:

Benchmark: timing 10000 iterations of Larry1, Larry2, UseSort, lee1,
stat1...
    Larry1: 10 wallclock secs ( 9.70 usr +  0.00 sys =  9.70 CPU)
    Larry2:  8 wallclock secs ( 7.79 usr +  0.00 sys =  7.79 CPU)
   UseSort: 51 wallclock secs (50.83 usr +  0.02 sys = 50.85 CPU)
      lee1: 14 wallclock secs (13.65 usr +  0.00 sys = 13.65 CPU)
     stat1: 34 wallclock secs (34.03 usr +  0.00 sys = 34.03 CPU)

My original example, rife with unneeded assignments, is, we see, only a
little slower than Larry's 1st example, and not quite twice as slow as his
2nd. The Statistics module is slower than I expected, with 'sort' bringing
up the rear. The 2 examples Larry provided look extremely close to my eye,
can anyone explain (or hazard a guess) why the subroutine is faster than the
inline?

Lee

--"Curiouser and curiouser"




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

Date: 13 Jul 1999 03:16:16 GMT
From: danny@lennon.postino.com (Danny Aldham)
Subject: subroutine in eval with broken pipe
Message-Id: <7meb20$2og$1@lennon.postino.com>

X-Newsreader: TIN [version 1.2 PL2]

I am trying to get a handle on eval. I have a piece of code below that uses
eval to run a subroutine that sends mail. If the open to sendmail fails, 
I expect to get the "Couldn't Send Mail" , but I am getting the program 
quit with a broken pipe. Can subroutines be contained inside an eval block?
If so, what else am I missing?  (I am forcing the open to fail by removing
/usr/lib/sendmail when I run it.)


#!/usr/bin/perl -w
$mail_program = "/usr/lib/sendmail -t -n";
$|=1 ;
$from = "Danny" ;
$to = "test\@host.domain.com" ;
$subject = "Test of throttle"; 
$message = " Just a test. ";
	eval  {
	&send_mail($from,$to,$subject,$message) ;
	} ;
	if ($@) {
	  print "Couldn't Send Mail : $@ \n" ;
	} else {
	  print "Sent mail OK \n";
	}

sub send_mail {
    local($fromuser, $fromsmtp, $touser, $tosmtp, 
      $subject, $messagebody) = @_;
     print "Mail prog is $mail_program . \n";
    open (MAIL, "|$mail_program") or  die "Sendmail failed to open $! \n" ;
    print MAIL <<__END_OF_MAIL__;
From: $from
To: $to
Subject: $subject

$message
__END_OF_MAIL__
close (MAIL);

} #end of send_mail


--
Danny Aldham     Providing Certified Internetworking Solutions to Business
www.postino.com  E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl


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

Date: 17 Jul 1999 15:12:23 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: subroutine in eval with broken pipe
Message-Id: <ylyagflyd4.fsf@windlord.stanford.edu>

Danny Aldham <danny@lennon.postino.com> writes:

> I am trying to get a handle on eval. I have a piece of code below that
> uses eval to run a subroutine that sends mail. If the open to sendmail
> fails, I expect to get the "Couldn't Send Mail" , but I am getting the
> program quit with a broken pipe.

If you're writing code to a pipe and you want to be able to catch errors
with something other than a signal handler, always do:

        $SIG{PIPE} = 'IGNORE';

> Can subroutines be contained inside an eval block?

Yup.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 17 Jul 1999 20:37:16 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Where to start with perl programming ?
Message-Id: <7mqphs$95$1@gellyfish.btinternet.com>

On Fri, 16 Jul 1999 15:14:36 GMT arpith@hotmail.com wrote:
> 
> What webserver would you recommend ? where can I find more help ?
> 

We dont recommend servers here - I would try asking in the newsgroup
comp.infosystems.www.servers.ms-windows

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

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 V9 Issue 178
*************************************


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