[6338] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 960 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 16 20:07:22 1997

Date: Sun, 16 Feb 97 17:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 16 Feb 1997     Volume: 7 Number: 960

Today's topics:
     (Q) return inside a grep BLOCK (Peter Bierman)
     Re: Comparing two dates (William E. Hatch)
     Re: difference btw s/// & tr/// (Bertil Wennergren)
     H: How to associate the .pl extention with perl.exe in  (Jvrgen Gustafsson)
     Re: H: How to associate the .pl extention with perl.exe (Nathan V. Patwardhan)
     Help with chat2.pl (Vasudev Dalal)
     How to push browser to a new URL via perl/CGI <hanklem@ibm.net>
     Re: How to push browser to a new URL via perl/CGI (Joshua Lerner)
     java.io.File.separator equivalent? (Jeff Bauer)
     Leading zero in print format <stats9@mail.idt.net>
     Re: Module installation in $HOME and dependences (Dave Thomas)
     more info about cryptswitch() (Dag Wieers)
     mysql interface (Matthew Ahrens)
     Re: Need Some CGI Security Advise <dean@tbone.biol.sc.edu>
     Re: Pig Latin <99borns@ionaprep.pvt.k12.ny.us>
     Re: Pig Latin <99borns@ionaprep.pvt.k12.ny.us>
     Re: Pig Latin <99borns@ionaprep.pvt.k12.ny.us>
     Re: Pig Latin (Greg Bacon)
     Re: Pig Latin (Dave Thomas)
     Re: Pig Latin (Greg Bacon)
     Re: Printing an array in Perl (Dave Thomas)
     Re: Printing an array in Perl (Piotr Piatkowski)
     Re: Reading directly into array is slow, why? <fawcett@nynexst.com.spam_spam_spam_sausage_and_spam>
     Re: RegEx, Email & Friedl's "Mastering..." Book (Abigail)
     s/// Quesiton (Jim Reynolds)
     Re: s/// Quesiton (Piotr Piatkowski)
     Searching for Perl-supported Linux database <chris@ixlabs.com>
     WIN32 PERL installation problem - perl1 (1/1) (rthomas)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Sun, 16 Feb 1997 14:16:19 -0800
From: bierman@apple.com (Peter Bierman)
Subject: (Q) return inside a grep BLOCK
Message-Id: <bierman-1602971416200001@bierpe3.apple.com>

Why does return inside a grep BLOCK return me out of the entire sub that I'm in?

Is there any simpler way to write a complex grep BLOCK than nesting lots
of if (foo) else 0; to return a value or false?

Here's how I rewrote it:

  @matches = grep {
    @d1 = unpack "a2aaaaaaaaaaa2a2", $_;
    @d2 = unpack "a2aaaaaaaaaaa2a2", $discname;

    #$d[11] is time wo/ frames

    if ($d1[0] eq $d2[0]) {

      $timedif = abs( (($d1[11] - $d2[11])*60) + ($d1[12] - $d2[12]) );
      if ($timedif < 3) {

        $sum = 0;
        for ($i=1; $i<11; $i++) {
          $sum += ($d1[$i] - $d2[$i]);
        }

        if ($sum < 5) {
          $_;
        }
        else 0;
      }
      else 0;
    }
    else 0;
  } @ids;


Here's the code I had that doesn't work:

  @matches = grep {
    @d1 = unpack "a2aaaaaaaaaaa2a2", $_;
    @d2 = unpack "a2aaaaaaaaaaa2a2", $discname;

    #$d[11] is time wo/ frames

    return 0 if ($d1[0] ne $d2[0]);

    $timedif = abs( (($d1[11] - $d2[11])*60) + ($d1[12] - $d2[12]) );
    return 0 if ($timedif > 3);

    $sum = 0;
    for ($i=1; $i<11; $i++) {
      $sum += ($d1[$i] - $d2[$i]);
    }

    return $_ if ($sum < 5);
    0;

  } @ids;


-pmb

-- 
bierman@apple.com 
http://www.upl.cs.wisc.edu/~lunatic/   "This is MASS MADNESS you MANIACS!"


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

Date: 16 Feb 1997 22:02:34 GMT
From: hatch@cais.cais.com (William E. Hatch)
Subject: Re: Comparing two dates
Message-Id: <5e805q$30e@news2.cais.com>

There are functions in the CPAN Date and Time directories for converting
a date-time string to a Julian date (days since a fixed time 4000+ BC)
or unix seconds (seconds since Jan 1 1970 00:00:00 gmt). Once you have
either of these, you can do a simple numeric comparison. This is a lot
simpler and less error prone than the ad-hoc method method suggested below.

