[12769] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 179 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 18 00:07:25 1999

Date: Sat, 17 Jul 1999 21:05:07 -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: 179

Today's topics:
        Accessing a MS Access Database <tom.kralidis@ccrs.nrcanDOTgc.ca>
    Re: Accessing a MS Access Database (Sam Holden)
        Anyone intrested in joining a group? <zamors@ync.net>
    Re: Closing Web Browser Connection on Lengthy Processes bane_dewitt@my-deja.com
    Re: DBM problem: very weird! (Ronald J Kimball)
    Re: fork() in Win32 <john@dlugosz.com>
    Re: Future of Perl (Rich)
        general--stupid question from a beginner (CLTCEvans)
        HHHHEEEEEEELLLLLLPPPPPPP!!!!!!!!!! <cshelby@mindspring.com>
        MS Access ODBC Truncates <matt@mail.tca.net>
        newbie needs help! <gilmanb@vuser.union.edu>
        Perl probs! <jjanovich@mindspring.com>
    Re: Perl probs! <pmallasch@mail.starnews.com>
    Re: Question for the perl gods <john@dlugosz.com>
    Re: Question for the perl gods <john@dlugosz.com>
    Re: Question for the perl gods <uri@sysarch.com>
    Re: Question: optimized method for finding the maximum  (Larry Rosler)
    Re: Question: optimized method for finding the maximum  (Larry Rosler)
    Re: Question: optimized method for finding the maximum  <rick.delaney@home.com>
    Re: Regular expression question (Problems with parsing  (Ronald J Kimball)
    Re: Sending mail with SMTP! (Anno Siegel)
    Re: Some more benchmark results: (Larry Rosler)
        split() skyfaye@my-deja.com
    Re: split() (Sam Holden)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Sat, 17 Jul 1999 20:58:01 -0400
From: Tom Kralidis <tom.kralidis@ccrs.nrcanDOTgc.ca>
Subject: Accessing a MS Access Database
Message-Id: <37912699.18E915D3@ccrs.nrcanDOTgc.ca>

How can access a .mdb from Perl?

Thanks

 ..Tom

-----------------------------------------------------------------------------------------
Tom Kralidis                                  Geo-Spatial Technologist 
Canada Centre for Remote Sensing              Tel: (613) 947-1828
588 Booth Street , Room 241                   Fax: (613) 947-1408
Ottawa , Ontario K1A 0Y7                     
http://www.ccrs.nrcan.gc.ca
-----------------------------------------------------------------------------------------


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

Date: 18 Jul 1999 01:20:23 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Accessing a MS Access Database
Message-Id: <slrn7p2auq.een.sholden@pgrad.cs.usyd.edu.au>

On Sat, 17 Jul 1999 Tom Kralidis <tom.kralidis@ccrs.nrcanDOTgc.ca> wrote:
>How can access a .mdb from Perl?

You could use open() and binmode() and guess the format.

If your running under windows you could also access it through ODBC. You
will need to get some perl database modules, and set up ODBC on you computer
to serve the .mdb file as a data source.

If you get stuck there is a lot of examples on the web for doing this
very thing. Just search for Access, ODBC, and perl and you should find
a few.


-- 
Sam

Simple rule: include files should never include include files.
	--Rob Pike


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

Date: Sat, 17 Jul 1999 20:41:41 -0500
From: "Robert Zamor" <zamors@ync.net>
Subject: Anyone intrested in joining a group?
Message-Id: <ejak3.4463$8c3.188102@typ41.nn.bcandid.com>

Hi, I have been programming in perl for a while now, and I am intrested in
making a small profit group. We would basiclly be making CGI scripts for
those that need them for a small price. So far there is no group name, and
once we start to get going I hope to get a top-level domain. E-mail me at
code@ync.net if you want to join, or for more info. This will be a small
group so it will fill up fast. The only requrments being, you want to make a
small profit, and be able to write CGI in perl. I am open for name
suggestions. Thank you and I look forward to hearing you.

-Code
Code@ync.net




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

Date: Sun, 18 Jul 1999 00:01:12 GMT
From: bane_dewitt@my-deja.com
Subject: Re: Closing Web Browser Connection on Lengthy Processes
Message-Id: <7mr5g4$m4s$1@nnrp1.deja.com>

I wrote:

> I have read the fork perldoc and the Boutell/Kew FAQs,
> and wrote the following test code (below). This prints
> "Hello World" to the browser, closes STDOUT, and attempts
> to fork a process that waits 2 minutes and writes to a
> file (to simulate a long-running process).
>
> The problem is, the browser remains connected to the app
> for the whole 2 minutes, so obviously I'm not understanding
> this close(STDOUT)/fork business very well.
>
> Would someone please tell me what I'm doing wrong?

No takers? I'm not asking to be spoon fed - I'm ready to do more work
to learn the answer to this, I just don't know where to turn to next.
Some FAQs come close to answering it, but the code that I try doesn't
do what I think it's supposed to do. It looks like one just closes
STDOUT and forks a new process, but that doesn't close the browser
connection. Hm.

If it's off topic, would someone please slap me with a big fish and
tell me where to ask?

Thank you,

BD


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


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

Date: Sat, 17 Jul 1999 22:21:39 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: DBM problem: very weird!
Message-Id: <1dv3x3p.14hkr8o1ebbcw0N@p31.block2.tc2.state.ma.tiac.com>

Zeng <zeng@haas.Berkeley.EDU> wrote:

>     dbmopen %tmp,  "tmp",  0644 || die "Can't open file ";
>     dbmopen %rmp,  "rmp",  0644 || die "Can't open file ";

Anno's already pointed out the problem with trying to read references
from a dbm file, so I'll just point out that your precedence is wrong in
the above two lines.

dbmopen(%tmp,  "tmp",  0644) || die "Can't open file ";
dbmopen %rmp,  "rmp",  0644  or die "Can't open file ";


Read about the precedence of || and or in the perlop documentation.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 17 Jul 1999 21:01:08 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: Re: fork() in Win32
Message-Id: <FC9F2FCA0886B70D.B274422413BBB532.D8A5C9DD6ECD9DC7@lp.airnews.net>


David Boyce <David.Boyce@fmr.com> wrote in message
news:3786416A.A5883AEF@fmr.com...
> Also, note from the above quoting mess that cmd.exe is still used to
> launch the program. I've never found a way to get system to avoid using
> the shell on Windows, in direct contravention of perldoc -f exec. But
> then I'm not a Windows programmer, just a Unix guy with a need to write
> code that will run on lesser systems too.


I poked my way through the Perl and Win32 specific source code last week on
a related issue.  For the opening an outgoing pipe (e.g. "foo|"), I found
that it first tries to execute the program directly (with the OS
CreateProcess primitive), and if that fails, then it involves the
command-line shell, which will be the default system shell (CMD.EXE or
COMMAND.COM depending on OS), purposfully avoiding the value of the COMSPEC
environment variable; or will use the value of the PERL5SHELL (if memory
serves) environment variable if set.

This was found in the low-level spawning implementation functions, so I
suppose all the related commands end up in the same place.  I was
specifically following thr route of open(), though, so there may be some odd
twists.

I haven't studied the resulting OS calls in detail to see what happens to
the Console window (or lack of) when Perl is hosted by a process that
doesn't have one (such as PerlScript).

To avoid using "the shell", use a stub program as the PERL5SHELL.  It would
just reflect its arguments as a command to CreateProcess.  Actually, I have
such a program that calls ShellExecute (the GUI shell, that is; does the
document file type mapping to the correct executable), that could be handy
in this situation.

Hmm, setting $ENV{PERL5PATH} just before an open or system or whatnot won't
work, because the result is cached after it is figured out the first time.
It would work from a BEGIN{} before it is needed the first time, if the
result of the %ENV changes is seen by C's getenv() function in the Perl
implementation (somehow I don't think it is, since putenv/setenv is
non-standard).

Maybe Perl could use a better "shell hook" that's under Perl's control?
Internally, the contents of PERL5SHELL (or the default) is parsed into a
list, (ends up something like qw(cmd.exe /c)) which is prepended to the
contents of the particular request.  Just make this list a Perl global
variable, and you can "local" it before the open/system/backtick command
that you want better control over.

--John





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

Date: Sun, 18 Jul 1999 02:43:14 GMT
From: spamhater@ucesucks.nouce.com (Rich)
Subject: Re: Future of Perl
Message-Id: <slrn7p2foj.uc4.spamhater@zippy.aa2ys.ampr.org>

On Sat, 17 Jul 1999 00:30:31 GMT, Jeffrey <Jeffrey@ix.netcom.com> wrote:
>Listen bitch, I learned a lot about how to program the Amiga computer
>and then it died in the marketplace. I don't want something like that
>to happen ever again. A language isn't fucking useful if you can't get
>a job programming in it.
>

   I'll give you a hint; only incompetent programmers worry about
what language a "programming job" asks for.  Competent programmers
are hired because they have the ability to solve problems
in a particular domain.  That, essentially, is the difference
between being a ( paid ) amateur and a true professional.  

>As for my original question, it was spurred by a comment in a CGI book
>that Java would take over and Perl would become a legacy language.
>Someone said the same thing in a message when I did a search on Deja
>News. So don't act like my question was so fucking stupid, bitch.

   I *always* check the USENET posting history of people who
I am considering for employment.  I'm certainly not alone in this
practice.

   Now, do you REALLY think that you have substantially improved
the odds of getting a real job in the future, by a) showing that
you are incapable of acting in a mature fashion, and b) showing
that you can be swayed by the random comments of people whose
expertise you obviously have no means of evaluating?

   Good luck flipping burgers.

