[25456] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7701 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 27 14:05:24 2005

Date: Thu, 27 Jan 2005 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Jan 2005     Volume: 10 Number: 7701

Today's topics:
    Re: ASP Perlscript/VBScript Order of execution <tadmc@augustmail.com>
    Re: ASP Perlscript/VBScript Order of execution <tadmc@augustmail.com>
    Re: Bug in perl v5.8.5 Built for sun4-solaris.  Any pat (Anno Siegel)
        encrypting and decrypting with perl <mdudley@king-cart.com>
    Re: encrypting and decrypting with perl <nobull@mail.com>
    Re: FAQ 4.48 How do I shuffle an array randomly? <noreply@gunnar.cc>
    Re: FAQ 4.48 How do I shuffle an array randomly? (Anno Siegel)
    Re: FAQ 6.17 Why don't word-boundary searches with "\b" (Peter Scott)
    Re: How can I call a subroutine / function and not wait xhoster@gmail.com
    Re: how to use callback function xhoster@gmail.com
        I will pay for perl help <LilaDuncan@XSPAMhotmail.co.uk>
    Re: I will pay for perl help <1usa@llenroc.ude.invalid>
    Re: I will pay for perl help <LilaDuncan@XSPAMhotmail.co.uk>
    Re: Net::SSH::Perl sending output to STDOUT <news@chaos-net.de>
    Re: Old tutorial - now corrected <comdog@panix.com>
    Re: Old tutorial - now corrected <flavell@ph.gla.ac.uk>
        Replace scalar in another scalar <mark.harris.invalid@ukonline.co.uk.invalid>
    Re: Replace scalar in another scalar <news@chaos-net.de>
    Re: Replace scalar in another scalar <1usa@llenroc.ude.invalid>
    Re: Replace scalar in another scalar <mark.harris.invalid@ukonline.co.uk.invalid>
    Re: Replace scalar in another scalar <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Replace scalar in another scalar <spamtrap@dot-app.org>
    Re: Replace scalar in another scalar <do-not-use@invalid.net>
    Re: sorting just the largest values xhoster@gmail.com
    Re: sorting just the largest values (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Jan 2005 10:10:00 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: ASP Perlscript/VBScript Order of execution
Message-Id: <slrncvi4io.3rt.tadmc@magna.augustmail.com>

LinnAxis <janschiffman@hotmail.com> wrote:

> Out of curiostiy, why be so rude? 


I assume that you are referring to my second post to this thread?

It is standard netiquette to supply some context in replies so
that people will know what it is that you are replying to.


> If perhaps this question was better
> directed at a different newgroup. why not try to be helpful and, dare I
> say, polite?


Hello! Is there anybody in there?

My first post to this thread *was* helpful and polite.

Did you see that one?

It said you were in the wrong place, and showed you where the
right place was.

You characterized that as "unfriendly" in a followup.


> Certainly you must have better ways to direct your angst 


My angst-containing post was my 2nd post, which was in reply
to you whining about my helpfully friendly 1st post.

So the answer to "why be so rude?" is because I was just
responding to who FIRST introduced rudeness, namely you.

You reap what you sow.


> than at first
> time posters 


When you were a first time poster, I answered in a friendly
and polite manner.

When you made a followup, you were no longer a first-time poster,
you were a whiner.


> who are simply seeking information.


In the wrong place.

Knowing where the right place is would seem to be very helpful
in such a search. Take that help and run with it rather than
denigrating the person who volunteered that help.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 27 Jan 2005 10:19:41 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: ASP Perlscript/VBScript Order of execution
Message-Id: <slrncvi54t.3rt.tadmc@magna.augustmail.com>

LinnAxis <janschiffman@hotmail.com> wrote:

> I was referring to Tad McClellen .


But I made 2 posts in this thead, so we *still* don't know
what you were commenting on.

If you quote what you are commenting on, then there is no
round-and-round trying to figure out what it is in reference to.

Why don't you just quote what you are commenting on like everybody
else on Usenet does?


> This is a newgroup, not a way of life.


Newsgroups have their own set of rules about what is socially
acceptable, if you do something socially unacceptable it is
more reasonable to expect a comment on it rather than expecting
that it will pass unnoticed.

Secondly, an experience usenetter can see clearly from your posts in
this thread that you are NOT an experienced usenetter, despite your
implications to the contrary.

Trying to fool us into thinking that you know what you are talking
about in reference to Usenet netiquette isn't going to work. We
are an insightful lot...


> "violates the most basic rules of nettiquette" - a bit heavy handed for
> a newgroup posting.


How can "playing by the rules that everyone else plays by" be
characterized as "heavy handed"? "normal" or "expected" would
seem a more reasonable characterization.


> This thread bores me so I will continue no further.


Your thread has bored *thousands* of people around the world
who are interested in Perl, because it was not _about_ Perl.

The whole world will feel bad now because you won't participate
any longer!


> Clearly there are many people in this world who need distractions
> outside of the net.


Clearly there are people who claim to know a lot but do not know a lot.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 27 Jan 2005 18:23:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bug in perl v5.8.5 Built for sun4-solaris.  Any patch availabale?
Message-Id: <ctbbio$omu$2@mamenchi.zrz.TU-Berlin.DE>

Gancy <ganesh_tiwari@hotmail.com> wrote in comp.lang.perl.misc:
> Hello All,
> 
> Today I have posted a question regrdaing a core dump issue. I did more
> investigation on this and I found some more information.

[snip]

> Has anyone faced similar problem?? If any patch is available then
> please let me know.
> 
> ******************************
> My previous question was....
> 
> Here is the snipet of the perl script, I have perl version v5.8.5 built
> for sun4-solaris. I have run this script on thousands of 'c','C++'
> headers and source files. Runs smoothly as my new ESTEEM car. But i
> have one surce file toke.c in my test case. soon this scripts hits this
> file at it dumps. I have tried and still trying to debug, but still no
> solutions. If anybody can help me with this would be of great
> appreciation. I can uploaded source file (toke.c) as well as core file
> frames(core), if needed.
> 
> 
> #!/usr/bin/perl
> 
> 
> $np = qr{
> \(
> (?:
> (?>[^()]+ )
> |
> (??{ $np })
> )*
> \)
> 
> 
> }x;
> 
> 
> $funpat = qr/((\W)?(\*?\*?\w+)\s*($np))/;
> my $temp;
> 
> 
> open (FILE, "toke.c") || die "Cannot open file";
> 
> 
> while($temp = <FILE>)
> {
> $tstring.=$temp;
> 
> 
> }
> 
> 
> close FILE;
> 
> 
> get_fn_call($tstring);
> 
> 
> sub get_fn_call($){
> my ($cur_str) = @_;
> while( $cur_str =~ m/$funpat/g )
> {
> $4 =~ /^\(((.*\n*.*)*)\)$/;
> get_fn_call($1);
> 
> 
> }
> }

That's a horrible little program.  Whoever wrote it must have been high
on recursion.  The first time I saw it, I just averted my eyes.

Recursive regexes are fun but should probably not be used in production
code.  In particular note that the /(??{ code })/ construct is still
experimental, which means that bugs must be expected.

The regex recursion seems to go out of control on toke.c.  You can watch this
after the following modification to the definitions of $np and $funpat:

    our $count;
    my $np;
    $np = qr{
    \(
    (?:
    (?>[^()]+ )
    |
    (??{ $count ++; print "recurs $count\n"; $np })
    )*
    \)
    }x;

    use re 'eval';
    my $funpat = qr/(?{ $count = 0 })((\W)?(\*?\*?\w+)\s*($np))/;

With other files, the count in recurs stays below 10 or so.  With toke.c,
it counts up until something breaks.  That looks like an error in the
definition of $np (I'm not debugging this any further).  The bug in
Perl is that it doesn't recognize deep regex recursion.  That could
presumably be demonstrated by a simpler program.

If you want to file a bug, write that simple demonstration.  If you want
your program to run on toke.c, fix the regex, it's wrong.

If you want your program to be solid code, rewrite it from scratch,
probably based on Text::Balanced.

Anno


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

Date: Thu, 27 Jan 2005 12:38:00 -0500
From: Marshall Dudley <mdudley@king-cart.com>
Subject: encrypting and decrypting with perl
Message-Id: <41F926F7.DFC9C7AE@king-cart.com>

I have an application where I need to encrypt a bit of text, and then I
need to be able to decrypt it using a customer's key.  I want to make
sure that the key to decrypt is NOT on the server anywhere, so hackers
cannot get the decrypt key, which means I cannot use a symetrical key
pair since the encryption key will need to be on the server.

What I need is more like a public key cypher.  But I want the customer
to be able to create his own private unencrypt key (like a password),
and then the server generates the public encrypt key from that.  I do
not want the customer to have to enter a 128 or 1028 byte sequence each
time he executes the program, but to be able to enter a password he can
remember or have written down.

This is what I want.

1. When customer signs up, he enters a password.  The password is NOT
stored on the system, but is used to generate a nonsymetrical encryption
key, which is stored on the server.
2. Sensitive information is encrypted using the encryption key.
3. When the customer wants to see the sensitive information, he has to
log in, using the password he supplied in #1, and this is the decryption
key for the information. This password is never stored on the server,
but only passed from session to session with an ssl connection.

Are there any libraries that allow a nonsymetrical key pair, where the
encryption key can be generated from the decryption key that the
customer supplies?

Thanks,

Marshall



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

Date: Thu, 27 Jan 2005 18:14:18 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: encrypting and decrypting with perl
Message-Id: <ctban2$3ir$1@sun3.bham.ac.uk>



Marshall Dudley wrote:

> I have an application where I need to encrypt a bit of text, and then I
> need to be able to decrypt it using a customer's key.  I want to make
> sure that the key to decrypt is NOT on the server anywhere, so hackers
> cannot get the decrypt key, which means I cannot use a symetrical key
> pair since the encryption key will need to be on the server.

So the obvious choice would be PGP.  There's a module on CPAN with 
"Crypt" and "PGP" in the name that may help.

> What I need is more like a public key cypher.  But I want the customer
> to be able to create his own private unencrypt key (like a password),
> and then the server generates the public encrypt key from that.  I do
> not want the customer to have to enter a 128 or 1028 byte sequence each
> time he executes the program, but to be able to enter a password he can
> remember or have written down.

Sounds very like the way PGP operates to me.

> This is what I want.
> 
> 1. When customer signs up, he enters a password.  The password is NOT
> stored on the system, but is used to generate a nonsymetrical encryption
> key, which is stored on the server.
> 2. Sensitive information is encrypted using the encryption key.
> 3. When the customer wants to see the sensitive information, he has to
> log in, using the password he supplied in #1, and this is the decryption
> key for the information. This password is never stored on the server,
> but only passed from session to session with an ssl connection.

There should be no problem doing that with PGP.  Of course the password 
may get stored in your swap-file.

> Are there any libraries that allow a nonsymetrical key pair, where the
> encryption key can be generated from the decryption key that the
> customer supplies?

Forget libraries, I'm not aware of any PK _algorithm_ that would allow 
that.  All the PK algorithms I know create a key _pair_ in a single 
operation and it is just about as hard to go from the private key to the 
public as the other way.

However there is no need in anything you've said you want to achieve to 
generate the encryption from the decryption key.  Simply store the 
encryption key (which is public after all) in step 1.

This, of course, has nothing to do with Perl.



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

Date: Thu, 27 Jan 2005 18:48:06 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FAQ 4.48 How do I shuffle an array randomly?
Message-Id: <35snnaF4okomgU1@individual.net>

PerlFAQ Server wrote:
> 4.48: How do I shuffle an array randomly?

<snip>

>     You've probably seen shuffling algorithms that work using splice,
>     randomly picking another element to swap the current element with
> 
>         srand;
>         @new = ();
>         @old = 1 .. 10;  # just a demo
>         while (@old) {
>             push(@new, splice(@old, rand @old, 1));
>         }
> 
>     This is bad because splice is already O(N), and since you do it N times,
>     you just invented a quadratic algorithm; that is, O(N**2). This does not
>     scale, although Perl is so efficient that you probably won't notice this
>     until you have rather largish arrays.

That comment makes me think of this thread:
http://groups-beta.google.com/group/comp.lang.perl.misc/browse_frm/thread/da705489201879ba

where it was shown that using splice for an occational shuffling is well 
as efficient as the alternatives even for arrays with thousands of elements.

Is the above too categorical?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 27 Jan 2005 18:33:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 4.48 How do I shuffle an array randomly?
Message-Id: <ctbc55$omu$3@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> PerlFAQ Server wrote:
> > 4.48: How do I shuffle an array randomly?
> 
> <snip>
> 
> >     You've probably seen shuffling algorithms that work using splice,
> >     randomly picking another element to swap the current element with
> > 
> >         srand;
> >         @new = ();
> >         @old = 1 .. 10;  # just a demo
> >         while (@old) {
> >             push(@new, splice(@old, rand @old, 1));
> >         }
> > 
> >     This is bad because splice is already O(N), and since you do it N times,
> >     you just invented a quadratic algorithm; that is, O(N**2). This does not
> >     scale, although Perl is so efficient that you probably won't notice this
> >     until you have rather largish arrays.
> 
> That comment makes me think of this thread:
> http://groups-beta.google.com/group/comp.lang.perl.misc/browse_frm/thread/da705489201879ba
> 
> where it was shown that using splice for an occational shuffling is well 
> as efficient as the alternatives even for arrays with thousands of elements.
> 
> Is the above too categorical?

No, Perl is too atypical :)

It is sometimes difficult to demonstrate N**2 behavior in Perl when one of
the loops is done in Perl and the other internally to Perl in C.  You need
large N to even see the quadratic behavior.

As general programming principles the statements in the FAQ are true.  I
wouldn't change them.

Anno


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

Date: Thu, 27 Jan 2005 15:29:38 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: FAQ 6.17 Why don't word-boundary searches with "\b" work for me?
Message-Id: <CN7Kd.188176$Xk.187085@pd7tw3no>

In article <260120051105278833%comdog@panix.com>,
 brian d foy <comdog@panix.com> writes:
>In article <U9uJd.169457$Xk.119808@pd7tw3no>, Peter Scott
><peter@PSDT.com> wrote:
>
>> In article <ct39o5$an5$1@reader2.panix.com>,
>>  PerlFAQ Server <comdog@panix.com> writes:
>
>> >6.17: Why don't word-boundary searches with "\b" work for me?
>
>> >    Two common misconceptions are that "\b" is a synonym for "\s+" and that
>> >    it's the edge between whitespace characters and non-whitespace
>> >    characters. Neither is correct. "\b" is the place between a "\w"
>> >    character and a "\W" character (that is, "\b" is the edge of a "word").
>
>> That seems unnecessarily misleading.  
>
>I wonder if those two things are even common misconceptions.  What
>have you run into in your classes?  In the Stonehenge classes I 
>pretty much explain \b in terms of \w and \W and emphasize that it's
>"Perl's odd notion of what a word is, not ours".  After I say that 
>a couple times, no one seems to have problems with it.

I rarely find people who know about \b to begin with.  The ones who do
and have gotten it wrong mostly think it's the boundary between
whitespace and non-whitespace.  I've seen some people use it in a
sense that suggested they thought it meant \W*, but upon questioning,
admitted they were guessing.

In case it wasn't clear, I was objecting to the assertion that a
\W character has to be present.  I tell people that \b is the
place between a word character and *something that isn't a word
character*, then explain why I emphasized the second part.  I think
the FAQ should say:

"\b" is the place between a "\w" character and either a "\W" character
or the edge of the string (that is, "\b" is the edge of a "word").

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: 27 Jan 2005 16:24:53 GMT
From: xhoster@gmail.com
Subject: Re: How can I call a subroutine / function and not wait for it to return?
Message-Id: <20050127112453.318$8l@newsreader.com>

bayxarea-usenet@yahoo.com wrote:
> Uh ... no.. it is NOT that I don't want to use the tools .. it is that
> AFAIK (as far as I know) these are not relevant

But people who know more than you on the subject keep telling you that they
are relevant!


> What I know -
>
> IPC - will allow me to call communicate with another process  - ok -
> great - but this isn't another process.

If you want it to run independently of the main program flow, the easiest
way is to make it another process (or another thread, but Perl threading
is not something I recommend).  You could rewrite this simple sub into a
very complex event-loop or polling type of thing, but that would make an
awful mess of the code.

> fork - will allow me to spawn the current process as a seperate child -
> ok - great but this isn't what I thought I would need - perhaps it is -
> hence the AFAIK in my reply!
>
> after reading the post from Anno regarding fork - I suppose I could do
> it that way -

If you want a module that will hide a lot of the mess from you, you may
be able to "use forks" if you are on unix, or "use threads" if you are on
Windows.  But these might not work for you, as there does not appear to
be a non-blocking "join" method.


> I was just hoping there was a way to handle it without
> starting an entire new version of the original code - this is a large
> program and I only want to exectute one tiny subroutine

It doesn't really matter how big the code is.  Fork is very efficient about
that.  Where you might run into trouble is if the data structures are very
large.  The finalization of the data structures by the child when it exits
can take a long time, so in that case the child should perhaps use
POSIX::_exit.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 27 Jan 2005 16:39:59 GMT
From: xhoster@gmail.com
Subject: Re: how to use callback function
Message-Id: <20050127113959.302$MG@newsreader.com>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
> bingster <bdu@iastate.edu> wrote in news:35qf2cF4n7tu5U1@individual.net:
>
> > Speaking of the example programs, if I had had access to any example
> > code, I would not have come here to bother you guys.  I saw the manual
> > mentioned the example directory as well.  However I've searched my
> > system from root, but did not find any related example code. I e-mailed
> > the author of the module.  But got no response.  Also searching
> > Net::XMPP in this newsgroup returns nothing but my posts.  Anyway,
> > thanks a lot for looking.
>
> Oh, c'mon ...
>
> http://search.cpan.org/src/REATMON/Net-XMPP-1.0/examples/
>
> The steps it took to find it:
>
> 1. http://search.cpan.org/
>
> 2. Type xmpp in the search box
>
> 3. Follow < Net::XMPP >
>
> 4. Follow < Net-XMPP-1.0 >

This one wasn't so obvious to me.

> 5. Follow < Browse >
>
> 6. Look in the examples directory
>
> I am not sure which one of these steps is not obvious.
>
> Sinan

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 27 Jan 2005 14:28:15 +0000
From: Lila Duncan <LilaDuncan@XSPAMhotmail.co.uk>
Subject: I will pay for perl help
Message-Id: <65thv0lv9p1c46do2mo6r7qnpmeq54jvab@4ax.com>

Hi,
I'm a newbie. I think perl is great and I'm busy getting together
documentation and links so I can learn more about it. 
I installed ActivePerl on my Win XP computer.
I recently wrote to the perl.beginners group about a problem I was having
but I got ignored. Maybe I wasn't advanced enough for them. :-)
My reasons for wanting to learn perl are practical and commercial.
I'd like to become a proficient buyer and seller on eBay.
I read David A Karp's book "ebay Hacks" in which he recommends the use of
perlscripts for automating eBay searches. The example files he gives don't
seem to be working for me at present. Maybe it's because the originals were
written to be run on a unix-like system and I'm running win-xp.
Anyway I've tried various modifications but so far I don't have enough
skill to overcome the problems. 
I'd be glad to pay for any advice or help on this subject. I can pay by
PayPal or other methods. Please email me if you're interested.

My address is: LilaDuncan@XSPAMhotmail.co.uk
Remove 'XSPAM' to mail me.
-- 
Lila Duncan


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

Date: Thu, 27 Jan 2005 14:32:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: I will pay for perl help
Message-Id: <Xns95EB6124D113asu1cornelledu@127.0.0.1>

Lila Duncan <LilaDuncan@XSPAMhotmail.co.uk> wrote in
news:65thv0lv9p1c46do2mo6r7qnpmeq54jvab@4ax.com: 

> I'd be glad to pay for any advice or help on this subject. I can pay
> by PayPal or other methods. Please email me if you're interested.

http://jobs.perl.org/


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

Date: Thu, 27 Jan 2005 14:54:16 +0000
From: Lila Duncan <LilaDuncan@XSPAMhotmail.co.uk>
Subject: Re: I will pay for perl help
Message-Id: <huvhv0hvia80ikb5gt7mubi1jid9kjr206@4ax.com>

On Thu, 27 Jan 2005 14:32:45 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:

>Lila Duncan <LilaDuncan@XSPAMhotmail.co.uk> wrote in
>news:65thv0lv9p1c46do2mo6r7qnpmeq54jvab@4ax.com: 
>
>> I'd be glad to pay for any advice or help on this subject. I can pay
>> by PayPal or other methods. Please email me if you're interested.
>
>http://jobs.perl.org/

Thanks for the reply. I went to the site and entered my email and name to
open an account. It didn't specifically announce that it would send me a
confirming email but I,m waiting for one expectantly. :-)
-- 
Lila Duncan


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