bill hatch

Nathan V. Patwardhan (nvp@shore.net) wrote:
: basj@cyber.xs4all.nl wrote:


: : Is there a function for this or will I have to split the dates in
: : components and compater them individually (hope not) ?

: I don't see what's wrong with using localtime().  :-)  It's not very 
: difficult to split the time into hours, minutes, and seconds, then compare
: the result with another entry.



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

Date: 16 Feb 1997 23:50:34 GMT
From: bw@mail2.tripnet.se (Bertil Wennergren)
Subject: Re: difference btw s/// & tr///
Message-Id: <5e86ga$o8u@minox.tripnet.se>

Andrew Johnson skribis:

: Elton Kong wrote:
: > 
: > Hi!
: >         I'm fairly new to PERL. Could anybody tell me what's the
: > difference between using the s/// and the tr/// operators. I mean
: > when I should use one and when the other. When both are good,
: > what's the philosophy to choose one over the other? Thanks
: 
: 
: check the perlop manpage and the perlre manpage.
: 
: s/// uses regexes and does subsitutions on matches
: 
: tr/// does not use regexes and does translations from, say
: lowercase to uppercase
: 

My first reaction to the tr-function was to try something like this, which
would be ideal for a lot of my text work:

tr/(ab)(cd)(ef)(gh)/ijkl/;

The idea was to translate certain character combinations into single
characters (ab -> i, cd -> j...). I doesn't work however. :-( I had to use
more cumbersome s-functions.

----------------------------------------------
Bertilo Wennergren

<bw@tripnet.se>, <bertilow@hem1.passagen.se>
<http://hem1.passagen.se/bertilow/bertilo.htm>
----------------------------------------------



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

Date: Sun, 16 Feb 1997 22:15:01 GMT
From: jorgen.gustafsson@mailbox.swipnet.se (Jvrgen Gustafsson)
Subject: H: How to associate the .pl extention with perl.exe in win95??
Message-Id: <3307840a.600786@nntpserver.swip.net>

Hello, have installed Perl5 for Win95 and there is no problem to run
a  script when i write PERL MYSCRIPT.PL, but when I write only
MYSCRIPT.PL, I'm getting an errormessage.....

How do I associate .pl files with perl.exe???
Doesn't the line #!/perl5/bin/perl do the job??

Any help appreciated

Please reply by email if possible

jorgen.gustafsson@mailbox.swipnet.se


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

Date: 16 Feb 1997 23:21:22 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: H: How to associate the .pl extention with perl.exe in win95??
Message-Id: <5e84pi$grv@fridge-nf0.shore.net>

Jvrgen Gustafsson (jorgen.gustafsson@mailbox.swipnet.se) wrote:

: How do I associate .pl files with perl.exe???
: Doesn't the line #!/perl5/bin/perl do the job??

File Manager _F_ile _A_ssociate perl.exe with .pl.

--
Nathan V. Patwardhan
nvp@shore.net
"[news:alt.fan.jwz]"


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

Date: 16 Feb 1997 23:11:34 GMT
From: vkd0871@omega.uta.edu (Vasudev Dalal)
Subject: Help with chat2.pl
Message-Id: <5e8476$sle@news.uta.edu>
Keywords: Opening a TELNET/FTP session in PERL

Hello all :

	I have been keeping an eye on the posts and till 
now I have not seen any-one really answer the problem/
question of opening a Telnet OR FTP session.

	The FAQS says that I need to use the chat2.pl 
script and just for the kicks I downloaded a copy of the 
script and tried to open a session, but it is not very 
obvious and I had no success.

	I was wondering if some-one out there has used the 
above mentioned script or any other to open a TELNET or 
FTP session ???

	I so, could you please guide me & many who have 
posted and got no help here.

	Any input is appreciated.

	Thnx in advance.

Vasu
-- 
Vasudev Dalal
400 S.Oak St, #111,
Arlington, TX 76010.
PH # : (H) (817)-861-5718
       (W) (817)-273-5634
****************************

"If opera is entertainment, then falling off a roof is transportation!"
                        --A. Neuman (MAD Comics)

I've always said, there are three kinds of people in the world, those who
are good at math, and those who aren't.

Did you hear about the man who was in a car accident and had to have his
whole left side amputated?

 He'e all right now.

Q: Why do blondes put TGIF on all of their shoes?
A: Toes Go In First!

http://club.ib.be/paul.van.stokstraeten/_hack.html
****************************


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

Date: Sun, 16 Feb 1997 17:19:45 -0700
From: Hank LeMieux <hanklem@ibm.net>
Subject: How to push browser to a new URL via perl/CGI
Message-Id: <3307A421.7BA1@ibm.net>

