[6867] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 492 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 17 11:04:24 1997

Date: Sat, 17 May 97 08:00:29 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 17 May 1997     Volume: 8 Number: 492

Today's topics:
     (Q) : about the "@" sign <eermmb@engunx.unl.edu>
     Re: (Q) : about the "@" sign (A. Deckers)
     Re: calling a Win32 API function from a Perl script <petri.backstrom@icl.fi>
     Re: Calling c code...help (Abigail)
     Format and output ? (Richard Dows)
     How to replace a line of text with multiple lines? (Graeme Merrall)
     Re: I need a programmers assistance... <ajohnson@gpu.srv.ualberta.ca>
     Re: inclu-OR in regex (Chipmunk)
     Re: Is there a port for NT <jspeight@mselva.demon.co.uk>
     Re: More trouble with Syslog <terry@spcuna.spc.edu>
     Re: New draft of scripting white paper <rdewolf@msmail2.hac.com>
     Re: Opening Javascript style windows with perl (Abigail)
     perl and awk <ahenig@iil.intel.com>
     Re: POP V3 implementation in Perl..Has anybody implemen (Neil Briscoe)
     Re: POP V3 implementation in Perl..Has anybody implemen (Clay Irving)
     Re: regrex question - really basic! <rootbeer@teleport.com>
     Re: Save Programming? (Tim Gim Yee)
     SOLN: Installing PerlScript - 306 bad - 303 ok. <jmoore@deleuze.informinteractive.com>
     Re: Sorting Associative by Values? (Brian Lavender)
     Re: splitting text (Chipmunk)
     Re: swallowing whitespace (Chipmunk)
     Re: Tatum O'Neil (David Alan Black)
     Re: What's the quickest way in perl to determine if a s <plussier@synnet.com>
     Re: What's the quickest way in perl to determine if a s (Abigail)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 16 May 1997 22:23:31 -0500
From: Daneshjoo <eermmb@engunx.unl.edu>
Subject: (Q) : about the "@" sign
Message-Id: <Pine.OSF.3.95.970516221237.7594A-100000@engunx.unl.edu>

Hi :

	I'm trying to set up an auto responder.  The problem accurs when I
want to define the address of the receiver.  If that person has an email
address as "someone@somewhere.com", I will recieve an error saying that
"@" is not valid.  How could I define the email address without having
this problem?  TIA

				Daneshjoo

			  eermmb@engvms.unl.edu
		



Here is part of the script that I'm trying to execute :


open (MAIL,"|/usr/bin/mail -s "$subject" someone@somewhere.com < $file");
close(MAIL);	



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

Date: 17 May 1997 12:34:58 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: (Q) : about the "@" sign
Message-Id: <slrn5nr9fi.20t.I-hate-cyber-promo@news.rediris.es>

In comp.lang.perl.misc,
	eermmb@engunx.unl.edu wrote:
>Hi :
>
>	I'm trying to set up an auto responder.  The problem accurs when I
>want to define the address of the receiver.  If that person has an email
>address as "someone@somewhere.com", I will recieve an error saying that
>"@" is not valid.  How could I define the email address without having
>this problem?  TIA
>

I don't think the error message is saying that @ is "not valid" as such.
More likely, it's telling you that you must escape it by preceding it
with a backslash: j.random.user\@some.dom-ain.com

>Here is part of the script that I'm trying to execute :
>
>
>open (MAIL,"|/usr/bin/mail -s "$subject" someone@somewhere.com < $file");
                                                 ^
                                                  Yup, there it is.
                                           Should be:
                                           someone\@somewhere.com
>close(MAIL);	
>

BTW, I'd be willing to bet my bottom dollar (er... pound sterling) that
this is covered in the documentation and the Perl FAQ, so you really
should read those before posting your question to thousands of news
servers all over the world.

Also, somewhere.com is a valid domain, so try not to use it for testing
purposes.

HTH,

Alain

-- 
Perl information: <URL:http://www.perl.com/perl/>
    Perl archive: <URL:http://www.perl.com/CPAN/>
        Perl FAQ: <URL:http://www.perl.com/CPAN/doc/FAQs/FAQ/>
