[19242] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1437 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 3 18:05:38 2001

Date: Fri, 3 Aug 2001 15:05:11 -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: <996876311-v10-i1437@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 3 Aug 2001     Volume: 10 Number: 1437

Today's topics:
    Re:  COmments appreciated 194.203.212.8 [demerphq]
    Re:  Re: COmments appreciated 194.203.212.8 [demerphq]
        [perl,v5.6.1]LWP::UserAgent (Christian Ribeaud)
    Re: Adding values of an array to an array in a hash (Yves Orton)
    Re: Adding values of an array to an array in a hash (Eric Bohlman)
        ANNOUNCE: DBD::Sybase 0.93 <mpeppler@peppler.org>
        Call Javascript from Perl <wuxf@ece.northwestern.edu>
    Re: Can't seem to get regex correct. <friedman@math.utexas.edu>
        cgi cookie question <blahblahblah@blah.com>
    Re: Changing user while using HTTP authentication <amrvka@emka.at>
    Re: COmments appreciated (Anno Siegel)
    Re: data collection and file management (katherine)
    Re: DBD::Oracle Error Message Makes no Sense ... to me <amrvka@emka.at>
        Dominus at TPC5 stuff now online (Mark Jason Dominus)
        dselect-like Perl package manager? (F. Xavier Noria)
    Re: Engineering vs. Hacking (was Re: How to supply modu (David H. Adler)
        FAQ: How do I permute N elements of a list? <faq@denver.pm.org>
    Re: FAQ: How do I shuffle an array randomly? (John J. Trammell)
        Fast $s1->isSubstringOf($s2) <kj0@mailcity.com>
    Re: Fast $s1->isSubstringOf($s2) <krahnj@acm.org>
        From UNIX to Windows <porter96@lycos.com>
    Re: From UNIX to Windows (Tad McClellan)
    Re: From UNIX to Windows <porter96@lycos.com>
    Re: How to extract non-character data from socket strea (Yves Orton)
    Re: Net::Ping and alarm troubles (Yves Orton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 3 Aug 2001 19:42:42 GMT
From: 194.203.212.8 [demerphq]
Subject: Re:  COmments appreciated
Message-Id: <9keuri0lti@enews4.newsguy.com>

> Hi!
> 
> I have a messageboard and i wanted to shorten all the words longer
> than 20 characters and put 3 dots after them.
> This is what i came up with:
> 
> if ($orig_message =~ m/(\w{20,})/)	{
> 	$truncated_message = substr($1, 0, 20);
> 	$orig_message =~ s/(\w{20,})/$truncated_message.../g;
> 	}
> 
> This is doing the trick for now but i was wondering if any of you
> professionals see something that i miss here. Perhaps a better way to
> do it...

Well, you could use the e modifier and do it in one line:

s/(\w{21,})/substr($1,0,20)."..."/ge;

Note that I am being picky with your spec and have changed the match to \w{21,} as \w{20,} will cause a twenty letter word to have the "..." added to it.

:-)

Yves
ps Read perlre.  Its worth the time. Better yet read it twice. Its still worth the time.





==================================
Poster's IP address: 194.203.212.8
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: 3 Aug 2001 19:47:45 GMT
From: 194.203.212.8 [demerphq]
Subject: Re:  Re: COmments appreciated
Message-Id: <9kev510m7u@enews4.newsguy.com>

> Markku Hirvonen <markku@huilustudio.fi> wrote:
> >
> >I have a messageboard and i wanted to shorten all the words longer
> >than 20 characters and put 3 dots after them.
> 
> 
>    $orig_message =~ s/(\w{20})\w+/$1.../g;

Erk.  And there I was doing the /e version. 

This is much nicer.

Yves


==================================
Poster's IP address: 194.203.212.8
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: 3 Aug 2001 12:00:26 -0700
From: christian.ribeaud@predict.ch (Christian Ribeaud)
Subject: [perl,v5.6.1]LWP::UserAgent
Message-Id: <393b8bf9.0108031100.1de45e94@posting.google.com>

Hi,

I have got a problem with the LWP::UserAgent module
(libwww-perl,v5.51). For every request regarding pictures (.gif) I get
the following error: "500 read timeout". The response does not seem to
be successfull. Do I have forgotten something? Here an extract of the
code. The code should work on Linux but I can not get it working on my
OS (WinNT4.0, ActiveState, binary build 628).

my $ua = LWP::UserAgent->new;
$ua->env_proxy;
$ua->agent("dltime/1.00 " . $ua->agent);
$ua->cookie_jar(HTTP::Cookies->new);
 ...
my $request = GET $url, [referer => $refer];
my $response = $ua->simple_request($request);
if ($response->is_success){...

I would be very grateful if someone could help me.
Have a nice day. Respects,

christian


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

Date: 3 Aug 2001 11:16:48 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Adding values of an array to an array in a hash
Message-Id: <74f348f7.0108031016.7bc20743@posting.google.com>

"Tom Melly" <tom.melly@ccl.com> wrote in message news:<3b6a8d55$0$3756$ed9e5944@reading.news.pipex.net>...
> "J.C.Posey" <jcp@myrtle.ukc.ac.uk> wrote in message
> news:jkog0b9cse9.fsf@myrtle.ukc.ac.uk...
SNIP
> for($n=0;$n<=$#fields;$n++){
>     $urls{$key}[$n] += $fields[$n];
> }


Or more perlishly:

$urls{$key}->[$n]+=$fields[$n] for my $n (0..$#fields);

Or perhaps one iota faster (for a large array.. but its not so dont
worry):

my $array=$urls{$key};
$array->[$n]+=fields[$n] for my $n (0..$#fields);

Then theres also the stranger looking, slightly more controversial
map() in void context:

map {$urls{$key}->[$_]+=$fields[$_]} (0..$#fields);

In fact are you sure that

$urls{$key}[$n] += $fields[$n];

shouldnt be 

$urls{$key}->[$n] += $fields[$n];

???

Yves
ps (Sorry ive been getting into the tmtowtdi thing a bit lately)


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

Date: 3 Aug 2001 19:19:12 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Adding values of an array to an array in a hash
Message-Id: <9ketfg$mko$6@bob.news.rcn.net>

Yves Orton <demerphq@hotmail.com> wrote:
> In fact are you sure that

> $urls{$key}[$n] += $fields[$n];

> shouldnt be 

> $urls{$key}->[$n] += $fields[$n];

The former is simply "syntactic sugar" for the latter.  They compile to 
the same code.



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

Date: Fri, 03 Aug 2001 13:46:04 -0700
From: "Michael Peppler" <mpeppler@peppler.org>
Subject: ANNOUNCE: DBD::Sybase 0.93
Message-Id: <tmm53unjqn8a20@corp.supernews.com>

ANNOUNCE: DBD::Sybase 0.93

The uploaded file

    DBD-Sybase-0.93.tar.gz

has entered CPAN as

  file: $CPAN/authors/id/M/ME/MEWP/DBD-Sybase-0.93.tar.gz
  size: 94878 bytes
   md5: 397a86475a7cb8f45a47ec29c991cbde

I'm happy to announce that DBD::Sybase 0.93 has finally been
released. This is a release that has a few interesting new features,
and some bug fixes.

First the new features:

1. Use ?-style placeholders and bind variables for the input
   parameters to stored procedures.

   This lets you write things like:

   $sth = $dbh->prepare("exec my_proc ?, ?");
   $sth->execute('foo', 'bar');

   Internally this uses the ct_param() API calls to execute an RPC
   call to the server (instead of a language call) which removes all
   SQL compiling from the request. From my benchmarks this is the
   absolute fastest way to execute a SQL statement.

2. Access to the ct_get/set_data() API for TEXT/IMAGE datatype fetch
   and store requests.

   This is provided via $sth->func() calls. The API is unfortunately
   rather convoluted, but that's mostly a consequence of the Sybase
   API and the fact that TEXT/IMAGE data is stored separately from the
   main data for the row, requiring the API to fetch a "text pointer"
   in order to be able to store or fetch the TEXT/IMAGE data directly.

3. The folks at Morgan Stanley have implemented a one-step routine
   called nsql() for Sybase::DBlib. 

   I've reproduced this routine here - also available via
   $dbh->func(). This routine can do automatic deadlock retries if you
   ask it nicely.

There are also some other changes, such as the ability to ask
connect() to encrypt the password, and support for the new
primary_key_info() request.

The configuration routines in Makefile.PL have been modified slightly
to check for the OpenClient version, and to *not* link with -linsck or
-ltli in the case of OC 11.x or later (avoids conflicts with settings
in $SYBASE/config/libtcl.cfg for multi-threaded configurations).

This version will unfortunately not build with FreeTDS 0.52 due to
some missing symbols in the FreeTDS libraries (symbols used in the
ct_get_data/ct_send_data() requests).

I expect this to be the last "beta" release - if there are no
particular problems with this release then I will release 1.00 "soon".

As usual please report any problems to me, either via email, or by
checking the bug tracking system at
http://www.peppler.org/cgi-bin/bug.cgi

Michael

PS. For those keeping track of such things... there's no 0.92 release
of DBD::Sybase - that version was never publically released.
-- 
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler@peppler.org - mpeppler@mbay.net
International Sybase User Group - http://www.isug.com




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

Date: Fri, 03 Aug 2001 15:56:33 -0500
From: Xingfu Wu <wuxf@ece.northwestern.edu>
Subject: Call Javascript from Perl
Message-Id: <3B6B1001.5483E73E@ece.northwestern.edu>

I use CGI.pm to pass a variable value to Javascript, I need to pass a
variable value from Javascript to Perl. I heard that PerlConnect of
mozilla.org can do that, but I do not know where I can get the version
for linux.

Does somebody know where the version is avaliable?

--
Xingfu





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

Date: Fri, 3 Aug 2001 13:20:22 -0500
From: "Chas Friedman" <friedman@math.utexas.edu>
Subject: Re: Can't seem to get regex correct.
Message-Id: <3b6aef28$1_1@feed1.realtime.net>


Mark Johnson <crvmp3@hotmail.com> wrote in message
news:90F26DC10markjohnsononfiberco@24.28.95.150...
> I'm having a really hard time getting the regular expressions down.  I
have
> the following text to parse:
>
> 1:1            R        0        0        0        0        0        0
> 0 ESC[6;01H
>
> 1:2            R        0        0        0        0        0        0
> 0 ESC[7;01H
>
> 1:3            R        0        0        0        0        0        0
> 0 ESC[8;01H
>
> 1:4            R        0        0        0        0        0        0
> 0 ESC[9;01H
>
> 2:1            R        0        0        0        0        0        0
> 0 ESC[10;01H
>
> 2:2            R        0        0        0        0        0        0
> 0 ESC[11;01H
>
> 4:8            R        0        0        0        0        0        0
> 0 ESC[21;01H
>
> 4:9            R        0        0        0        0        0        0
> 0 ESC[01;55HThu Aug 2 16:49:23 2001
>
> 4:10            R        0        0        0        0        0        0
> 0 ESC[6;01H
>
> 4:32            R        0        0        0        0        0        0
> 0 ESC[01;55HThu Aug 2 16:49:31 2001
>
> There are no newlines, I added them for posting purposes, and the ESC is
> really a \033 or ASCII 27.
>
> What I need to do is parse out just from the R to the \e (ESC character).
> I tried:
>
>         @arr = (m/R*\e/g);
>
>             while( @arr )
>
>             {
>
>                 $line = shift @arr;
>
>                 $results .= "$line";
>
>             }
>
>
> But this doesn't return me anything.  I tried every variation of what I
> could think of with no success.  The closest I got was (m/\b\C/g)... There
> must be some conceptual piece that I'm not understanding which is probably
> really obvious.
>
> Thanks for any help you can give me.

 The match operator searches a string (default $_) and returns true or
false.
@arr = (m/R*\e/g); certainly doesn't do what you want - it produces an array
containing 1 or "".  Is the above your whole script?
You need to read lines into variables (probably an array) and then try to
match each line. Perhaps someone here will write the script for you, but
you might read about matching and try again.
                          chas friedman




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

Date: Fri, 03 Aug 2001 21:03:15 GMT
From: "Hmmm..." <blahblahblah@blah.com>
Subject: cgi cookie question
Message-Id: <nkEa7.82$Gw1.7516@newsread1.prod.itd.earthlink.net>

Hi.

I am running test scripts to understand how cookies work with cgi.  I am
trying to create a cookie in one script, and retrieve it in another.  Each
script creates an html page to display the results. Here is the first script
and it's output (which indicates that the cookie is created successfully:

#!/usr/bin/perl -w
############## start of first script #############
use CGI;
$query = new CGI;

print <<top_html;
content-type: text/html

<HTML><HEAD><TITLE>
Creating the cookie.
</TITLE></HEAD><BODY>
top_html

$the_cookie = $query->cookie(-name=>'howdy',
value=>'12345',  -expires=>'+3d');
if (defined $the_cookie)
{
 print "<p>the_cookie is defined $the_cookie";
}
else
{
 print "<p>the_cookie is not defined $the_cookie";
}

print <<bottom_html;
</BODY></HTML>
bottom_html
############## end of first script #############
The first script produces the output:

the_cookie is defined howdy=12345; path=/cgi-bin/; expires=Mon, 06-Aug-2001
20:31:38 GMT
############## end of first output ############
Here is the second script and it's output:

#!/usr/bin/perl -w
############## start of second script #########
use CGI;
$query = new CGI;


print <<top_html;
content-type: text/html

<HTML><HEAD><TITLE>
Did the cookie come back?
</TITLE></HEAD><BODY>
top_html

$the_cookie = $query->cookie('howdy');
if (defined $the_cookie)
{
 print "<p>the_cookie is defined $the_cookie";
}
else
{
 print "<p>the_cookie is not defined $the_cookie";
}

print <<bottom_html;
</BODY> </HTML>
bottom_html
############## end of second script #########
This second script produces the output:

the_cookie is not defined
############## end of second output ########

Why can't I get the cookie in the second script?  Thanks.




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

Date: Fri, 03 Aug 2001 20:42:59 GMT
From: "Mrvka Andreas" <amrvka@emka.at>
Subject: Re: Changing user while using HTTP authentication
Message-Id: <n1Ea7.9209$U27.365551@news.chello.at>

hi

"Simon Perreault" <nomis80@linuxquebec.com> schrieb im Newsbeitrag
news:HSea7.7632$Ah5.139702@wagner.videotron.net...

> The problem is simple: I'm programming an administration interface much
> like webmin (but much simpler, the audience targetted is not the same) and
> I'm using HTTP authentication. Now I want to add a feature that lets you
> change the user you are logging as, and that feature shouldn't be "Please
> close your browser and come again."
>
> I was thinking of writing a script that would say "access denied" once,
> forcing the browser to ask the user for a username/password, and then it
> would forward the user to where he came from.

yes, you think the right way!
write a perl script like this:

print "HTTP/1.1 401 Unauthorized\n";
print "WWW-Authenticate: Basic realm=\"my secure site\"\n\n";

this will send the browser "not-authorized" and forces to re-authenticate.

> Thanks.

you're welcome

cya




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

Date: 3 Aug 2001 18:37:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: COmments appreciated
Message-Id: <9ker0n$hj8$3@mamenchi.zrz.TU-Berlin.DE>

According to Tad McClellan <tadmc@augustmail.com>:
> Markku Hirvonen <markku@huilustudio.fi> wrote:
> >
> >I have a messageboard and i wanted to shorten all the words longer
> >than 20 characters and put 3 dots after them.
> 
> 
>    $orig_message =~ s/(\w{20})\w+/$1.../g;

 ...or the regex-free version:

    substr( $orig_message, 20) = '...' if length $orig_message > 20;

Anno


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

Date: 3 Aug 2001 13:57:24 -0700
From: kstar8864@hotmail.com (katherine)
Subject: Re: data collection and file management
Message-Id: <848d6bd2.0108031257.4df9492@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9keofv$hj8$1@mamenchi.zrz.TU-Berlin.DE>...

Thanks for your help Anno :)

-Katherine


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

Date: Fri, 03 Aug 2001 21:15:40 GMT
From: "Mrvka Andreas" <amrvka@emka.at>
Subject: Re: DBD::Oracle Error Message Makes no Sense ... to me
Message-Id: <0wEa7.10003$U27.382509@news.chello.at>

hi

"Tom Hoffmann" <tom.hoffmann@worldnet.att.net> schrieb im Newsbeitrag
news:7i_97.29193$gj1.2765219@bgtnsc05-news.ops.worldnet.att.net...
> I am just starting to work with the DBI and DBD::Oracle. I have
> installed them both successfully. However, when I try to connect to the
> Oracle database I get the following error:
>
> install_driver(Oracle) failed:
> Can't load
> '/usr/opt/perl5/lib/site_perl/5.005/aix/auto/DBD/Oracle/Oracle.so'
> for module DBD::Oracle:
> dlopen:
> /usr/opt/perl5/lib/site_perl/5.005/aix/auto/DBD/Oracle/Oracle.so: A
> file or directory in the path name does not exist. at
> /usr/opt/perl5/lib/5.00503/aix/DynaLoader.pm line 169.
>  at (eval 1) line 3
> Perhaps a required shared library or dll isn't installed where expected
>  at ./DBItest.pl line 10
>

which version of oracle software do you have installed?
if  you have sql*plus , then try to connect with this first.

> my $dbh = DBI->connect('dbi:Oracle:TRNG', 'tom', 'pwd')
>         or die "Could not connect to database:";
> $dbh->disconnect();

take a close look at your environments!
and put them in your perl script like
$ENV{ORACLE_HOME}= "..."
your $ENV{LD_LIBRARY_PATH}= "..."
 ..
 .

cya

Andy




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

Date: Fri, 03 Aug 2001 20:03:53 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Dominus at TPC5 stuff now online
Message-Id: <3b6b03a8.a8c$21@news.op.net>
Keywords: Iran, advisor, linden, papacy



The following items may interest you, and are now available on my web site:

* Slides from my talk on "The Identity Function"

        The title backfired: Too many people didn't know what the
        identity function was, and those who did assumed that I must
        have been referring to something else. The identity function
        is a function such as sub identity { return $_[0] } which
        returns its argument unchanged. In this talk, I show four
        unexpectedly useful uses for the identity function.

        http://perl.plover.com/yak/Identity/

* Slides from my talk "Dirty Stories About the Perl Regex Engine"

Here's the description of this talk from the brochure:

     This talk is too short to tell you all about how the Perl regex
     engine works---that would take years, and cost millions of
     lives. Instead, I'll do three very brief case studies of how it
     handles certain specific features. You've probably always
     suspected that the Perl regex engine was concealed filthy secrets
     and nasty surprises; these three features are noteworthy for
     being particularly disgusting.

     Barf bags will be provided.

     Mark-Jason Dominus wrote the back-end of ActiveState's regex
     debugger. He is presently recuperating at the Miskatonic
     University Hospital in Whately, Massachusetts.

Full details are available, including a picture of the barf bags (Yes,
I really brought barf bags. Did you think I was joking? I never joke.)
and the complete slides from the talk.

        http://perl.plover.com/yak/dirty/


* My paper "Rx: A Regex Debugger for Perl", plus the source code for
  Rx itself.  Also some early demo applications

        http://perl.plover.com/Rx/
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 3 Aug 2001 20:41:36 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: dselect-like Perl package manager?
Message-Id: <9kf2a0$5apik2@news1s.iddeo2.es>

Is there any Perl package manager that resembles Debian's dselect?
That is, it would be able to display available modules, search by
author, category, ... (un)install modules, check dependencies, suggest
modules, etc.

-- fxn


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

Date: 3 Aug 2001 21:10:26 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Engineering vs. Hacking (was Re: How to supply modules with your     software.)
Message-Id: <slrn9mm4q2.e4j.dha@panix2.panix.com>

In article <3B5C7701.5AB900F7@stomp.stomp.tokyo>, Godzilla! wrote:
> David Coppit wrote:
>  
>> Godzilla! wrote:
>> > David Coppit wrote:
> 
> (snipped)
> 
>> <sigh> Not everyone is here to burn you at the stake. Let me reiterate
>> that I'm trying to change your mind, not tell you how to think. And I'm
>> providing an alternative view to your "just code up every module you
>> need" view.
> 
> 
> You are practicing deceit as usual. You clearly stated,
> 
> "...do not advocate this position."

You have omitted the beginning of that statement.  It started with the
word "please", which, in normal english parlance makes it a request,
rather than a demand.

You often omit such relevant details, but condemn others for doing so.
I take this to be a hypocritical attitude.

I would be surprised to see you reply to this without such omission, if
you reply at all.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Despite his tendency to become sidetracked in debates with invisible
giraffes, he was an exemplary player, and rarely licked anyone without
prior permission    - Diablo on Shazam Twix 


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

Date: Fri, 03 Aug 2001 18:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I permute N elements of a list?
Message-Id: <wUBa7.10$T3.170735616@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How do I permute N elements of a list?

    Here's a little program that generates all permutations of all the words
    on each line of input. The algorithm embodied in the permute() function
    should work on any list:

        #!/usr/bin/perl -n
        # tsc-permute: permute each word of input
        permute([split], []);
        sub permute {
            my @items = @{ $_[0] };
            my @perms = @{ $_[1] };
            unless (@items) {
                print "@perms\n";
            } else {
                my(@newitems,@newperms,$i);
                foreach $i (0 .. $#items) {
                    @newitems = @items;
                    @newperms = @perms;
                    unshift(@newperms, splice(@newitems, $i, 1));
                    permute([@newitems], [@newperms]);
                }
            }
        }

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.49
-- 
    This space intentionally left blank


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

Date: 03 Aug 2001 18:54:19 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: FAQ: How do I shuffle an array randomly?
Message-Id: <slrn9mlb2f.4km.trammell@haqq.hypersloth.net>

On Fri, 03 Aug 2001 00:20:39 GMT, PerlFAQ Server <faq@denver.pm.org> wrote:
> 
>         # fisher_yates_shuffle( \@array ) : 
>         # generate a random permutation of @array in place
>         sub fisher_yates_shuffle {
>             my $array = shift;
>             my $i;
>             for ($i = @$array; --$i; ) {
>                 my $j = int rand ($i+1);
>                 @$array[$i,$j] = @$array[$j,$i];
>             }
>         }

What I don't like about this is an empty array pukes up a fatal error:

  [ ~/test/fy-002 ] cat -n foo.pl 
     1  #!/usr/bin/perl -w
     2  use strict;
     3  sub fisher_yates_shuffle {
     4      my $array = shift;
     5      my $i;
     6      for ($i = @$array; --$i; ) {
     7          my $j = int rand ($i+1);
     8          @$array[$i,$j] = @$array[$j,$i];
     9      }
    10  }
    11
    12  fisher_yates_shuffle( [] );
    13
  [ ~/test/fy-002 ] ./foo.pl 
  Modification of non-creatable array value attempted, subscript -1 at
  ./foo.pl line 8.
  [ ~/test/fy-002 ]

How about something a bit more robust?

  sub fisher_yates_shuffle {
    my $array = shift;
    for (my $i = @$array; $i > 0; $i--) {
      my $j = int rand ($i+1);
      @$array[$i,$j] = @$array[$j,$i];
    }
  }

Apologies if this has been dealt with before.  A search on Google turned
up no hits.

-- 
Aren't you, at this point, cutting down a California Redwood using a
banana *and* a particle accelerator?
                                         - Bernard El-Hagin, in CLPM


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

Date: 3 Aug 2001 16:52:50 -0400
From: kj0 <kj0@mailcity.com>
Subject: Fast $s1->isSubstringOf($s2)
Message-Id: <9kf2v2$iut$1@panix3.panix.com>



If I have two strings, $s1 and $s2, one way to find out whether $s1 is
a substring of $s2 is to use the test ($s2 =~ /$s1/).

Is there a faster way?

Thanks,

KJ


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

Date: Fri, 03 Aug 2001 21:21:35 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Fast $s1->isSubstringOf($s2)
Message-Id: <3B6B163E.B80F94D6@acm.org>

kj0 wrote:
> 
> If I have two strings, $s1 and $s2, one way to find out whether $s1 is
> a substring of $s2 is to use the test ($s2 =~ /$s1/).
> 
> Is there a faster way?

perldoc -f index
perldoc -f rindex



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 03 Aug 2001 13:06:59 -0500
From: Steve Postlewait <porter96@lycos.com>
Subject: From UNIX to Windows
Message-Id: <3B6AE843.BC794F66@lycos.com>

I've written a number of scripts that run fine on a UNIX machine, but
now I need to move somethings to Windows, which is using ActivePerl.

From a prompt I type: perl hello.cgi  and I get the standard .html code,
including my <H1>Hellow World</H1> line. This seems to tell me that Perl
is working.

When I enter the URL on a browser however ... nothing happens.  Well
actually, I get the "Connect: www.xxxx.com connected. Waiting for reply"
on the status bar at the bottom.

In other words my Hello World never appears on the browser.

I've tried using #!perl rather than the UNIX #!/usr/local/bin/perl ...
but that may have nothng to do with the problem.

Any suggestions?

Thanks,

Steve



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

Date: Fri, 3 Aug 2001 15:56:37 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: From UNIX to Windows
Message-Id: <slrn9mm0fl.1e6.tadmc@tadmc26.august.net>

Steve Postlewait <porter96@lycos.com> wrote:
>I've written a number of scripts that run fine on a UNIX machine, but
>now I need to move somethings to Windows, which is using ActivePerl.
>

>Any suggestions?


Yes. Ask questions about web server setup in a newsgroup about
web servers such as:

        comp.infosystems.www.servers.ms-windows


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


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

Date: Fri, 03 Aug 2001 15:50:55 -0500
From: Steve Postlewait <porter96@lycos.com>
Subject: Re: From UNIX to Windows
Message-Id: <3B6B0EAF.A707B423@lycos.com>



Tad McClellan wrote:

> >I've written a number of scripts that run fine on a UNIX machine, but
> >now I need to move somethings to Windows, which is using ActivePerl.
> >
>
> >Any suggestions?
>
> Yes. Ask questions about web server setup in a newsgroup about
> web servers such as:
>
>         comp.infosystems.www.servers.ms-windows

I take it by your response that it isn't a Perl problem ... that helps :)

Thanks,

Steve



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

Date: 3 Aug 2001 12:28:45 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: How to extract non-character data from socket stream?
Message-Id: <74f348f7.0108031128.6404bdc@posting.google.com>

crvmp3@hotmail.com (Mark Johnson) wrote in message news:<90F25DFACmarkjohnsononfiberco@24.28.95.150>...
> krahnj@acm.org (John W. Krahn) wrote in <3B6A2AB5.CB6521CB@acm.org>:
> 
> >From: "John W. Krahn" <krahnj@acm.org>
> >Newsgroups: comp.lang.perl.misc
> >Subject: Re: How to extract non-character data from socket stream?
> >
> >Mark Johnson wrote:

SNIP

> >    ( my $response = <$SOCKET> ) =~ s/\e\[[0-9;]*[ABCDHJKRfhsum]/ /;

> Sorry for my ignorance, but does the \e translate to the binary value 27 in 
> the regular expression?  

Yes. Isnt perl nice?

> 
> Would read this as:
> 
>     	substitute anything starting with an ESC, 
>     	followed by any number between 0 and 9, 
>     	followed by a semicolon, 
>     	and then (I'm not sure what this last part is saying)...

Not quite,

s/\e\[[0-9;]*[ABCDHJKRfhsum]/ / 

could also be written as

s/\e              # substitute escape
  \[              # followed by left square bracket
  [0-9;]*         # followed by 0 or more digits or semicolons
  [ABCDHJKRfhsum] # followed by exactly 1 A,B,C... or m
 / /x             # with a space, regex in extended syntax mode.

Maybe check out perlre about a dozen times (at least thats how many
times it took me to absorb a reasonable amount of info, its dense
stuff at times :-)

Cheers,
Yves


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

Date: 3 Aug 2001 12:20:30 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Net::Ping and alarm troubles
Message-Id: <74f348f7.0108031120.7cbbfab5@posting.google.com>

"Brian McGee" <mcgeeb@jot.nb.ca> wrote in message news:<nNya7.1254$TQ6.194368@news-nb00s0.nbnet.nb.ca>...
> On an NT based machine running ActivePerl 5.6+, I can not get Net::Ping to
> behave.

SNIP

> The Unsupported function alarm function is unimplemented at
> D:/Perl/lib/Net/Ping.pm line 308.

SNIP

> I noticed that I can not get the alarm function to work. I have re-installed
> ActivePerl with the newest version but alarm does not work. That is the
> 'tcp' problem at least, though I have no idea how to fix it.

If you check the document ActivePerl faq5 - Implementation Quirks you
will see the following:

Certain functions don't seem to work on ActivePerl.
There are several functions that are unimplemented in the ActivePerl
system. Here is a complete list of unimplemented functions:

Functions for processes and process groups 
alarm(), getpgrp(), getppid(), getpriority(), setpgrp(), setpriority()

So now you know that they know that alarm() doesnt work. (More to the
point, you arent going crazy)  Unfortunately other than upgrading to
linux I have no idea what you should do.

No doubt however someone else will.

Cheers,
Yves


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

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.  

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


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