Group,

This question deals with both CGI and perl.  What I want to do is this: 
If an HTML form input is submitted and successfullly processed by my
script, I want the user's browser to bring up a pre-existing HTML thank
you page, rather than a page of text generated by the script.  So how do
I get the script to push the browser to a new URL?

Greatly appreciating your assistance,

Hank

-- 

Hank LeMieux
Santa Fe, NM
(505) 986-8166
http://members.aol.com/HankWeb/

-- 

Hank LeMieux
Santa Fe, NM
(505) 986-8166
http://members.aol.com/HankWeb/



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

Date: 16 Feb 1997 19:42:59 -0500
From: jlerner@panix.com (Joshua Lerner)
Subject: Re: How to push browser to a new URL via perl/CGI
Message-Id: <5e89ij$k90@panix3.panix.com>

In article <3307A421.7BA1@ibm.net>, Hank LeMieux  <hanklem@ibm.net> wrote:

>This question deals with both CGI and perl.  What I want to do is this: 

Your question doesn't really have anything to do with Perl -- it belongs
in a CGI newsgroup.

>If an HTML form input is submitted and successfullly processed by my
>script, I want the user's browser to bring up a pre-existing HTML thank
>you page, rather than a page of text generated by the script.  So how do
>I get the script to push the browser to a new URL?

print "Location: http://www.someplace.on.the.net/foo.html\n\n";

Good luck,

Joshua Lerner


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

Date: Sun, 16 Feb 1997 21:34:25 GMT
From: JeffBauer@Bigfoot.com (Jeff Bauer)
Subject: java.io.File.separator equivalent?
Message-Id: <33077c5f.1957865271@news.bayarea.net>

Apologies if this issue is addressed in the Perl FAQ or Camel book,
but I didn't find it whilst skimming ...

In the interest of retaining environment neutrality, are there Perl5
equivalents to Java's static  File.separator and File.pathSeparator
variables?

Thanks,
Jeff 


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

Date: Sun, 16 Feb 1997 16:30:09 -0500
From: Chris Plachta <stats9@mail.idt.net>
Subject: Leading zero in print format
Message-Id: <33077C60.3F463F4E@mail.idt.net>

Does anyone know how to get rid of the leading zero in a fixed
precision numeric value in a print format?  I wnat to print a
value that looks like this:

 .323

rather than this:

  0.323

When I use the notation:

@.###

in my print format it still gives me the leading zero.  Any clever
tricks or do I have to hack the field up before calling the write
command?  

Thanks for you time.


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

Date: 16 Feb 1997 21:34:48 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Module installation in $HOME and dependences
Message-Id: <slrn5gev6j.v1e.dave@fast.thomases.com>

On 16 Feb 1997 17:18:22 +0100, Kent Boortz <kent@erlang.ericsson.se> wrote:
> So why no Unix environment variable with additional paths to search?
> 
> I searched the FAQ and perlrun man-page but couldn't find anything.
> The only solution I can think of is to install my own copy of Perl
> but i would prefer not to. Especially since I have lots of scripts
> that begin with "#!/usr/local/bin/perl".

>From perl.pod:

=item PERL5LIB

A colon-separated list of directories in which to look for Perl library
files before looking in the standard library and the current
directory.  If PERL5LIB is not defined, PERLLIB is used.  When running
taint checks (because the script was running setuid or setgid, or the
B<-T> switch was used), neither variable is used.  The script should
instead say

    use lib "/my/directory";
    
=item PERLLIB

A colon-separated list of directories in which to look for Perl library
files before looking in the standard library and the current
directory.  If PERL5LIB is defined, PERLLIB is not used.
	    


A grep through the documentation for directory or library found it.

Regards

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Sun, 16 Feb 1997 22:27:34 GMT
From: dag@dds.nl (Dag Wieers)
Subject: more info about cryptswitch()
Message-Id: <33078953.15841077@news.ping.be>

Hi,

In a Perl FAQ I encountered this:

>You might also look into the cryptswitch() stuff in the perl
>source, which would allow you to ship something in a form they can't
>read.

Can anyone give me more information about cryptswitch, 'cause I
doesn't seem to find it. 
And is this a solution to protect your sources against changing it by
a third party ?

Thanks in advance,

DAG
(dag@dds.nl)



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

Date: Sun, 16 Feb 1997 22:18:10 GMT
From: matt@callnet.com (Matthew Ahrens)
Subject: mysql interface
Message-Id: <330985f4.68121854@news.alt.net>

I was checking out the mySQL web page, because of my frustrations using
mSQL, so i looked on CPAN for a perl interface for mySQL but could not find
one.