>>>>>>>>>>>>> NB: comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<<<<<


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

Date: Fri, 16 May 1997 10:11:46 +0200
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: calling a Win32 API function from a Perl script
Message-Id: <337C16C2.5133@icl.fi>

Harold Howe wrote:
> 
> Howdy folks,
> 
> 1- Can an API function be called from within the Perl script, like
> GetSystemMetrics?
> 
> 2- Can a Perl script call a DLL function, if I provide the DLL?

Yes. Look up, e.g., Win32::* in your Perl for Win32 documentation. 
If you don't have it, go to

   http://www.activeware.com

to get it (along with the latest Perl for Win32).

If you want to call any arbitrary Win32 API function (that isn't
already supported/implemented), then you need to create your own
Perl extensions first (look in perlxstut, perlxs, perlguts in
the docs for more).

regards,
 ...petri.backstrom@icl.fi
    ICL Data Oy
    Finland


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

Date: Sat, 17 May 1997 05:52:20 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Calling c code...help
Message-Id: <EAB9n8.LrL@nonexistent.com>

On 17 May 1997 03:31:20 GMT, amhardin@erols.com wrote in
comp.lang.perl.misc URL: news:5lj8q8$gbu$1@bilbo.reference.com:
++ I am trying to call c code from a perl script - Im running on
++ LINUX and have used GNU C for my C code...this WAS working at
++ one point and Im not sure why it is not anylonger. The c code
++ seems to be working fine (when i execute it from the command
++ line in LINUX, I get the expected results (an ID). But for
++ some reason when I try to run it  from the perl script it
++ doesn't even seem to be calling the c code - (it comes back
++ quickly and no id was returned) ... heres the calling code
++ from perl....any advice would be appreciated...

I've no idea what Linux and C got to do with it... "search.exe"
doesn't seem like a typical Linux name to me.

++  $pid = open PROG, "search.exe @zip5 @zip4 @filename |";
++                                   (search accepts 3 variables)

Are you sure this is what you want? It will only work if the
arrays @zip5 @zip4 and @filename each contain a single element.

Perhaps you want:

open PROG, "search.exe $zip5[0] $zip4[0] $filename |" or
   die "search.exe failed: $!";

@idnumb = <PROG>;  # Note that this slurps in all the lines.

close PROG;

You might want to do:
my $command = "search.exe $zip5[0] $zip4[0] $filename";
print $command, "\n";

and see if it contains what you think it contains.

++  unless (defined $pid) {
++        die "open not completed";
++        }
++ 
++  print $pid;    (just put this in for debugging - i get a value)
++  @idnumb = <PROG>;
++  close(PROG);
++ 
++  print @idnumb;
++ 
++ 
++ Thanks in advance..


Abigail


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

Date: 16 May 1997 14:44:46 GMT
From: marius@randomc.com (Richard Dows)
Subject: Format and output ?
Message-Id: <5lhrsu$al4@news1.randomc.com>

I have a file where it uses the 'format' functions;  I have a problem 
in that I want to push the output of the format's 'write' to a mail 
using the Net::SMTP package - but I don't know how to do this.  If
someone has done this could you please mail me how, or reply on here
how to ?  Thank you,

Richard Dows,
marius@randomc.com


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

Date: Sat, 17 May 1997 09:01:49 GMT
From: graeme@manawatu.gen.nz (Graeme Merrall)
Subject: How to replace a line of text with multiple lines?
Message-Id: <337d71a0.1516474@news.manawatu.gen.nz>

Hi.
I'm trying to achieve a locally scripted type of SSI thing (if that
makes sense). Basically, my script parses a file looking for comments
and then inserts the right thing at the approriate place like a footer
for instance. I want to do this locally without using SSI's on a web
server.

What I did was slurp the text I want inserted into an array and try
and replace the file but no go for some reason.

Here's some potted code. It's looking for $HEADER in the html file

open (MYFILE, header.txt);
@header = <MYFILE>;
close MYFILE;

and then open the file I want replaced and...
open (BASEFILE, +< base.html);
$insertline = <BASEFILE>;
while ($insertline ne "") {
  if ($insertline =~ /\$HEADER/) {
    $insertline =~ s/$insertline/@header/;
     $insertline = <BASEFILE>
  }
}