Date: Thu, 27 Jan 2005 15:21:50 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Net::SSH::Perl sending output to STDOUT
Message-Id: <slrncvhu7u.2g0.news@maki.homeunix.net>

ryanmhuc@yahoo.com wrote :
> I'm using Net::SSH::Perl to connect to remote server but when every I
> run commands it is sending output to STDOUT.
>
> $ssh = Net::SSH::Perl->new($ip);
> $ssh->login($user, $pass);
> ($out, $err, $ext) = $ssh->cmd("ls -l");
>
> So when I run the command instead of the the command output being put
> into $out it goes straight to STDOUT. Furthermore if the password is
> incorrect the $ssh->cmd stops my program.  Anyone know how to get
> around this?

I used this module, too.
I only get an output after 'print $out'

There is a good example script at 

	http://search.cpan.org/src/DROLSKY/Net-SSH-Perl-1.25/eg/cmd.pl

to start from.

Don't forget to say
	debug => 0
if you don't want to see the debug messages.

HTH
Martin

-- 
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
 .32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'


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

Date: Thu, 27 Jan 2005 09:29:02 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Old tutorial - now corrected
Message-Id: <270120050929024145%comdog@panix.com>

In article <Xns95EB1A0C76EA9ebohlmanomsdevcom@130.133.1.4>, Eric
Bohlman <ebohlman@omsdev.com> wrote:

> binnyva@hotmail.com wrote in news:1106766522.966545.9750
> @z14g2000cwz.googlegroups.com:

> > I admit that I should correct those scirpts - I will.

> > But please not that those are functional scirpt -
> > just not perfect. They have some bugs. The most

> Most people with any experience in programming wouldn't consider 
> "functional" to be a useful way of saying "works only when conditions are 
> just right.

Indeed, "functional" means something different than
"functioning" or "working". :)

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: Thu, 27 Jan 2005 16:34:23 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Old tutorial - now corrected
Message-Id: <Pine.LNX.4.61.0501271632140.21974@ppepc56.ph.gla.ac.uk>

On Thu, 27 Jan 2005, brian d foy wrote:

> Indeed, "functional" means something different than
> "functioning" or "working". :)

And "Functional Programming" has a rather specialised meaning.

Hmmm: http://www.dcs.gla.ac.uk/fp/pictures/lambda-and-chip.gif

Not my cup of tea, though.


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

Date: Thu, 27 Jan 2005 14:21:42 -0000
From: "Mark" <mark.harris.invalid@ukonline.co.uk.invalid>
Subject: Replace scalar in another scalar
Message-Id: <35sbthF43ahs6U1@individual.net>

Hello,

I have 2 scalars. I want to remove all occurences of one within the other.