Does anyone have a perl interface to mySQL?

should I try to run msqltomysql (or whatever that utility is for converting
C code from msql to mysql calls) on the source for the Msql perl module?

thanks,
--matt


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

Date: 16 Feb 1997 19:44:03 -0500
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Need Some CGI Security Advise
Message-Id: <x0n2t445yk.fsf@tbone.biol.sc.edu>

Richard Watkins <rwatkins@crosslink.net> writes:
> I am considering placing some limited security into some of my web
> pages via adding a REMOTE_HOST or REMOTE_ADDR lookup of an incoming
> surfer to certain page.  Is it possible to create a "authorized
> list" type of file that lists all authorized IP addresses or Domain
> names that are authorized to visit this site?  This file must be
> protected and lookup by the Perl script for authorization and deny
> access to all others. I know the server admin people can place some
> user IP restrictions on my pages in concern, but I'm avoiding
> bothering those guys when possible.  The web pages concerned are not
> really sensitive, but some of my company people are putting pressure
> on me to develop some limited security into my web site (I'm just
> hosting pages and have a shell account to store CGIs and web pages).
> I can't seem to find any examples of this - Please help if you
> having any suggestions or know a site that shows some examples.
> Thanks, Rick rwatkins@crosslink.net

A much easier way to do it is to use .htaccess files.  Most web
servers of which I'm aware support the use of a file named ".htaccess"
in any directory of the document tree.  In that file you can use the
standard server limitation/protection/passwording/etc. controls.
Check your server's documentation for details, and take a look at the
server configuration files from your site's server to see how (and if)
they've implemented .htaccess.  If the site managers haven't, then ask
them to do so (or threaten that you'll make them maintain your
security information...).

-Dean
-- 
N. Dean Pentcheff   <pentcheff@acm.org>   WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83  A0 BF CB C0 D1 0E 76 C0 
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"


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

Date: Sun, 16 Feb 1997 15:57:42 -0800
From: "!Stephen!" <99borns@ionaprep.pvt.k12.ny.us>
To: Chris Schleicher <chrissch@cs.uoregon.edu>
Subject: Re: Pig Latin
Message-Id: <33079EF6.6F2F@ionaprep.pvt.k12.ny.us>

> Ugh.  A classic case a naughty goto.  ;-)  Just how do you expect
> to ever reach that if statement?
> 
> Lose the LOOP, and test for "exit" before you translate to pig latin:
> 
>     while (<>) {
>         die "Exiting!" if /^exit$/;
>         s/\b([^aeiouy]*)(\S+)\s?/$2$1ay  /gi;
>         print;
>     }
> 
> or, even lazier:
> 
>     [~] 7 % perl -lpe 'die "Exiting!" if /^exit$/; \
>     ?                  s/\b([^aeiouy]*)(\S+)\s?/$2$1ay  /gi;'
> 
> 
> Hope this helps,
> 
> --Chris
> -- 
>      Chris Schleicher                      Office:  541/346-3998
>      Univ of Oregon CIS GTF                email: chrissch@cs.uoregon.edu
>                 URL: http://www.cs.uoregon.edu/~chrissch/

Chris,
	Thanks for the help! I tried your suggestion, in fact I now have
several variations on your suggestion. I *love* my stupid PERL program!
:-)

-- 
!Stephen!
Try the *new* incredibly fantastic HTML contest!
	http://home1.gte.net/spantz


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

Date: Sun, 16 Feb 1997 16:03:30 -0800
From: "!Stephen!" <99borns@ionaprep.pvt.k12.ny.us>
To: "Nathan V. Patwardhan" <nvp@shore.net>
Subject: Re: Pig Latin
Message-Id: <3307A052.6CB@ionaprep.pvt.k12.ny.us>

Nathan,
	You're sick:-) But funny! 
-- 
!Stephen!
Try the *new* incredibly fantastic HTML contest!
	http://home1.gte.net/spantz


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

Date: Sun, 16 Feb 1997 16:01:12 -0800
From: "!Stephen!" <99borns@ionaprep.pvt.k12.ny.us>
To: Greg Bacon <gbacon@CS.UAH.Edu>
Subject: Re: Pig Latin
Message-Id: <33079FC8.13E3@ionaprep.pvt.k12.ny.us>

Greg,
	Thanx for the help! Unfortunately, I'm not sure I understand what the
last part of your letter means. What is all that stuff about regexes=>,
etc. mean? 