I hope that's right. I left my code in my other computer :)
Anyway, it gets all the way down to the replacement section and dies
for some reason. I tried making it 
$insertline =~ s/$insertline/@header/e; 
but no go there as well as well as various other permutations as my
limited skill would allow.

If someone (and I know you do) as an easy fix (and I know there is)
I'd like to know :)

Cheers,
 Graeme

 


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

Date: Fri, 16 May 1997 23:40:23 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: I need a programmers assistance...
Message-Id: <337D36B7.4B93FC2D@gpu.srv.ualberta.ca>

Nathan V. Patwardhan wrote:
> 
> winnt@winnt.icss.com wrote:
> 
> : 7
> : 8
> : 9
> : 15
> : ,add all the numbers line by line and
> : print out the total. All that I've been
> 
> perl -e '$i=0; while(<>){$i+=$_;} print $i,"\n";' number_file.txt
> 
  
you initialized variables but didn't use -w, I'll go the
opposite way and use -w but no explicit variables :-)

  perl -we 'print eval join("+",<>),"\n"' filename

regards
andrew


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

Date: 17 May 1997 06:41:50 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: inclu-OR in regex
Message-Id: <5ljjve$ern$1@dartvax.dartmouth.edu>

In article <5ld200$p49$1@mathserv.mps.ohio-state.edu>
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:

> [A complimentary Cc of this posting was sent to Eli the Bearded 
> <usenet-tag@qz.little-neck.ny.us>],
> who wrote in article <5lcr2h$u7e$1@news.netusa.net>:
> > alex <alex.t.silverstein@bender.com> wrote:
> > > I want to match the letters a b and c in a string at least once
> > > but in any order. The part I don't get is how to say "in any order"
> 
> In fact the question taken in LITERALLY is answered by
>         /[abc]/;
> but I do not think it is what the author was intending... ;-)

I completely disagree.  The original question quite clearly states,
"the *letters* a b *and* c" [my emph., obviously], not "the letter a or
the letter b or the letter c".

Chipmunk


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

Date: Sat, 17 May 1997 13:49:57 +0100
From: John Speight <jspeight@mselva.demon.co.uk>
Subject: Re: Is there a port for NT
Message-Id: <0iDB8DA1lafzEwI9@mselva.demon.co.uk>

Ok guys,
sorry for not reading the FAQ (my excuse is that I had only an hour's
internet access from getting home to going back to work in which to see
if PERL - amongst many other possibilities - could be used on AIX, NT,
HP-UX, etc, etc)

Thanks for your help
-- 
John Speight


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

Date: Sat, 17 May 1997 09:16:38 GMT
From: Terry Kennedy <terry@spcuna.spc.edu>
Subject: Re: More trouble with Syslog
Message-Id: <EABJ3q.32n@spcuna.spc.edu>

Bernard Cosell <bernie@rev.net> writes:
> I commented out that call to hostname at line 92, but now I'm still
> getting funniness.  When I run the program it gets:
> Identifier "Sys::Syslog::args" used only once: possible typo at (eval 22) line 2.
> Identifier "Sys::Syslog::y" used only once: possible typo at (eval 27) line 2.

  I just ran into this - it's some sort of problem with the script that con-
verts the system includes into ones suitable for perl not checking to see if
things are ever used. I made the following hack at fixing it:

*** sys/syslog.ph.orig	Tue Jan 21 00:11:16 1997
--- sys/syslog.ph	Sat May 17 02:35:14 1997
***************
*** 70,75 ****
--- 70,76 ----
      if (!defined &KERNEL) {
  	require 'machine/ansi.ph';
  	require 'sys/cdefs.ph';
+ 	use vars qw($protos $y);
      }
  }
  1;

  Note that this will break any perl 4 scripts that try to syslog, since
the older version doesn't understand "use vars".

  I didn't see the start of this discussion (I don't normally follow this