I've tried this:

$delim = '|';
$value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";

$value =~ s/$delim//g;

print "$value\n";

 ... but it doesn't work - it prints $value unaltered. What do I need to do
to the "$value =~ s/$delim//g;" line to realise that I'm reffering to the
_value_ of $delim, rather than the literal text "$delim"?

This is possibly a FAQ, but it's dead hard to know what to put into Go-Ogle
to find this information.

Thanks for any help,

Mark




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

Date: Thu, 27 Jan 2005 15:37:32 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Replace scalar in another scalar
Message-Id: <slrncvhv5c.2g0.news@maki.homeunix.net>

Mark wrote :
> Hello,
>
> I have 2 scalars. I want to remove all occurences of one within the other.
>
> I've tried this:

use strict;
use warnings;

> $delim = '|';

$delim = '\|';

> $value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";
>
> $value =~ s/$delim//g;
>
> print "$value\n";

HTH
Martin

-- 
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
 .32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'


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

Date: Thu, 27 Jan 2005 14:38:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Replace scalar in another scalar
Message-Id: <Xns95EB622ABBFCasu1cornelledu@127.0.0.1>

"Mark" <mark.harris.invalid@ukonline.co.uk.invalid> wrote in
news:35sbthF43ahs6U1@individual.net: 

> Hello,
> 
> I have 2 scalars. I want to remove all occurences of one within the
> other. 
> 
> I've tried this:
> 
> $delim = '|';
> $value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";
> 
> $value =~ s/$delim//g;
> 
> print "$value\n";
> 
> ... but it doesn't work - it prints $value unaltered. What do I need
> to do to the "$value =~ s/$delim//g;" line to realise that I'm
> reffering to the _value_ of $delim, rather than the literal text
> "$delim"? 