> FWIW:
> 
> oreo% cat test.pl
> #! /usr/bin/perl
> 
> use Benchmark;
> 
> timethese(100000,
>     {
>      'regex' => '$_ = "exit\n"; $a = /^exit$/',
>      'cmp'   => '$_ = "exit\n"; chomp; $a = $_ eq "exit"',
>      'index' => '$_ = "exit\n"; $a = (index $_, "exit" == 0)',
>      'substr' => '$_ = "exit\n"; $a = (substr($_, 0, 4) eq "exit")',
>     }
> );
> oreo% test.pl
> Benchmark: timing 100000 iterations of cmp, index, regex, substr...
>        cmp:  3 secs ( 2.89 usr  0.00 sys =  2.89 cpu)
>      index:  3 secs ( 1.94 usr  0.00 sys =  1.94 cpu)
>      regex:  3 secs ( 3.79 usr  0.00 sys =  3.79 cpu)
>     substr:  4 secs ( 3.01 usr  0.00 sys =  3.01 cpu)
> 
> Greg
> --
> Greg Bacon <gbacon@cs.uah.edu>
> Unix / Perl Consultant
> Perl Institute Partner - http://www.perl.org/

	Thanx a lot!
-- 
!Stephen!
Try the *new* incredibly fantastic HTML contest!
	http://home1.gte.net/spantz


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

Date: 16 Feb 1997 21:43:34 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: 99borns@ionaprep.pvt.k12.ny.us
Subject: Re: Pig Latin
Message-Id: <5e7v26$3n6@info.uah.edu>

[Posted and mailed]

In article <33079FC8.13E3@ionaprep.pvt.k12.ny.us>,
	"!Stephen!" <99borns@ionaprep.pvt.k12.ny.us> writes:
: Greg,
: 	Thanx for the help! Unfortunately, I'm not sure I understand what the
: last part of your letter means. What is all that stuff about regexes=>,
: etc. mean? 

OK.. here's a bit of a play-by-play:

# tell perl to go grab a library called Benchmark.pm and make it
# available to us (read about "use" in perlfunc)
use Benchmark;

# now that we have access to the Benchmark package, we can do all sorts
# of cool things.. read the manpage/perldoc on Benchmark for the full
# story

# one of Benchmark's subs is timethese, which takes two arguments.
# The first is a repeat count, i.e. "do what I'm about to tell you
# this many times".  The second is a reference to a hash (if you don't
# know what this means, go read the perlref manpage) whose keys are
# identifiers that have some meaning to the programmer and whose
# values are small pieces of Perl code to be run the repeat count number
# of times.
timethese(100_000, # run each of these 100,000 times
    {
     # a simple, anchored regular expression
     'regex'  => '$_ = "exit\n";        $a = /^exit$/',

     # chomp and string compare
     'cmp'    => '$_ = "exit\n"; chomp; $a = $_ eq "exit"',

     # is first occurence of "exit" at position 0 in $_?
     'index'  => '$_ = "exit\n";        $a = (index $_, "exit" == 0)',

     # are the first four characters of $_ e-x-i-t?
     'substr' => '$_ = "exit\n";        $a = (substr($_, 0, 4) eq "exit")',
    }
);

oreo% test.pl
Benchmark: timing 100000 iterations of cmp, index, regex, substr...
       cmp:  3 secs ( 2.89 usr  0.00 sys =  2.89 cpu)
     index:  3 secs ( 1.94 usr  0.00 sys =  1.94 cpu)
     regex:  3 secs ( 3.79 usr  0.00 sys =  3.79 cpu)
    substr:  4 secs ( 3.01 usr  0.00 sys =  3.01 cpu)

This is the output of the above program.  The most important statistic
is user time (abbreviated usr).  You'll note that "index" executed in
the least amount of time.  Speed isn't everything of course, and what
"index" gains in speed it loses in readability, IMHO.

BTW, from perlop:

     The => digraph is mostly just a synonym for the comma
     operator.  It's useful for documenting arguments that come
     in pairs.  As of release 5.001, it also forces any word to
     the left of it to be interpreted as a string.

Hope this helps,
Greg
-- 
Greg Bacon <gbacon@cs.uah.edu>
Unix / Perl Consultant
Perl Institute Partner - http://www.perl.org/


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

Date: 16 Feb 1997 22:03:38 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Pig Latin
Message-Id: <slrn5gf0sk.v4t.dave@fast.thomases.com>

On 16 Feb 1997 21:43:34 GMT, Greg Bacon <gbacon@cs.uah.edu> wrote:
> oreo% test.pl
> Benchmark: timing 100000 iterations of cmp, index, regex, substr...
>        cmp:  3 secs ( 2.89 usr  0.00 sys =  2.89 cpu)
>      index:  3 secs ( 1.94 usr  0.00 sys =  1.94 cpu)
>      regex:  3 secs ( 3.79 usr  0.00 sys =  3.79 cpu)
>     substr:  4 secs ( 3.01 usr  0.00 sys =  3.01 cpu)
> 
> This is the output of the above program.  The most important statistic
> is user time (abbreviated usr).  You'll note that "index" executed in
> the least amount of time.  Speed isn't everything of course, and what
> "index" gains in speed it loses in readability, IMHO.