- Rich



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

Date: 18 Jul 1999 03:41:40 GMT
From: cltcevans@aol.com (CLTCEvans)
Subject: general--stupid question from a beginner
Message-Id: <19990717234140.12039.00001038@ng-fd1.aol.com>

i am running perl scripts under unix.  do they have to be in a cgi-bin?
also, does my perl interpreter/compiler have to be anywhere special?
finally, do i have to have a special line of codein the perl scripts to tell
where to look for the interpreter?

email:  perllinux@aol.com

Thanks


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

Date: Sat, 17 Jul 1999 23:46:37 -0400
From: "cshelby" <cshelby@mindspring.com>
Subject: HHHHEEEEEEELLLLLLPPPPPPP!!!!!!!!!!
Message-Id: <7mria0$ugi$1@nntp3.atl.mindspring.net>

Ok, here's the deal....
I have tired (key word is tired!) to write a script for forms.  Well, for
some reason it shows a misconfig error, and it sends the E-mail in hex,  I
have included the script and the subform script at the bottom, if you see
any errors sticking out, PLEASE let me know!  Thanks for everything in
advance....
____________________________________________________________________________
______
(questions.cgi)
____________________________________________________________________________
______
#!/usr/bin/perl
#
#
#
require "cgi-lib.pl";
&ReadParse;