Oh, but that is not what is happening. Indeed Perl is correctly using the 
value of $delim. The problem is that the pipe character has a specific 
meaning in regular expressions. Try:

#! /usr/bin/perl

use strict;
use warnings;

my $delim = '|';
my $value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";

$value =~ s/\Q$delim\E//g;

print "$value\n";
__END__

C:\Dload> q
Test!

For more information, read

perldoc perlretut

"Grouping things and hierarchical matching"

and

"More on characters, strings, and character classes"

Sinan


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

Date: Thu, 27 Jan 2005 14:36:32 -0000
From: "Mark" <mark.harris.invalid@ukonline.co.uk.invalid>
Subject: Re: Replace scalar in another scalar
Message-Id: <35scpbF4rokloU1@individual.net>

Thanks!

Mark




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

Date: Thu, 27 Jan 2005 15:35:50 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Replace scalar in another scalar
Message-Id: <Xns95EB9EAA3E7ABelhber1lidotechnet@62.89.127.66>

"Mark" <mark.harris.invalid@ukonline.co.uk.invalid> wrote:

> Hello,
> 
> I have 2 scalars. I want to remove all occurences of one within
> the other. 
> 
> I've tried this:
> 
> $delim = '|';
> $value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";
> 
> $value =~ s/$delim//g;
> 
> print "$value\n";
> 
> ... but it doesn't work - it prints $value unaltered. What do I
> need to do to the "$value =~ s/$delim//g;" [...]


