[16632] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4044 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 17 09:15:28 2000

Date: Thu, 17 Aug 2000 06:15:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966518118-v9-i4044@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 17 Aug 2000     Volume: 9 Number: 4044

Today's topics:
    Re: Certain Items in a string <nickco3@yahoo.co.uk>
    Re: Certain Items in a string <nickco3@yahoo.co.uk>
    Re: Checking if variables exist <abe@ztreet.demon.nl>
        close window <radjis@hotmail.com>
    Re: cookie problem (Colin Keith)
    Re: crypt function (Colin Keith)
    Re: date and time in perl (Mike Stok)
    Re: Fork & Waitpid (Anno Siegel)
    Re: GD.pm Test Fails? (Martien Verbruggen)
    Re: How do I send data to another Server ??? (Colin Keith)
    Re: How to know if a scalar contain string or numeric d (Colin Keith)
    Re: HTTP_REFERER (Colin Keith)
    Re: Listing users in Win NT <clandos@bigfoot.com>
        lucky7.to - What a lucky Free URL Redirection Service! (Christine)
    Re: LWP nukes user alarms? <gisle@ActiveState.com>
        MS Access (Mauri Heinonen)
        newbie - documentation <gecco@gundam.com>
    Re: Newbie - print here problem <wyzelli@yahoo.com>
    Re: perl 5.6 (Eric Bohlman)
        PERL/TK AND WIDGETS <dunfeeje@pilot.msu.edu>
    Re: problems installing DBD::oracle for oracle-db-acces rudi_runkel@my-deja.com
        problems with Tk and NT4 <jemand@klop.com>
    Re: Regex Alternation Question nobull@mail.com
    Re: Sorting is very slow (Anno Siegel)
    Re: Split Stumper jon_nixon@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 17 Aug 2000 13:05:07 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: Certain Items in a string
Message-Id: <399BD4F3.AA02B060@yahoo.co.uk>

Ben Kennedy wrote:

> "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote

[snipped usual garbage]

> I appreciate your posts because they help me work on my patience skills.  If
> only people were more patient!
>
> --Ben Kennedy

I love Godzilla posts. I actually took her out of my killfile because I was
missing the entertainment so much. I'd see bits quoted by Larry, et al and I
kept going over to Deja to see what I'd missed.

-- Nick



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

Date: Thu, 17 Aug 2000 13:35:41 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: Certain Items in a string
Message-Id: <399BDC1D.EC922D6@yahoo.co.uk>

"Godzilla!" lost her rag thusly:

> Larry Rosler attempts to cover for his hatred:

and

> introducing hatred

and

> malice intent and hatred.

and

> a chance to be hateful

and

> elected to tell lies.

and

> an ignorant hateful lying arse

and

> simply flat out lying with malice intent.

and

> utterances of a serious hateful nature holding great
> malice intent,

and

> contextual lie

and

> more hateful remarks.

and

> a chance to be repugnantly hateful

and

> with disregard for your personal image.

and

> Your article is pure hatred.

and

> zero tolerance policy regarding hatred.

and

> Your hatred is repugnant

and (my personal favorite)

> and leads me to believe, like many others
> here in this newsgroup, you are not of healthy mind.

and

> Your hatred and routine expressions of hatred

and

> Your hatred may curl the lips of all others here into
> a smug smile

and the finale

> As much as you would love to escape a backslash to
> excuse your abhorrent behavior, you won't escape
> this shameful display of sociopathic hatred fitting
> only for a cretin, a display your unhealthy ego
> commanded you to foolishly make a stage event.

I think this is what the psychiatrists refer to as "projection". And
just in case you all missed it the first time:

> and leads me to believe, like many others
> here in this newsgroup, you are not of healthy mind.

It would explain a lot, wouldn't it?
--
Nick




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

Date: Thu, 17 Aug 2000 14:05:51 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Checking if variables exist
Message-Id: <n9jnpscp3h7nhfnqbjvrgcvo8g802d21tj@4ax.com>

On Thu, 17 Aug 2000 04:59:48 GMT, Todd Eddy <vrillusions@mail.com>
wrote:

> I didn't think you would need the rest of it, since it really won't effect this
> in any way, so I thought I would just post that to save a little on the loading
> time.  So heres the whole thing:
> 
> #!/usr/bin/perl
No warnings, no Taint checking, no strictness; Some CGI you're doing
there.

	#!/usr/bin/perl -wT
	use strict;

> ###############
> # Form Processing Section
> #########################
> # Determining whether or not the <FORM> method is GET or POST
> # if it is GET, that means all the data was appended to the URL
> # if it is POST, all the data was put into STDIN, a data buffer

Please stop doing that. There is a module that does this for you (and
better).

While you are studying the documentation that comes with CGI.pm, 'fix'
your script like:

	use CGI qw(:standard);
	use CGI::Carp 'fatalsToBrowser';

	my %FORM = map { $_ => param($_) } param();

And start using the tools suitable for the job, it's all in the CGI.pm
package.

> # Send data as html
> ###################
> print "Content-type: text/html\n\n";

	print header;

> # Parsing the variables
> #######################
> $date = $FORM{'LAN_Date'};
> $newdate = $date;
> $newdate =~ tr[/][-];   # replace /es with -es
> @filedate = split(/-/, $newdate);
> if ($filedate[0] < 9) { $filedate[0] = "0".$filedate[0]; }
> if ($filedate[1] < 9) { $filedate[1] = "0".$filedate[1]; }
> $filedate = "20".$filedate[2]."-".$filedate[0]."-".$filedate[1];
> $datalocation = $datadir.$filedate.".df";

	my $datalocation = sprintf "${datadir}20%d-%02d-%02d.df",
		(split m!/!, param('LAN_Date'))[2, 0, 1];

[rest left as an exercise]

-- 
Good luck,
Abe


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

Date: Thu, 17 Aug 2000 14:32:53 +0200
From: "Flip" <radjis@hotmail.com>
Subject: close window
Message-Id: <8ngm3v$av7mh$1@reader3.wxs.nl>

Could anybody tell me what the perl command is to close the current
browserwindow

thanks.




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

Date: Thu, 17 Aug 2000 10:41:05 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: cookie problem
Message-Id: <5jPm5.153$DT4.3920631@nnrp2.clara.net>

In article <399AC531.74F53800@taiwan.com>, MartinQz <martinqz@taiwan.com> wrote:
>Thanks for your help first, but because I am new to perl programming and the
>deadline is coming, I don't have enough time to study the CGI.pm, so I need
>to use the current method to implement the cookie program.

Type perldoc CGI::Cookie.
The example you will see is extremely simple and you can just copy it into 
your code.  For example your code and its errors can be compressed into 
this:

  use CGI qw(:standard);
  use CGI::Cookie;
  my(%cookies) = CGI::Cookie->fetch();   # get the cookies

You have your data ...

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Thu, 17 Aug 2000 08:53:32 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: crypt function
Message-Id: <gKNm5.151$DT4.3918652@nnrp2.clara.net>