print "Content-type:text/html\n\n";

#From, E-mail Address, Subject, Message
$csinfo = "CS Web Designs";
$csemail = "sales\@cswebdesigns.com";
$cssubject = "We will get back to you as soon as possible";
$csmessage = "Thank you for your interest in our company.  You question will
be answered as soon as possible.";
$customer = $formdata{'EMAIL'};
$first = $formdata{'FIRSTNAME'};
$last = $formdata{'LASTNAME'};
$company = $formdata{'ORGANNAME'};
$phone = $formdata{'PHONE'};
$time = $formdata{'BESTTIME'};
$question = $formdata{'COMMENTS'};

#Opening the mail
open(MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;

#Printing the customer Mail information
print MAIL "To: $customer\n";
print MAIL "From: $csinfo\n";
print MAIL "Subject: $cssubject\n";
print MAIL "Dear, $first $last\n";
print MAIL "$csmessage]\n";
print MAIL "You entered the following information.\n";
print MAIL "Company Name: $company\n";
print MAIL "Phone Number: $phone\n, the best time to call: $time\n";
print MAIL "Your Question: $question\n";
print MAIL "We will send the answer to your questions as soon as possible.
Thank you.\n";

#Closing mail
close(MAIL);

#Open the mail
open(MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;

#Printing CS'  Mail
print MAIL "To: $csemail \nFrom: $customer\n";
print MAIL "Subject: Question\n";
print MAIL "$first $last\n";
print MAIL "$company\n";
print MAIL "$question\n";
print MAIL "$phone\n $time\n";

#Closing Mail again
close(MAIL);

____________________________________________________________________________
______
subformparse.lib
____________________________________________________________________________
______
#!/usr/bin/perl

sub Parse_Form {

if ($ENV{'REQUEST_METHOD'} eq 'GET') {@pairs = split(/&/,
$ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer,
$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);

if ($ENV{'QUERY_STRING'}) {@getpairs = split(/&/, $ENV{'QUERY_STRING'});
push(@pairs, @getpairs);
}

} else {
print "Content-type:text/html\n\n";
print "<p>Use Post or Get";
}

foreach $pair (@pairs) { ($key,$value) = split (/=/, $pairs);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9]) /pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9]) /pack("C", hex($1))/eg;