Greg - an interesting thing happens if you change the test cases so that $_
is NOT set to 'exit\n'.

Here are my "before" timings:

   Benchmark: timing 300000 iterations of cmp, index, regex, substr...
   cmp:  2 secs ( 1.36 usr  0.00 sys =  1.36 cpu)
   index:  2 secs ( 1.05 usr  0.00 sys =  1.05 cpu)
   regex:  4 secs ( 1.48 usr  0.00 sys =  1.48 cpu)
   substr:  3 secs ( 1.47 usr  0.00 sys =  1.47 cpu)
		     

If I change exit\n to xexit\n, then I get

   Benchmark: timing 300000 iterations of cmp, index, regex, substr...
   cmp:  2 secs ( 1.30 usr  0.00 sys =  1.30 cpu)
   index:  2 secs ( 1.06 usr  0.00 sys =  1.06 cpu)
   regex:  2 secs ( 1.02 usr  0.00 sys =  1.02 cpu)
   substr:  4 secs ( 1.45 usr  0.00 sys =  1.45 cpu)

Suddenly, regex is cheapest (I guess because its anchored, so it only looks
at one character, while the others all have to scan the entire string). As
this is the most common case (there's only one exit for a whole string of
other cases), then maybe the regex approach ain't so bad after all!

Regards

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 16 Feb 1997 22:47:39 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: Dave@Thomases.com
Subject: Re: Pig Latin
Message-Id: <5e82qb$3n6@info.uah.edu>

[Posted and mailed]

In article <slrn5gf0sk.v4t.dave@fast.thomases.com>,
	dave@fast.thomases.com (Dave Thomas) writes:
: Suddenly, regex is cheapest (I guess because its anchored, so it only looks
: at one character, while the others all have to scan the entire string). As
: this is the most common case (there's only one exit for a whole string of
: other cases), then maybe the regex approach ain't so bad after all!

I hope you didn't get the impression that I was saying that my solution
was in any way better than Chris's (or anyone else's).  I've always
payed due homage to Our Motto set down from on high: TMTOWTDI.  My
point is similar to one Randal made about teaching formats to his Perl
classes: once he teaches formats, students try to solve all problems
with formats, even when such a solution is suboptimal.  Jeffrey's
aforementioned article beautifully illustrates the great extent to which
we can focus on regular expressions and ignore other possible solutions.

I come but to advocate open minded programming. :-)

Greg
-- 
Greg Bacon <gbacon@cs.uah.edu>
Unix / Perl Consultant
Perl Institute Partner - http://www.perl.org/


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

Date: 16 Feb 1997 21:41:06 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Printing an array in Perl
Message-Id: <slrn5gevif.v1e.dave@fast.thomases.com>

On Sun, 16 Feb 1997 11:39:14 -0700, Halo <halo@asu.edu> wrote:
>  for($i=2; $i < $a; $i++)
>  {
>   printf "%s", $words[i];
                        ^------ noticable lack of a $ sign here!
>  }        
> 

You might want to look at array slices and 'join' as a more compact way of
expressing this.

Regards

Dave



-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 16 Feb 1997 22:55:25 +0100
From: kompas@galaxy.uci.agh.edu.pl (Piotr Piatkowski)
Subject: Re: Printing an array in Perl
Message-Id: <5e7vod$fhg@galaxy.uci.agh.edu.pl>

Halo <halo@asu.edu> wrote:
: Hi,
:   I have a databse with names and addresses of people. Each address and
: name is on a single line. The first field is the state followed by the
: zip code and then the name and the rest of the address. I want to print
: the Name and address on one line and the State and zip code on the next.
: A sample record looks like this
: WY 82070 Tomane James    3307 Alta Vista D Laramie 
: I was doing it in the following way
:  for($i=2; $i < $a; $i++)
:  {
:   printf "%s", $words[i];
                       ^^^ you've missed $  (should be $words[$i])
:  }        

: where words is my array.
: my result looks loke this
: WYWYWYWYWYWYWY  

$words[i] == $words["i"] == $words[0] == "WY"  ( != $words[$i] )

-- 
Piotr Pi1tkowski, Uczelniane Centrum Informatyki, AGH Krakow, POLAND


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