In article <8neaoq$tid$1@nnrp1.deja.com>, sankarmukh@my-deja.com wrote:
>In article <3999d081.10891009@news1.tninet.se>,
>  jonas.nilsson@mbox326.swipnet.se (Jonas Nilsson) wrote:
>> I have a text file with username:password, the password is crypt. I
>> want to have an: "e-mail me my password because I forgot it"
>> -function. When I do that I only get the crypted version. How do I
>> decrypt the password.
>>
>> Thanks.
>> Jonas N
>>
>
>Apparently there is: I posted the following mail, but nobody replied.
>May be you can figire it out.
>
>*******************************************************************
>I copied the decrypt subroutine from a FAQ:
> But this is giving me syntax error. What is wrong here?
> Any advice is appreciated.
>
> **************************************************************
>
> #!/usr/local/bin/perl -w
> $crypted=crypt(smuk_012,"cm");
> print "$crypted";
> print "\n";
> &decrypt;
> sub decrypt {
>             $crypted = shift;
>             local $" = "";
>             foreach $x[0] ("\x00" .. "\xFF") {             foreach
>$x[1] ("\x00" .. "\xFF") {             foreach $x[2] ("\x00" .. "\xFF")
>{
>     foreach $x[3] ("\x00" .. "\xFF") {             foreach $x[4]
>("\x00" .. "\xFF") {             foreach $x[5] ("\x00" .. "\xFF") {
> foreach $x[6] ("\x00" .. "\xFF") {             foreach $x[7] ("\x00" ..
>"\xFF") {                 return "@x" if $crypted eq crypt "@x",
> $crypted;             
>         }
> print "\n";
> print "$crypted";
> ~
> ~
> "crypt_san.pl" 21 lines, 669 characters
> devwk77:/u/ctssmuk> crypt_san.pl
> syntax error at crypt_san.pl line 9, near "$x["

In "foreach $x[0] ( .. )" you can't assign to an array element, you can only 
assign to a scalar. Perlsyn man page: "foreach probably won't do what you 
expect if VAR is a tied or other special variable.   Don't do that either."

> syntax error at crypt_san.pl line 18, near "}}"
This is because of the above syntax error

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Thu, 17 Aug 2000 12:19:55 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: date and time in perl
Message-Id: <LLQm5.7243$K5.121904@typhoon.austin.rr.com>

In article <MPG.1405c827c1c4d13d9896b3@localhost>,
jason  <elephant@squirrelgroup.com> wrote:

>and corrected (or improved depending on how generous you're feeling) .. 
>improper use of 'local' instead of 'my' .. two arrays (months and days) 
>created and never used .. unecessary escaping of colons in double-quoted 
>strings .. unecessary use of ampersand on function call
>
>and that's forgetting the fact that (apart from leading zeros on days 
>and months less than 10) Lincoln's code can be replaced by two lines
>
>  use POSIX;
>  $main::time = POSIX::strftime( '%m/%d/%Y at %H:%M:%S' => localtime);

You might want to have a look at the memory cost of a plain

  use POSIX;

in a perl program - it's a little more than a couple of unused arrays.  Also
using POSIX like that imports many symbols into your namespace.  The POSIX::
prefix is not necessary in your code snippet.

  use POSIX 'strftime';

  $::time = strftime( '%m/%d/%Y at %H:%M:%S', localtime );

will reduce namespace "pollution" and still tell the reader of the code where
strftime came from.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: 17 Aug 2000 11:37:05 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Fork & Waitpid
Message-Id: <8ngip1$ld1$1@lublin.zrz.tu-berlin.de>

Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote in comp.lang.perl.misc:
>I was shocked! How could andrewjasper@my-deja.com <andrewjasper@my-deja.com>
>say such a terrible thing:
>>I'm using fork and waitpid, but waitpid keeps returning an error value
>>of 256 after the process has already been forked.
>>
>>Does anyone have any ideas?
>
>Hmm I think you should read "perldoc perlvar" for an explanation of what
>$? actually is. You need to do something like "$? >> 8" to get the exit
>value. This will tell you that the exit() return value of your child
>process was 1.

Not to mention that what $? contains is not an indication that
waitpid() failed.  It's the return code of the (now terminated)
process.  See perldoc -f waitpid.

Anno


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

Date: 17 Aug 2000 11:34:35 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GD.pm Test Fails?
Message-Id: <slrn8pnilf.6h5.mgjv@martien.heliotrope.home>

On Wed, 16 Aug 2000 17:23:59 GMT,
	brudden@goebusiness.com <brudden@goebusiness.com> wrote:
> 
> PERL_DL_NONLAZY=1 /raid1/perl5.6.0/bin/perl -Iblib/arch -Iblib/lib 
> -I/raid1/perl5.6.0/lib/5.6.0/sun4-solaris -I/raid1/perl5.6.0/lib/5.6.0 -e 
> 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
> t/GD................Can't load './blib/arch/auto/GD/GD.so' for module GD: 
> ld.so.1: /raid1/perl5.6.0/bin/perl: fatal: relocation error: file 
> /usr/local/lib/libgd.so.4: symbol jpeg_resync_to_restart: referenced 
                                    ^^^^
> symbol not found at /raid1/perl5.6.0/lib/5.6.0/sun4-solaris/DynaLoader.pm 
> line 200.
>  at t/GD.t line 11

> I have the libs installed :libpng, libz.  Everything built with the same 

And do you have the JPEG libraries installed? That's the symbol that
can't be found. And if they are installed, can they be found by your
linker? On solaris you probably will need to have the path to the
library in your LD_LIBRARY_PATH environment variable.

> compiler (gcc).  Looking at the README.unix, they mention a similar issue 
> on Linux related to dynamicaly loading modules but no mention of how to
> fix it on solaris(if that issue is even related).  Any ideas? 

\begin{offtopi}

How did you get libgd compiled as a shared library? With a lot of work?
Last time I checked it was only suppurted as a static library,
notwithstanding how people like RedHat distribute it.

\end{offtopic}

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: Thu, 17 Aug 2000 09:00:05 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: How do I send data to another Server ???
Message-Id: <pQNm5.152$DT4.3918707@nnrp2.clara.net>

In article <399AB493.AFAF3792@lmc.ericsson.se>, "Mirko Bulovic (LMC)" <lmcmibu@lmc.ericsson.se> wrote:
>fetch from requires a username and password. I can't find in LWP how to send
>a username and password with my request?

Please, try and read the documentation you were given. It would save you 
time rather than waiting for a reply.

In the LWP::UserAgent man page there is a description of the function 
credentials() (and get_basic_credentials())


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Thu, 17 Aug 2000 10:47:31 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: How to know if a scalar contain string or numeric data?
Message-Id: <7pPm5.154$DT4.3920128@nnrp2.clara.net>

In article <8nfb63$fjq@netnews.hinet.net>, sth@ms1.hinet.net () wrote:
>     the "~" part.
>         ~$x ne ~"$x" ? 'numeric' : 'string'

There's a nice description in the perlop man page in the "Bitwise String 
Operators" section.

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Thu, 17 Aug 2000 10:49:58 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: HTTP_REFERER
Message-Id: <qrPm5.155$DT4.3920838@nnrp2.clara.net>

In article <8nee3t$1pv$1@nnrp1.deja.com>, Rich More <rmore1@my-deja.com> wrote:
>Try $ENV{SCRIPT_FILENAME}

Except that is nothing to do with the variable set in $ENV{HTTP_REFERER}. 
The referer is set by the user agent to the page it just came from, but it 
doesn't have to send it.

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Thu, 17 Aug 2000 14:36:02 +0200
From: "uunet" <clandos@bigfoot.com>
Subject: Re: Listing users in Win NT
Message-Id: <399bdc35$0$29239@personalnews.de.uu.net>

http://www.activestate.com/Products/ActivePerl/
has an perl that supports windows nt user and group and domain functions in
win32

Win32::NetAdmin - manage network groups and users in perl

LoggedOnUsers(server, userRef)

Gets an array or hash with the users logged on at the specified computer. If
userRef is a hash reference, the value is a semikolon separated string of
username, logon domain and logon server.


Carsten

jason <elephant@squirrelgroup.com> schrieb in im Newsbeitrag:
MPG.1405d56f120a80fa9896b7@localhost...
> Dr. Peter Dintelmann wrote ..
>
> >s24673 schrieb in Nachricht <3999e546.0@scctn03.sp.edu.sg>...
> >>Does anyone know how to list the users who are logged on in Win NT using
> >>Perl?
> >
> >    usually there is only one user logged in. You will
> >    find the username in $ENV{USERNAME}.
> >    If you are interested in a listing of available logins
> >    on NT have a look at the GetUsers() method in
> >    Win32::NetAdmin.
>
> 'usually' ? .. that's a simply incorrect answer .. certainly it would be
> true for the majority of NT workstations .. but NT hosts providing FTP
> or HTTP services .. or print services .. or NT domain services will
> usually have many more than one user logged in
>
> the Win32::NetAdmin module provides a method to view the logged in users
>
>   perldoc Win32::NetAdmin
>
> for more information
>
> --
>   jason -- elephant@squirrelgroup.com --




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

Date: 17 Aug 2000 12:52:22 GMT
From: kittychim@sinagirl.com (Christine)
Subject: lucky7.to - What a lucky Free URL Redirection Service!
Message-Id: <8ngn66$kn0$14@news.ctimail.com>

lucky7.to - What a lucky Free URL Redirection Service!

If the URL of your homepage is too long and too complex,
e.g. www.free3hostingg.com/myaccount/index.html
e.g. www.uuwaterlooooo.edu/cs/~tommy/index.html

Instant Activiation!!!
After signing up, you can have a free 
and a short URL and use it immediately as follow:

e.g. lucky7.to/tom

Please visit http://lucky7.to
to sign up for your own FREE URL

I hope you will enjoy using our Free service.

Thank you very much.





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

Date: 17 Aug 2000 12:06:10 +0200
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: LWP nukes user alarms?
Message-Id: <m38ztwnqwd.fsf@eik.g.aas.no>

David Coppit <newspost@coppit.org> writes:

> I'd like to be able to put a time limit on my script, which is using LWP.
> Unfortunately, it looks like LWP is using alarm() for its timeouts, which is
> not interacting well with my alarms.

LWP has not used alarm() since Dec 1997 (release 5.18), but LWP still
use IO::Socket and some older versions of that module use alarm to
timeout connect.  Make sure you have IO-1.20 and things should be ok.

-- 
Gisle Aas


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

Date: Thu, 17 Aug 2000 12:26:46 GMT
From: mauri.heinonen@kopteri.net (Mauri Heinonen)
Subject: MS Access
Message-Id: <399bd9f1.113181756@news.kopteri.net>

Hi

How I can you in WinNT MS Access in my own perl-scripts wich i make
with activeperl? Wich is that module and where i can download it???

I hope someone helps me!!!

Mauri Heinonen
mauri.heinonen@kopteri.net


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

Date: Thu, 17 Aug 2000 11:28:37 GMT
From: Gecco th Ruled <gecco@gundam.com>
Subject: newbie - documentation
Message-Id: <399BCC62.11639713@gundam.com>

where i can find the dicumentation onf Net:IRC?
i search the documentation of command like

        $self->join("#IRC.pm");
        $self->privmsg("#IRC.pm", &pickrandom());
        $self->topic("#IRC.pm");

10x


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

Date: Thu, 17 Aug 2000 20:04:29 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Newbie - print here problem
Message-Id: <hdPm5.4$Ur2.606@vic.nntp.telstra.net>

<scottfreez@my-deja.com> wrote in message
news:8ng8lq$5qh$1@nnrp1.deja.com...
> print<<FINISH;
> Content-type: text/html
>
> hey there
> FINISH
>
> Can anyone tell me why this doesn't work?
>
> Here's the error message:
> CGI Error
>
> The specified CGI application misbehaved by not returning a complete set
> of HTTP headers. The headers it did return are:
>
> Can't find string terminator "FINISH" anywhere before EOF at
> C:\Inetpub\wwwroot\perl\flockansi.pl line 1.
>

Make sure there is a carriage return after the terminating 'FINISH'.

This is a FAQ.

Wyzelli




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

Date: 17 Aug 2000 12:30:57 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: perl 5.6
Message-Id: <8nglu1$sq3$4@slb7.atl.mindspring.net>

Randal L. Schwartz (merlyn@stonehenge.com) wrote:
: >>>>> "Eric" == Eric Bohlman <ebohlman@netcom.com> writes:
: 
: Eric> I think you mean 5.6.2.  Under the new numbering scheme,
: Eric> odd-numbered releases are developmental versions and
: Eric> even-numbered ones are production versions.
: 
: Wrong even/odd number.
: 
: 5.7.x is for Perl developer internal use (odd middle digit).
: 5.6.x is for Perl stable releases (even middle digit).

Thanx for the correction.



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

Date: Thu, 17 Aug 2000 08:49:27 -0400
From: Jeffrey Scott Dunfee II <dunfeeje@pilot.msu.edu>
Subject: PERL/TK AND WIDGETS
Message-Id: <399BDF57.EA92F138@pilot.msu.edu>

I'm trying to find a function that will return the name of a button I
have created, or some type of identifier that lets me know what button I
have pressed.  Perhaps return the label on the button, that would be
ideal. But I can not find any functions like this. Does anybody know
anything about PERL/TK enough to tell me if a function like this
exists... thanks

-jeff dunfee
dunfeeje@pilot.msu.edu




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

Date: Thu, 17 Aug 2000 10:29:01 GMT
From: rudi_runkel@my-deja.com
Subject: Re: problems installing DBD::oracle for oracle-db-access
Message-Id: <8ngep0$c88$1@nnrp1.deja.com>


> > I thought that there is no need to install any oracle-software when
I
> > want to connect to a oracle-db via perl on my suse-linux system. Am
I
> > wring or what do I make wrong?
> >
>
> You are wrong - you need the Oracle client libraries.
>
> /J\
>
And where do I get those libaries?

Thanks

Michael


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 17 Aug 2000 14:22:55 +0200
From: "chris" <jemand@klop.com>
Subject: problems with Tk and NT4
Message-Id: <8nglce$1ng$1@pollux.ip-plus.net>

hi all
i  get perl of a NT4 box with sp6 .
even when i try to start a perl with use::Tk i get a Dr.Watson.
can help me somone  ?
cu chris




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

Date: 17 Aug 2000 12:42:50 +0100
From: nobull@mail.com
Subject: Re: Regex Alternation Question
Message-Id: <u93dk4nmf9.fsf@wcl-l.bham.ac.uk>

Jonas Reinsch <Jonas.Reinsch@ppi.de> writes:

> $alt = "(" . join(")|(", @alt) . ")";

> @parens = $string =~ /$alt/;

> for ($i = 0; $i<@parens; $i++) {
>     if ($parens[$i]) {$part = $alt[$i];last}
> }

Might be maginally more efficient written as:

my $i = 0;
for ($string =~ /$alt/) {
     if (defined) {$part = $alt[$i]; last}
     $i++;
}

But that's still O(n).  I can see a way to make this O(log n) but it's
a lot more complex so unless n is huge I can't see it being worth the
overhead.  Even then I'm not sure it's better.

> Is there a more direct way to do this?

I don't think so.

Interestingly the answer to this question in the FAQ doesn't even
recommend combining the regular expressions into a single regex.
Perhaps you should Benchmark your approach against the one given in
the FAQ.

Of course, as the FAQ points out, a lot more time is likely to
consumed compiling /$alt/ so if this is all inside a loop over which
the set of patterns is invarient then compiling with qr// is likely to
be a far more significant saving in time.


-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 17 Aug 2000 12:17:15 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting is very slow
Message-Id: <8ngl4b$lib$1@lublin.zrz.tu-berlin.de>

Sean Malloy  <srmalloy@home.com> wrote in comp.lang.perl.misc:
>Jim Chim <mecks@ust.hk> wrote:
>>    I have write a code to sort some meteorological data which contain
>>281560 data point.
>>And write a sortin scheme to sort it. I know bubble sort only. I found
>>that it take more
>>than 10 hours to sort the data in PIII 800MHz machine. Can anyone give
>>me some idea
>>of how to improve the scheme so that it work faster. Thanks.
>>    My code is attached in this message.
>
>The bubble sort is an O(n^2) algorithm; that is, for any data volume
>n, the amount of time the sort takes is proportional to the square of
>n. It's a very bad sort algorithm, compared to others. Quicksort, for
>example is O(n ln(n)) -- for a data volume n, the amount of time it
>takes will be proportional to n times the natural log of n. So, for
>any volume of data, quicksort will be (n/ln(n)) times faster. For
>281560 data points, that comes out to 22438 times faster. For a
>processing time of ~10 hours with bubblesort, you would need less than
>1.75 hours with quicksort.

You don't understand what the O(f(n)) notation means.  Roughly speaking,
it means that there is a constant A such that for large n the runtime
of an algorithm is proportional to A*f(n).  So, if all you know is the
asymptotic behavior, there is no way to predict, for a specific case,
how big the gain of the faster algorithm will be over the slower one.
All you know is, that for some (probably large) n there is a point
where the fast method beats the slow one.

[snip of quicksort pseudocode]

Anno


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

Date: Thu, 17 Aug 2000 11:40:00 GMT
From: jon_nixon@my-deja.com
Subject: Re: Split Stumper
Message-Id: <8ngiue$gm7$1@nnrp1.deja.com>

#!/usr/bin/perl
use strict;

my $text = "'this',5,'is a test, to see',55,83,'if','anyone','can, get
it'";

# escape all the single quotes before splitting

$text =~ s/\'([^\']*)\'/\'\\\'$1\\\'\'/g;

foreach ( eval $text ) { print "$_\n" }


Sent via Deja.com http://www.deja.com/
Before you buy.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


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


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