group) but I think you'll have other problems if you comment out the host-
name stuff in syslog.ph, since the hostname is used to connect to syslogd
(I suppose you could code in localhost if you absolutely had to). Also,
make sure your syslogd is listening to the syslog port - lots of newer sys-
tems don't listen by default (filling up the logs seems to be a common
denial of service attack).

	Terry Kennedy		  Operations Manager, Academic Computing
	terry@spcvxa.spc.edu	  St. Peter's College, Jersey City, NJ USA
        +1 201 915 9381 (voice)   +1 201 435-3662 (FAX)


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

Date: 16 May 1997 17:00:40 GMT
From: Bob De Wolf <rdewolf@msmail2.hac.com>
Subject: Re: New draft of scripting white paper
Message-Id: <5li3ro$7f3@hacgate2.hac.com>

In article <3376A8FB.65F3@dis.org> Cimarron Taylor, cimarron@dis.org
writes:
>I disagree. The domain-specific languages you can build with Tcl 
>are pretty much limited to the variations of the simple procedural
>constructs Tcl and most other shell languages have.  Tcl is really
>just a variation of /bin/sh which makes it easy to run commands in 
>the same process.  
>
>To put it another way, I've never heard anyone speak of extending the 
>"programming paradigm" of /bin/sh when they create a new executable.
>Why should that terminology apply to Tcl?

Not really.  The statements provided by /bin/sh et all are hard coded in
the interpreter.  The tcl interpreter does not define language
statements, only language structure.  Statements and procedures are the
same in tcl.  With the tcl 'proc' command you can add a new statement
(you can also do this with 'c').  To demonstrate this, you can add an
'until' statment to tcl with a four or five lines of tcl in a 'proc'
command (you could also use 'c').  'until' does the same thing as 'while'
except that the logic inverted.  I don't think you can do this kind of
thing with /bin/sh or anything derived from it.  You can't do it with c
or c++, pascal, ... etc, etc.

Another interesting feature of tcl is that it has no operators (in
particular, no replacement statement ).  This eliminates the problem of
type-matching that is endemic to languages that use the replacement
statement.  I think using the '=' sign in a replacement statement came
to programming because people thought that, since computers do
arithmetic, we should program the same way we do mathematics.


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

Date: Sat, 17 May 1997 02:46:58 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Opening Javascript style windows with perl
Message-Id: <EAB12A.MIM@nonexistent.com>

On Sat, 17 May 1997 09:56:50 +0900, christopher wrote in
comp.lang.perl.misc URL: news:337D0252.1C63@inorbit.com:
++ This might appear to be a javascript question, but is more likely a perl
++ question (albeit rather cgi in form, apologies..)
++ 
++ When printing to the browser I know I can print to a new window using
++ Window-target, could someone direct me to or tell me what the perl
++ syntax is for sending the window attributes to the browser too (ie size,
++ toolbars etc etc) ?


It's not a Perl question at all.

You cannot even use Perl for it.

It's a Javascript thingy.

Go and find a javascript group, like rec.pets.mozilla.



Abigail


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

Date: Sat, 17 May 1997 13:23:49 +0300
From: Allon Henig <ahenig@iil.intel.com>
Subject: perl and awk
Message-Id: <337D8735.1132@iil.intel.com>

Hi, 
	I want to do an awk command in a perl program. If it was in the shell I
would have done:

awk '{FS=".";print $2}' filename

but since I need to use it in the perl program, I need to use the
'system' command which uses the "" it'self:

system (" awk '{FS=".";print $2}' filename    ");

this of course causes an error because of too much "" . Do you have any
suggestions how to overcome this problem ?

		Thanks, Allon


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

Date: 17 May 1997 09:55:55 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: POP V3 implementation in Perl..Has anybody implemented it?
Message-Id: <memo.19970517105613.8781B@skep.compulink.co.uk.cix.co.uk>

In article <337d0898.921118@news.jaring.my>, hcs@pc.jaring.my
(Harichandran Sukerathavan) wrote:

> Hey,
>
> I'm looking for a perl implementation of the POPV3 protocol....can
> somebody let me know if anybody has done it. I'm planning to implement
> a mail reader via browser, where the mail is retrieved using the POP
> protocol.
>

Yup, you need Libnet and Mailtools from the CPAN archive.