$value =~s/<!--(.|\n)*-->//g;

if ($formdata{$key}) {$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
1;


--
Need a web site?  Need it at a LOW price?
Need Cheep Hosting? (As low as $24.95 a month for 250MB)
Need a web site?  Need Promotion?
Check out CS Web Designs!
See them at http://www.cswebdeisgns.com




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

Date: Sat, 17 Jul 1999 16:10:57 -0500
From: Matt Turner <matt@mail.tca.net>
Subject: MS Access ODBC Truncates
Message-Id: <3790F161.C3A8333C@mail.tca.net>

I am having a problem getting information out of a memo type field in an
access database.  If the memo field is only 80 characters long, my perl
script (using DBI, DBD-ODBC, activestate, WinNt4) returns the column
fine.  But if the memo field is 81 or more characters long I get the
following error:

DBD::ODBC::st fetchrow_array failed: [Microsoft][ODBC Microsoft Access
97 Driver]Data Truncated  (SQL-01004)(DBD: st_fetch/SQLFetch (long
truncated) err=1) at test.pl line 12

So obvisouly the memo field is truncate and it brings up the error.  I
did a lot of research and thought I would need to expand the buffer in
the ODBC control panal and shot it up from 512 up to 2560 and it did no
good.  It is kind of odd how it works for 80 characters, but not 81.

Does anyone have any suggestions.  I really need to be able to store
fields over 255 characters so I really need the memo fields.

Thanks,
Matt


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

Date: Sat, 17 Jul 1999 23:37:28 -0400
From: Brian Gilman <gilmanb@vuser.union.edu>
Subject: newbie needs help!
Message-Id: <37914BF7.D3240B1E@vuser.union.edu>

Hello!
    I am trying to write a small utility programm that will preen a log
file for words specified in a config file......I am having trouble
getting these variables (scalars) into an array.....

I'm trying something like:

sub init_words{

    my $word_list;
my @array_of_words;

open (CONF, "/etc/preener.conf") || die "can't open config file: !$";

while($word_list = <CONF>){
    chomp ($word_list); #kill those pesky \n's
    shift(@array_of_words) = $word_list;
return @array_of_words;
    }
}

but, obviously this doesn't work (I wouldn't be asking for help if it
did!).......Can someone help me with this? I'm really, really new to
perl but findthe language useful and fun to learn!

                                                Thanks in advance!

Brian



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

Date: Sat, 17 Jul 1999 14:31:53 -0400
From: "Jim Janovich" <jjanovich@mindspring.com>
Subject: Perl probs!
Message-Id: <7mqi2s$g46$1@nntp9.atl.mindspring.net>

I am running Redhat 5.2 with Perl 5.004.  Have a few cgis setup....whenever
I try to access the cgi or .pl from a webpage.....it tries to d/l the .pl
file.....whats the prob?

Thanx
Jim




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

Date: Sat, 17 Jul 1999 19:47:59 -0600
From: "K. Paul Mallasch" <pmallasch@mail.starnews.com>
Subject: Re: Perl probs!
Message-Id: <xs9k3.450$Cs3.5408364@news.netdirect.net>

In article <7mqi2s$g46$1@nntp9.atl.mindspring.net> , "Jim Janovich" 
<jjanovich@mindspring.com> wrote:

> I am running Redhat 5.2 with Perl 5.004.  Have a few cgis setup....whenever
> I try to access the cgi or .pl from a webpage.....it tries to d/l the .pl
> file.....whats the prob?
>
> Thanx
> Jim
>
>

Web server not configured to recognize .cgi or .pl perhaps?


-K. Paul Mallasch - Webmaster
http://www.thestarpress.com


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

Date: Sat, 17 Jul 1999 20:39:53 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: Re: Question for the perl gods
Message-Id: <08154D172D44101F.C4576579BC8CE354.61FEB7F199B140E7@lp.airnews.net>

Sure.  I didn't realize the Perl community had such short screens, that's
all.  In some other newsgroups elaborate quote formatting is overkill for a
simple reply to such a short message.  And unneccessary, since any modern
newsreader will show you the original message just as easily.

--John

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:7mqff2$jsi$1@lublin.zrz.tu-berlin.de...
> John M. Dlugosz <john@dlugosz.com> wrote in comp.lang.perl.misc:
>
> >That's not Perl regex syntax....
>
> ...referring to an expression that was about 50 lines down the page.
>
> Would you please trim what you quote to contain only what you are
> going to comment on and also place your comments below what they
> refer to?
>
> Thank you.
>
> Anno




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