| is a special character in regexes. So


   $value =~ s/\Q$delim//g;


should do it.


-- 
Cheers,
Bernard


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

Date: Thu, 27 Jan 2005 09:47:26 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Replace scalar in another scalar
Message-Id: <J4OdnWDlhI1iY2XcRVn-iQ@adelphia.com>

Mark wrote:

> I've tried this:
> 
> $delim = '|';
> $value = "||||||||T||||||e||||||||||s|||||||||t||||||||!||||||";
> 
> $value =~ s/$delim//g;
> 
> print "$value\n";
> 
> ... but it doesn't work - it prints $value unaltered. What do I need to do
> to the "$value =~ s/$delim//g;" line to realise that I'm reffering to the
> _value_ of $delim, rather than the literal text "$delim"?

You *are* getting the value of $delim. However, that value is a character
that has special meaning when used in regexes. You'd get the same result
from using the value as literal text:

    $value =~ s/|//g;

To match a literal |, you need to escape it:

    $value =~ s/\|//g;

So naturally, what you want to do is store the escape in $delim:

    $delim = '\|';

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 27 Jan 2005 15:48:33 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Replace scalar in another scalar
Message-Id: <yzdhdl3j5by.fsf@invalid.net>


Martin Kissner <news@chaos-net.de> writes:
> Mark wrote :
> > I have 2 scalars. I want to remove all occurences of one within the other.
> >
> > I've tried this:
> 
> use strict;
> use warnings;
> 
> > $delim = '|';
> 
> $delim = '\|';