Regards
Neil



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

Date: 17 May 1997 09:40:36 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: POP V3 implementation in Perl..Has anybody implemented it?
Message-Id: <5lkcgk$q2@panix.com>

In <337d0898.921118@news.jaring.my> hcs@pc.jaring.my (Harichandran Sukerathavan) writes:

>I'm looking for a perl implementation of the POPV3 protocol....can
>somebody let me know if anybody has done it. I'm planning to implement
>a mail reader via browser, where the mail is retrieved using the POP
>protocol. 

My first inclination would be: Mail::POP3Client -- "It provides an 
object-oriented interface to a POP3 server, and it can be used to 
write perl-based biff clients, mail readers, or whatever."

 -- http://www.perl.org/CPAN/modules/by-module/Mail/
  
-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Fri, 16 May 1997 20:06:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: John Moreno <phenix@interpath.com>
Subject: Re: regrex question - really basic!
Message-Id: <Pine.GSO.3.96.970516200111.16343G-100000@kelly.teleport.com>

On Thu, 15 May 1997, John Moreno wrote:

> From: John Moreno <phenix@interpath.com>

Well, that's a new way to spell it. I thought I'd seen them all. :-)

> Subject: regrex question - really basic!

Well, that's a new way to spell it. I thought I'd seen them all. :-)

> I am trying to do a extract a email address out of a string using a
> regular expression. 

Okay.... As long as you're not trying to detect whether it's a _valid_
e-mail address. 

> I'm using [^ <]+@[^ \r,>]+ which works as a regular expression.  The
> problem is getting this into a perl statement.

Maybe you want something like this? This will extract something which
matches that pattern from $some_string. You'll get undef if there's not a
match. Hope this helps! 

    ($address) = ( $some_string =~ /([^ <]+@[^ \r,>]+)/ );

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 17 May 1997 08:54:23 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: Save Programming?
Message-Id: <337d70f3.35677852@news.oz.net>

On Fri, 16 May 1997 16:09:37 +0200, Alex `Taker` Pircher
<pircher@informatik.tu-muenchen.de> wrote:

>And is there a easy way to remove nearly all special characters, so
>that the $file contains only: A-Z a-z / _ -

Use character classes:
$file =~ s/[^\w\-\/]//g; # \w includes 0-9 also


-- Tim Gim Yee             tgy@chocobo.org
http://www.dragonfire.net/~tgy/moogle.html
"Will hack perl for a moogle stuffy, kupo!"


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

Date: Fri, 16 May 1997 05:53:32 -0400
From: Jason Moore <jmoore@deleuze.informinteractive.com>
To: A.Huebsch@magnet.at
Subject: SOLN: Installing PerlScript - 306 bad - 303 ok.
Message-Id: <337C23C7.3377C6A7@deleuze.informinteractive.com>

Hi,

I had similar problems installing perlscript 306 on NT server.  For some
reason the dll couldn't be registered through the perl installation
script or using "regsvr32 perlse.dll".  

i downloaded an older version which installed properly and the sample
 .asp files now work.

ftp://ftp.activeware.com/Perl-Win32/beta/PlSEi303.EXE

:jason 

-- 
 .......................................................................
jason moore                                               
416.595.5232   
Internet Applications Developer                      Inform Interactive
jmoore@deleuze.informinteractive.com   http://www.informinteractive.com


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

Date: Sat, 17 May 1997 08:09:28 GMT
From: brian@brie.com (Brian Lavender)
Subject: Re: Sorting Associative by Values?
Message-Id: <337d6681.14507222@nntp.netcruiser>

posted and cc-ed to author

On Fri, 16 May 1997 15:15:00 -0400, Thom Brooks <thomthrd@umich.edu>
wrote:

>Hello. I'm a newbie with a probably very repetitive question, so I
>apologize if I've posted this for the millionth time, or to the wrong
>place.

Well, we are all beginners of what we are about to do.