Date: Sat, 17 Jul 1999 20:43:41 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: Re: Question for the perl gods
Message-Id: <A00F6E1AB8D7333F.0689551A1645D63F.BFF7EFC38EB7C5BC@lp.airnews.net>


Uri Guttman <uri@sysarch.com> wrote in message
news:x7vhbji1rs.fsf@home.sysarch.com...
> so why not tell him to use HTML::Parser?

Why are you asking me?  If you read his question, you would know why I
didn't recommend a specific Perl module as a solution.

--John

P.S.  I'm I getting the "snotty quotient" correct?  I'm new to this
newsgroup and still trying to fit in.  I'm used to much more polite and
gentile conversation.




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

Date: 17 Jul 1999 23:57:03 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Question for the perl gods
Message-Id: <x7d7xqip9s.fsf@home.sysarch.com>

>>>>> "JMD" == John M Dlugosz <john@dlugosz.com> writes:

  JMD> Sure.  I didn't realize the Perl community had such short
  JMD> screens, that's all.  In some other newsgroups elaborate quote
  JMD> formatting is overkill for a simple reply to such a short
  JMD> message.  And unneccessary, since any modern newsreader will show
  JMD> you the original message just as easily.

the fact that you can look up a previous message is irrelevent. you
comment may be about one part of the quoted post and you still have to
bounce around to get the context and reply. it has nothing to do with
screen sizes but in keeping quotes and replies in context so the thread
maintains some semblence of logic (as if our threads really ever attain
that lofty goal).

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: Sat, 17 Jul 1999 16:39:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <MPG.11fab3f8867fffc7989ceb@nntp.hpl.hp.com>

In article <3790F5AF.6D68FFD6@mcmahon.qal.berkeley.edu> on Sat, 17 Jul 
1999 14:29:20 -0700, Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu> 
says...
 ...
> 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?

Yes.

 ...
> sub larry2 {
>   return max my @lengths;
> }

The argument passed in to this subroutine is replaced by a new, empty 
array.  No wonder it runs faster than those benchmarks that actually do 
something!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 17 Jul 1999 19:16:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <MPG.11fad8d585277613989ced@nntp.hpl.hp.com>

In article <3790F5AF.6D68FFD6@mcmahon.qal.berkeley.edu> on Sat, 17 Jul 
1999 14:29:20 -0700, Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu> 
says...
 ... 
> #!/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)

I changed the benchmark to remove the computation of the random array, 
which shouldn't affect the timing of any method different from the 
others.  I also fixed the two subroutines so they do the same work.  The 
only difference now is one extra subroutine call, with copying of the 
arguments.


#!/usr/local/etc/perl -w
use strict;
use Benchmark;

sub randarray {
  my $count = shift;
  my $limit = shift;
  return map rand($limit), 1 .. $count
}
my @a = randarray 100, 100;

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 @_;
}

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

timethese (
  10000,
    {
     'Larry1' => sub { larry1(@a) } ,
     'Larry2' => sub { larry2(@a) },
     'UseSort' => sub { usesort(@a) }
    }
);
__END__

Benchmark: timing 10000 iterations of Larry1, Larry2, UseSort...
    Larry1:  3 wallclock secs ( 3.24 usr +  0.00 sys =  3.24 CPU)
    Larry2:  4 wallclock secs ( 3.52 usr +  0.00 sys =  3.52 CPU)
   UseSort: 17 wallclock secs (17.18 usr +  0.00 sys = 17.18 CPU)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 18 Jul 1999 03:20:40 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Question: optimized method for finding the maximum value in an array
Message-Id: <379147DA.7255568@home.com>

Larry Rosler wrote:
> 
> timethese (
>   10000,
>     {
>      'Larry1' => sub { larry1(@a) } ,
>      'Larry2' => sub { larry2(@a) },
>      'UseSort' => sub { usesort(@a) }
>     }
> );
> __END__
> 
> Benchmark: timing 10000 iterations of Larry1, Larry2, UseSort...
>     Larry1:  3 wallclock secs ( 3.24 usr +  0.00 sys =  3.24 CPU)
>     Larry2:  4 wallclock secs ( 3.52 usr +  0.00 sys =  3.52 CPU)
>    UseSort: 17 wallclock secs (17.18 usr +  0.00 sys = 17.18 CPU)

Since I mentioned builtin I thought I should add it to this benchmark.