Date: 16 Feb 1997 18:10:48 -0500
From: Tom Fawcett <fawcett@nynexst.com.spam_spam_spam_sausage_and_spam>
To: bw@mail2.tripnet.se (Bertil Wennergren)
Subject: Re: Reading directly into array is slow, why?
Message-Id: <8jraigfitj.fsf@lethe.i-have-a-misconfigured-system-so-shoot-me>

bw@mail2.tripnet.se (Bertil Wennergren) writes:
> I am puzzled by the time differences in the following simple code.
> Reading a file directly into an array is much slower (on larger files)
> than reading it indirectly through more lines of code. Why is this?
>  
> I'm running Perl on an Atari ST, which is of course in itself a _very_
> slow machine. To duplicate my results on a faster machine much bigger
> files would be needed, I suppose.
>  
>[script deleted] 
>
> This prints out:
>  
> "small" first try: 0 second(s)
> "small" second try: 0 second(s)
> "medium" first try: 4 second(s)
> "medium" second try: 8 second(s)
> "large" first try: 16 second(s)
> "large" second try: 102 second(s)
>  
> Is this a fault in the Atari ST version of Perl, or is there another
> explanation?

Interesting effect.  I don't know whether it's your machine, the
implementation (4.036 is pretty old) or your RAM size.  I'd guess you're
catching some garbage collection and paging in your timing of the second
loop, since Perl has to de-allocate the space of @text.

So I added:
	@text = ();
before the second loop and got these timings on my machine:

"large" first try: 11 second(s)
"large" second try: 6 second(s)     

(large = 8 meg file, Sparc10 running SunOS 4.1.3, 64 meg)

These timings are closer to what I'd expect.

-Tom 


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

Date: Mon, 17 Feb 1997 00:07:13 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: RegEx, Email & Friedl's "Mastering..." Book
Message-Id: <E5q0C1.HBz@nonexistent.com>

On Fri, 14 Feb 1997 21:22:26 GMT, cggatt@worldnet.att.net wrote in comp.lang.perl.misc:
++ Any help would be appreciated - 
++ 
++ In Friedl's book there is an example of parsing email headers that are
++ all single line entries. I am trying to match to headers that have
++ multiple line selections like the following -
++ 
++ Received: Blah BLah
++ 	    Blah BLah
++ Date: BLah Blah
++ 
++  I am reading the email header as one continuos string instead of
++ saving to file and reading from STDIN. Right now, I match on the colon
++ and the word metacharacters. Problem - I use (.*) to match everything
++ after the colon and this breaks on the \n. How would I tell the
++ expression to match the multiple line, as above, but go back to
++ matching normally on the 'Date:' line. Again, any help is appreciated.

#!/usr/local/bin/perl -wT
 
use strict;
 
undef $/;    # Read the whole file at once.
 
foreach (split /\n(?!\s)/, <>) { # Split on newlines not followed by whitespace.
    /^Received: (.*)/s and print "Received: $1\n";
    /^Date: (.*)/s     and print "Date: $1\n";
    last if /\n$/;                         
}


I split the string using /\n(?!\s)/, thus newlines not followed by
whitespace.  In that case, header lines that get continues on the next
line (and hence start with whitespace), don't get splitted. The 'undef
$/' makes that I can read the whole file at once. Finally, the trailing
s on the regexs make that . matches newlines as well.

(The 'last if /\n$/' makes the loop terminate at the end of the headers;
 which are separated by a blank line from the body.)


Abigail



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

Date: Sun, 16 Feb 1997 21:25:26 GMT
From: reynolds-j@mindspring.com (Jim Reynolds)
Subject: s/// Quesiton
Message-Id: <33077a66.49940986@news.mindspring.com>

I am trying to do the following string conversion and am stuck.
Thank You in advance!