>If anybody could be kind enough to answer this, would you cc: it to my
>email, thomthrd@umich.edu, and to the newsgroup so people know my
>question was answered? I don't have a lot of time to read the newsgroup
>(or I probably would've seen the solution already, right? :)

Randal Schwartz wrote an interesting column regarding the finding of
the number of times a word occurs in a file. It is pretty trick.
Offhand I can't say directly how you would modify it to get what you
want, but I am sure it will give you some good clues.

http://www.stonehenge.com/merlyn/UnixReview/col02.html

Brian
----------------
Brian Lavender
Napa, CA
Brie Business Directory - Napa Valley     http://www.brie.com/bbd 
(707) 226-8891

"Have you heard of the new improbability drive?"


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

Date: 17 May 1997 06:51:26 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: splitting text
Message-Id: <5ljkhe$ern$2@dartvax.dartmouth.edu>

Zachary Brown wrote:
> 
> I'm having a tough time with the following problem:
> 
> How to split along the boundary between space and nonspace.

You don't need to split on the boundary between space and nonspace:

@a = split(/(\s+)/, $foo);

since using parentheses in the split pattern saves the delimiters in
the array.

Chipmunk


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

Date: 17 May 1997 07:03:17 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: swallowing whitespace
Message-Id: <5ljl7l$bhv$1@dartvax.dartmouth.edu>

In article <337B5F36.41C67EA6@bbb.caltech.edu>
Venkat Jagadish <venkat@bbb.caltech.edu> writes:

>         I tried the following :
>         
>                 s/(\s+)(^[\n])(.*)/$2$3/g ;

^[\n] matches a newline at the beginning of a line.
[^\n] matches any character other than a newline (as does . in the
normal case)
I assume this typo does not occur in your actual code, as you would not
get the results described below.

>         but when the default pattern space ($_) encounters a line 
>         such as
> 
>         "login name@host.    network.domain"
>               ^           ^
>               |           |
> 
>           (single ws)   (3 successive ws)
> 
>                 
>         the above substitution yields
> 
>         "loginname@host.   network.domain"
> 
>  Apparently, it matches a single whitespace followed by a   
>  non-whitespace character but not successive whitespace (excluding
>  line-break) characters. 
> 
>  The surprising thing is that it works when I rerun the script
>  on this modified file once more.
>  I thought the /g modifier should take care of matching all 
>  the occurrences in one shot.

That's because * is greedy, so .* matches the rest of the string. 
Thus, there is only one occurence of your pattern in the string.  It
has nothing to do with a single whitespace versus consecutive
whitespace.

Basically, your regexp does not do what you expect.
/(\s+)([^\n])(.*)/ matches one or more whitespace characters, followed
by any character other than a newline (the next character can't be a
newline anyway, because a newline would match \s+), followed by 0 or
more characters other than a newline.  It matches from the first
whitespace to the end of the string.
Try this instead:
s/[ \t]+//g;
which removes all space and tab characters - i.e. whitespace other than
newlines.

Chipmunk


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

Date: 17 May 1997 11:55:00 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Tatum O'Neil
Message-Id: <5lk6ak$oon@pirate.shu.edu>

Hello -

abigail@fnx.com (Abigail) writes:

>On Fri, 16 May 1997 16:06:55 -0500, Paul T. McNally wrote in
>comp.lang.perl.misc URL: news:337CCC6E.3380@radiks.net:
>++ Does anyone know when the actress and Oscar winner Tatum O'Neil
>++ was born? I'm thinking she was born close to 3-6-62, but I knew more
>++ when I had this bitty crush about the time Bad News Bears came out.
>++ I need to know for it may become a vital part of my home page!!
>++ Very important!


>Djee, you can have some sympathy for those single digit IQ's who
>think any question about CGI belongs in a group about Perl.

>But posting a questions about an Oscar winner in a Perl group
>just because you might want to add it to your home page? I didn't
>know people with a negative IQ were allowed to touch keyboards.

At least it didn't start with "This is a question for Tatum O'Neal"
(a la "Randal Schwartz" posting a few days ago...).

David Black
dblack@icarus.shu.edu


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

Date: Thu, 15 May 1997 15:20:23 -0400
From: Paul Lussier <plussier@synnet.com>
Subject: Re: What's the quickest way in perl to determine if a scalar is a list?
Message-Id: <Pine.GSO.3.96.970515151816.5574L-100000@pickett>

daku@nortel.ca (Mark Daku) writes:

> I'm looking for the FASTEST way to locate a string in an array. By
> fastest I mean in cpu not in code style.

DEC Alpha 500Mhz CPU ;)