use builtin;
timethese (
  30000,
    {
     'Larry1' => sub { larry1(@a) } ,
     'Larry2' => sub { larry2(@a) },
     'UseSort' => sub { usesort(@a) },
     'Builtin' => sub { builtin::max(@a) },
    }
);
__END__

Benchmark: timing 30000 iterations of Builtin, Larry1, Larry2,
UseSort...
   Builtin:  1 wallclock secs ( 0.75 usr +  0.00 sys =  0.75 CPU)
    Larry1:  9 wallclock secs ( 8.33 usr +  0.00 sys =  8.33 CPU)
    Larry2:  9 wallclock secs ( 8.89 usr +  0.00 sys =  8.89 CPU)
   UseSort: 25 wallclock secs (25.33 usr +  0.01 sys = 25.34 CPU)

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 17 Jul 1999 22:21:40 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Regular expression question (Problems with parsing ascii go diagrams)
Message-Id: <1dv3xp6.ui1l721tojz8oN@p31.block2.tc2.state.ma.tiac.com>

Toni Cornelissen <toni@dse.nl> wrote:

>     /(\d{0,2})\s+((?:[\.OX\d] |\d\d)+)\s*\1/

>     3  . X . 4 O . . 3

> Can someone tell me what I'm doing wrong 
> and what the correct expression I should use is.

Remember that the regex engine tries to find the leftmost match.  At the
beginning of the string, it can match zero digits (for \1), then some
whitespace, then a digit and a space (for \2), then some more
whitespace, and then the zero digits of \1 again.

You should allow for that leading whitespace in your regex:

/^\s*(\d{0,2})\s+((?:[\.OX\d] |\d\d)+)\s*\1/

This one matches some whitespace, the digit 3 (for \1), some more
whitespace, seven occurences of the repetition in \2, some more
whitespace, and then the 3 of \1 again.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 18 Jul 1999 01:17:59 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sending mail with SMTP!
Message-Id: <7mra07$ks6$1@lublin.zrz.tu-berlin.de>

Ruben  <rgonzalez@csus.edu> wrote in comp.lang.perl.misc:
>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:

If you did follow the Cookbook it probably refers to an older version
of Mail::Mailer.  You should also look into perldoc Mail::Mailer, which
documents the installed version.

>*********************************************************
>#!/usr/bin/perl -w
>use Mail::Mailer;
>use DB_File;
>use Fcntl;
>
>eval {
>$mailer = Mail::Mailer->new("smtp","mail.myisp.net");

If you give a mail server, you need the keyword Server before it:

$mailer = Mail::Mailer->new( 'smtp', Server => '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?'
>             );

The open method wants a hash reference, not a hash:

$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: $!";

You don't close the mailer as a filehandle, you call the close
method:

$mailer->close;

This call returns undef.  I haven't looked into that.

Anno


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

Date: Sat, 17 Jul 1999 16:41:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Some more benchmark results:
Message-Id: <MPG.11fab4881f8d5b46989cec@nntp.hpl.hp.com>

In article <Ku7k3.12355$FD6.50905@news2.atl> on Sat, 17 Jul 1999 
18:30:28 -0400, Lee Clemmer <libertarian@mindspring.com.com> says...
> 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?

See my answer to Andrew Perrin.  Doing nothing is often faster than 
doing something.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 18 Jul 1999 00:57:03 GMT
From: skyfaye@my-deja.com
Subject: split()
Message-Id: <7mr8or$n1b$1@nnrp1.deja.com>

Hi,

  Can someone tell me why the split function splits the string into 3
elements instead of 2?


$line = "   Boston     87";   # All the white spaces are spaces
@words = split(/\s+/, $line);
$size = @words;
print "size of words = $size\n";

OUTPUT
-------
size of words = 3

Thanks,
Hung


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


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

Date: 18 Jul 1999 01:17:05 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: split()
Message-Id: <slrn7p2aok.een.sholden@pgrad.cs.usyd.edu.au>

On Sun, 18 Jul 1999 00:57:03 GMT, skyfaye@my-deja.com wrote:
>Hi,
>
>  Can someone tell me why the split function splits the string into 3
>elements instead of 2?
>
>
>$line = "   Boston     87";   # All the white spaces are spaces

Because that is how split works. Read the documentation about split that
comes with perl to find out how to do what you want.

perldoc -f split

-- 
Sam

People get annoyed when you try to debug them.
	--Larry Wall


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

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 179
*************************************


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