To let Perl help you get from '|' to '\|', you can use the quotemeta()
function:

$delim = '|';
$delim = quotemeta $delim;


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

Date: 27 Jan 2005 16:52:40 GMT
From: xhoster@gmail.com
Subject: Re: sorting just the largest values
Message-Id: <20050127115240.981$82@newsreader.com>

"Alex Hart" <alex_the_hart@yahoo.com> wrote:
> > Most people wouldn't consider 20,000 items to be a "very large list."
> > I'd suggest first just trying the brute-force approach of reading
> them
> > into an array, sorting them, and taking the last 50 results. Only if
>
> I'm developing a real-time application, and a particular sort was
> taking several minutes when the list got up to 20,000.

That is definitely pathological.

> It might be a
> problem with the data being too ordered to start with (or does per
> shuffle before it sorts?).

Depends on the version.  Which version are you using?

> I'll try some of the suggestions here, and I'll be sure to benchmark
> along the way.

Unfortunately, benchmarking is extremely difficult in cases where there are
unknown and unpredictable pathological patterns in the data.  Be careful.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 27 Jan 2005 17:26:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sorting just the largest values
Message-Id: <ctb88g$ng0$1@mamenchi.zrz.TU-Berlin.DE>

 <xhoster@gmail.com> wrote in comp.lang.perl.misc:
> "Alex Hart" <alex_the_hart@yahoo.com> wrote:
> > > Most people wouldn't consider 20,000 items to be a "very large list."
> > > I'd suggest first just trying the brute-force approach of reading
> > them
> > > into an array, sorting them, and taking the last 50 results. Only if
> >
> > I'm developing a real-time application, and a particular sort was
> > taking several minutes when the list got up to 20,000.
> 
> That is definitely pathological.

I agree. There's some gross inefficiency going on.  We should see the
sort, it's certainly speed-up-able.

In general, the solution to the "bottom-n" problem is a heap.  In pseudo-
code (using a mythical module Heap, but there are real ones on CPAN):

    use Heap;
    my $h = Heap->new();
    my $n = 50;
    for ( @data ) {
        $h->insert( $_);
        $h->extract_maximum if $h->size > $n;
    }
    my @top_n = map $h->extract_maximum, 1 .. $h->size;

If the heap implementation doesn't have a ->size method, it is easy to
use an external counter instead.

If $n is larger than the data size, the algorithm does a heap sort on
the data.  If $n is smaller, it is faster than the equivalent sort.

Anno


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 7701
***************************************


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