> I have a lot of arrays in my code I just want to speed up the validation.
> 
> EG:
> ----------
> @array = ("a","b","c","d","e","f");
> 
> $string = "a";
> 
> # were "isin" is my really fast look up code,  I've used it like an operator.
> # but it doesn't have to be a code block will do.
> if ( $string isin @array ) {
>   print "found it\n";
> } else {
>   print "Ah sucks it's not there!\n";
> }
> -----------
> I would really like to have the exists function work on arrays as well.

	foreach $element (0..$#array){
	  if ($array[$element] =~ /$string/) {
	    print "found it in \$array[$element]\n";
	  }
	}

Or, alternatively:

	print "found it\n" if (join (' ', @array) =~ /$string/);

Or even:

	print "found it\n" if (grep ($string, @array));

I think the grep is the most efficient of these 3 methods.  There are probably 
several other ways to do this, and I'm sure browsing the man pages would reveal
them all.  But I leave that as an excercise for the reader :)
-- 

Seeya,
Paul
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Paul Lussier		=   It is a good day	=The next best thing to doing -
= 3Com S2 Division	-    to put slinkies	-something smart is not doing =
- plussier@synnet.com	=     on escalators	=      something stupid.      -
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
     =			      Interesting trivia:			-
     -   If you took all the sand in North Africa and spread it out	=
     =		 ...it would cover the entire Sahara desert.		-
      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



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

Date: Sat, 17 May 1997 09:10:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: What's the quickest way in perl to determine if a scalar is a list?
Message-Id: <EABIu2.87y@nonexistent.com>

On Thu, 15 May 1997 15:20:23 -0400, Paul Lussier wrote in
comp.lang.perl.misc,comp.lang.perl.modules URL: news:Pine.GSO.3.96.970515151816.5574L-100000@pickett:
++ daku@nortel.ca (Mark Daku) writes:
++ 
++ > I'm looking for the FASTEST way to locate a string in an array. By
++ > fastest I mean in cpu not in code style.
++ 
++ DEC Alpha 500Mhz CPU ;)
++ 
++ > I have a lot of arrays in my code I just want to speed up the validation.
++ > 
++ > EG:
++ > ----------
++ > @array = ("a","b","c","d","e","f");
++ > 
++ > $string = "a";
++ > 
++ > # were "isin" is my really fast look up code,  I've used it like an
++ > operator.
++ > # but it doesn't have to be a code block will do.
++ > if ( $string isin @array ) {
++ >   print "found it\n";
++ > } else {
++ >   print "Ah sucks it's not there!\n";
++ > }
++ > -----------
++ > I would really like to have the exists function work on arrays as well.
++ 
++ 	foreach $element (0..$#array){
++ 	  if ($array[$element] =~ /$string/) {
++ 	    print "found it in \$array[$element]\n";
++ 	  }
++ 	}
++ 
++ Or, alternatively:
++ 
++ 	print "found it\n" if (join (' ', @array) =~ /$string/);
++ 
++ Or even:
++ 
++ 	print "found it\n" if (grep ($string, @array));
++ 
++ I think the grep is the most efficient of these 3 methods.  There are
++ probably 
++ several other ways to do this, and I'm sure browsing the man pages would
++ reveal
++ them all.  But I leave that as an excercise for the reader :)


Actually grep can't be the most efficient; at least not always. Consider:

@array = ('aaaa' .. 'zzzz', 'foo');
and search for 'foo'.

grep will always go through the entire array, while the following
exists quickly:

$i = $#array + 1;
while ($i --) {do { print "Found it!\n"; last; } if $array [$i] eq 'foo';}


grep will always do n tests, while a loop will do n test for unsuccesfull
match, but an expected n/2 tests for a succesfull match.


If you have to do several searches, building a hash out of the array
first will win.



Abigail


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

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

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


------------------------------
End of Perl-Users Digest V8 Issue 492
*************************************

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