I would like to use the s/// function to covert the string:
[link=http://www.foo.com/]

to...

<a href="http://www.foo.com/">http://www.foo.com/</a>

HELP!!!


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

Date: 16 Feb 1997 23:03:25 +0100
From: kompas@galaxy.uci.agh.edu.pl (Piotr Piatkowski)
Subject: Re: s/// Quesiton
Message-Id: <5e807d$g24@galaxy.uci.agh.edu.pl>

Jim Reynolds <reynolds-j@mindspring.com> wrote:
: I am trying to do the following string conversion and am stuck.
: Thank You in advance!

: I would like to use the s/// function to covert the string:
: [link=http://www.foo.com/]

: to...

: <a href="http://www.foo.com/">http://www.foo.com/</a>

s!\[link=(.*?)\]!<a href="$1">$1</a>!

So what was your problem?

-- 
Piotr Pi1tkowski, Uczelniane Centrum Informatyki, AGH Krakow, POLAND


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

Date: Sun, 16 Feb 1997 15:50:54 -0800
From: Chris Schoenfeld <chris@ixlabs.com>
Subject: Searching for Perl-supported Linux database
Message-Id: <33079D5E.17160D8A@ixlabs.com>

I'm in the market for a database with the following features:

1. Native Linux and Spac Solaris support (i.e. share binary db's).
2. A thoroughly tested Perl 5 module interface.
3. Speedy, for CGI work.
4. Either commercial or well-supported PD.
5. Native file/record locking.

We have been using Berkeley DB / DB_File but wish to move to something a
little more robust, as we have been having some portability, locking,
and corruption problems here and there.

After some preliminary research, I have narrowed it down to the
following:

Mini-SQL
MiniSQL seems well supported with its own Perl interface module. It is
also touted as being faster then PostgreSQL, although comparatively
lacking in features.

PostgreSQL
PostgreSQL also seems well supported, and has its own Perl module, but
is not quite as fast as Msql.

Empress
Empress not only has its own Perl module, but both the module and Linux
seem to be commercially supported for this product. I don't know the
price, but have sent email to the company for more info.

DBD::DBI (sp?) module.
I am curious about the status of this module, and especially the mSQL, 
PostgreSQL, and Empress interfaces. What exactly is the status of this
project, and can anyone reccommend a particular implementation for
production work? It would certainly be an advantage to have a
well-supported transparent layer.


I am no database guru. I just know the DB_File interface and that's
about it. We are ready to move to something bigger and better and
looking for some pointers. If anyone has any recomendations or
experiences with the above I would love to hear them.

Thanks
Chris


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

Date: Sun, 16 Feb 1997 22:28:11 GMT
From: rthomas9@worldnet.att.net (rthomas)
Subject: WIN32 PERL installation problem - perl1 (1/1)
Message-Id: <5e81kh$5ic@mtinsc04.worldnet.att.net>

begin 644 perl1
M#0I)(&1O=VYL;V%D960@82!B:6YA<GD@<&%C:V%G92!F;W(@5TE.,S(@4&5R
M;"!W:&EC:"!W87,@;&ES=&5D(&%S(#$Q,"UI.#8N>FEP(`T*;VX@=W=W+G!E
M<FPN:&EP+F-O;2X@#0H-"E5.>FEP960@:70@;VMA>2!A;F0@=&AE;B!E>&5C
M=71E9"!)3E-404Q,+D)!5"P@=VAI8V@@86)E;F1E9"!W:71H('1H92`-"F9O
M;&QO=VEN9R!M97-S86=E+@T*#0HB8V%N)W0@;&]C871E($Y4+G!H(&EN($!)
M3D,@*&1I9"!Y;W4@<G5N(&@R+G!H*2!A="!I;G-T86QL+F)A="!L:6YE(#,U
M(@T*#0I4:&4@;6%N:69E<W0@;&ES=',@3E0N<&@@86YD(&ET('!H>7-I8V%L
M;'D@97AI<W1S(&EN('1H92!097)L(&1I<F5C=&]R>2X@(`T*:#(N<&@@:7,@
M;F]T(&QI<W1E9"!I;B!T:&4@;6%N:69E<W0@86YD(&1O97,@;F]T(&5X:7-T
M('!H>7-I8V%L;'D@:6X@=&AE(%!E<FP@#0ID:7)E8W1O<GDN(`T*#0I)('=E
M;G0@8F%C:R!T;R!W=W<N<&5R;"YH:7`N8V]M(&9O<B!H96QP(&)U="!T:&5I
M<B!&05$@86YD(&1I8W5S<VEO;B!'<F]U<`T*:7,@;F]N+65X:7-T86YT(&]R
M('5S96QE<W,N#0H-"DD@86QS;R!D;W=N;&]A9&5D('1H92!S86UE(&)I;F%R
M>2!P86-K86=E(&9R;VT@=W=W+F%C=&EV97=A<F4N8V]M(&9O<B!724XS,B`-
M"E!E<FP@=VAI8V@@=V%S(&%L<V\@;&ES=&5D(&%S(#$Q,"UI.#8N>FEP+"!A
M;F0@=&AE('-A;64@=&AI;F<@:&%P<&5N960N(`T*#0I!;GEO;F4@96QS92!H
M879E('1H:7,@<')O8FQE;3\_/R`@06YY('-U9V=E<W1I;VYS('=E;&-O;65D
M(2$-"@T*5&AA;FL@>6]U(&9O<B!Y;W5R('1I;64N#0I"97-T+"`-"@T*4BX@
,5&AO;6%S#0H-"@T*
`
end


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

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

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 V7 Issue 960
*************************************

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