[18682] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 850 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 18:10:46 2001

Date: Mon, 7 May 2001 15:10:15 -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: <989273415-v10-i850@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 7 May 2001     Volume: 10 Number: 850

Today's topics:
        random numbers <saras@gj.net>
    Re: random numbers (John Joseph Trammell)
    Re: random numbers (Craig Berry)
    Re: random numbers <bart.lateur@skynet.be>
    Re: redirect to a url & avoiding hacks <tinamue@zedat.fu-berlin.de>
    Re: Script to automatically generate email to Webmaster <godzilla@stomp.stomp.tokyo>
        Script to automatically generate email to Webmaster whe <uwnewsREMOVETHIS@home.com>
    Re: sessions and closures <bart.lateur@skynet.be>
    Re: sessions and closures (Abigail)
        Sort String <root@root.com>
    Re: Sort String <root@root.com>
    Re: Sort String (Randal L. Schwartz)
    Re: Sort String <root@root.com>
    Re: Sort String <djm@spamfree.mcoe.k12.ca.us>
    Re: Sort String (John Joseph Trammell)
    Re: Sort String (Randal L. Schwartz)
    Re: Sort String (Randal L. Schwartz)
    Re: Sort String <thomasvdv@yucom.be>
    Re: Sort String <juex@deja.com>
    Re: Sort String <djm@spamfree.mcoe.k12.ca.us>
    Re: Sort String <hillr@ugs.com>
    Re: Sort String (Randal L. Schwartz)
    Re: Sort String <joe+usenet@sunstarsys.com>
    Re: Sort String <juex@deja.com>
    Re: Sort String (Randal L. Schwartz)
    Re: Sort String (Craig Berry)
    Re: Sort String <djm@spamfree.mcoe.k12.ca.us>
    Re: Sort String <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: unicode support in perl 5.6 -- I'm trying to get it ("Resnick, David")
        Win32::ODBC hangs unless I run with "-d" <tmvatcher@Xbigfoot.com>
    Re: WTD: PERL SCRIPT writing for small task, payment no <lmoran@wtsg.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 7 May 2001 13:37:39 -0600
From: "sas" <saras@gj.net>
Subject: random numbers
Message-Id: <3af6fa1a$1@news.gj.net>

Does anyone have a script that will generate random numbers? Someone told me
I could do it with Perl but I don't know where to start. It must be a 5
digit random number which will be associated with a specific name, (an "ID"
number), I want to check against a log file to be sure the number hasn't
been used already and then add the number and associated name to that log
file.  Any help will be greatly appreciated.
Thanks
Sara S
saras@gj.net




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

Date: Mon, 07 May 2001 21:00:56 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: random numbers
Message-Id: <slrn9fe0va.efg.trammell@bayazid.hypersloth.net>

On Mon, 7 May 2001 13:37:39 -0600, sas <saras@gj.net> wrote:
> Does anyone have a script that will generate random numbers? Someone told me
> I could do it with Perl but I don't know where to start.

A good place would be to search your documentation, perhaps looking
in the index under "random".  Another good start would be searching
the web; can I suggest the search term "Perl random number"?

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


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

Date: Mon, 07 May 2001 21:31:31 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: random numbers
Message-Id: <tfe51jn402f971@corp.supernews.com>

sas (saras@gj.net) wrote:
: Does anyone have a script that will generate random numbers? Someone
: told me I could do it with Perl but I don't know where to start.

You start where you *always* start when faced with questions like these --
by looking at the copious and well-written Perl documentation, which you
obtained conveniently packaged with your Perl distribution.  In this case,
you know you need a function, so the 'perlfunc' documentation is the
obvious place to look.  In a bout of optimism, I tried this:

/m/hermosa/usr3/home/cberry > perldoc perlfunc | grep random
             salt create a random two character string whose
             Entries are returned in an apparently random order.
             The actual random order is subject to change in
             random order.  The actual random order is subject to
     rand    Returns a random fractional number greater than or
                 printf "bits are %*vb\n", " ", $bits;       # random bitstring
     srand   Sets the random number seed for the `rand' operator.
             If EXPR is omitted, uses a semi-random value
             Note that you need something much more random than
             program, or you won't get random numbers out of
             apparently random order.  The actual random order is

Looks like 'rand' is a good bet, hm?  You can then read more about it
using 'perldoc -f rand'.

: It must be a 5 digit random number which will be associated with a
: specific name, (an "ID" number), I want to check against a log file to
: be sure the number hasn't been used already and then add the number and
: associated name to that log file.  Any help will be greatly
: appreciated.

You already have the outline:  Read in the existing IDs, add a new one
not in the list, write out the new IDs.  From there on down it's a
question of mechanics.  I'd suggest posting your best effort and letting
us help you with the parts you aren't getting.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 07 May 2001 21:35:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: random numbers
Message-Id: <o95eft0q7jeit7v3kkna5ve9l8sli5ir89@4ax.com>

sas wrote:

> It must be a 5
>digit random number which will be associated with a specific name, (an "ID"
>number), I want to check against a log file to be sure the number hasn't
>been used already and then add the number and associated name to that log
>file.

Once you get over 100000 visitors, you'll be in trouble.

-- 
	Bart.


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

Date: 7 May 2001 21:56:00 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: redirect to a url & avoiding hacks
Message-Id: <9d75lg$h44c7$2@fu-berlin.de>

Alan J. Flavell <flavell@mail.cern.ch> wrote:

> This is O.T for a Perl language group, but if we're going to tackle
> it at all...

> On 7 May 2001, Tina Mueller wrote:

>> ok, my suggestions if you wanna avoid using CGI.pm is,

> Normally, my suggestion would be "think again".  But if you really and
> truly are going to use none of the other tried and tested facilities
> of CGI.pm in your script, and you're fully acquainted with the
> relevant details of the specification, then it's OK, I suppose.

>> print at least these three lines:

> Not necessarily, because status 302 is defined to be the default
> when a Location: response is issued from a parsed-headers script.
> So it could be left out.

well, this is what CGI.pm does, so it can't be wrong.
if i had a CGI-script which does nothing more than this
redirect, I wouldn't use CGI.pm, because then it is overkill.
(provided that it is not an nph-script)
for anything else a little bit more complex, of course
i would recommend CGI.pm, too.
i responded to the suggestion to use:
print "Location: url/path";

which shows that not using CGI.pm should not be recommended,
because it is missing for keystrokes - "\n\n".
or even more correct, CGI.pm knows better what to
use for the header end.

regards,
tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 07 May 2001 11:54:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Script to automatically generate email to Webmaster when page error  occurs
Message-Id: <3AF6EF5E.496C6E10@stomp.stomp.tokyo>

Netyak wrote:
 
(snipped)

> I want to receive an automatic email message each time a
> Web visitor generates a 404 "page not found" error.


Write a custom error message redirect and associated
email program per information available at this site:

http://httpd.apache.org/docs/custom-error.html


Godzilla!


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

Date: Mon, 07 May 2001 18:11:06 GMT
From: "Netyak" <uwnewsREMOVETHIS@home.com>
Subject: Script to automatically generate email to Webmaster when page error occurs
Message-Id: <_yBJ6.125023$xN4.8011651@news1.sttls1.wa.home.com>

I want to receive an automatic email message each time a Web visitor generates a
404 "page not found" error.

Thanks



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

Date: Mon, 07 May 2001 19:34:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: sessions and closures
Message-Id: <40udftskncrpafv9215g9dculok2an0acf@4ax.com>

Abigail wrote:

>F. Xavier Noria (fxn@isoco.com) wrote:
>
>:) That's why I asked whether someone
>:)  had written (or had considered to write) cgis like that and would like to
>:)  share his or her thoughts.

>I fail to see why Perl lacks this. Perl happily stores a reference to
>a closure in a hash.

CGI's are independent prgrams. Storing a closure in a hash is not
enough. You need to be able to save the closure on disk, later reload it
in a fresh context, and continue from there.

-- 
	Bart.


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

Date: Mon, 7 May 2001 21:30:56 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: sessions and closures
Message-Id: <slrn9fe50g.t91.abigail@tsathoggua.rlyeh.net>

Bart Lateur (bart.lateur@skynet.be) wrote on MMDCCCVI September MCMXCIII
in <URL:news:40udftskncrpafv9215g9dculok2an0acf@4ax.com>:
{}  Abigail wrote:
{}  
{} >F. Xavier Noria (fxn@isoco.com) wrote:
{} >
{} >:) That's why I asked whether someone
{} >:)  had written (or had considered to write) cgis like that and would like to
{} >:)  share his or her thoughts.
{}  
{} >I fail to see why Perl lacks this. Perl happily stores a reference to
{} >a closure in a hash.
{}  
{}  CGI's are independent prgrams.
    ^^^^


Are you claiming that CGI equals Perl, or are you claiming that CGI
programs written in LISP magically overcome the obstacle of being
restarted?

Of course the CGI isn't suitable for this task. But that's not a langauge
issue, now is it? 



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'


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

Date: Mon, 7 May 2001 14:07:42 -0400
From: root <root@root.com>
Subject: Sort String
Message-Id: <3af6e549$1@addressworks2.umassd.edu>

Hi,

Here's a little challenge.  I want to sort an alpha string grouped by two 
characters. Example:

$original = "abracadeba"

after sort... (?)

$sorted = "abbacadera                            "

I want to do this with a minimum of code.

Thanks.

Thomas.


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

Date: Mon, 7 May 2001 14:09:16 -0400
From: root <root@root.com>
Subject: Re: Sort String
Message-Id: <3af6e5a8$1@addressworks2.umassd.edu>

Ignore those spaces in $sorted.  My cat walked over my keyboard :-)

Thomas

root wrote:

> Hi,
> 
> Here's a little challenge.  I want to sort an alpha string grouped by two
> characters. Example:
> 
> $original = "abracadeba"
> 
> after sort... (?)
> 
> $sorted = "abbacadera                            "
> 
> I want to do this with a minimum of code.
> 
> Thanks.
> 
> Thomas.
> 



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

Date: 07 May 2001 11:20:11 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m1u22xdns4.fsf@halfdome.holdit.com>

>>>>> "root" == root  <root@root.com> writes:

root> Hi,
root> Here's a little challenge.  I want to sort an alpha string grouped by two 
root> characters. Example:

root> $original = "abracadeba"

root> after sort... (?)

root> $sorted = "abbacadera                            "

root> I want to do this with a minimum of code.

Smells like homework.  What's the context of this question?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 7 May 2001 14:19:20 -0400
From: root <root@root.com>
Subject: Re: Sort String
Message-Id: <3af6e803$1@addressworks2.umassd.edu>

Trust me it's not homework.  :-)  It is something I need to sort a list of 
codes that are grouped in pairs.


Randal L. Schwartz wrote:

>>>>>> "root" == root  <root@root.com> writes:
> 
> root> Hi,
> root> Here's a little challenge.  I want to sort an alpha string grouped
> by two root> characters. Example:
> 
> root> $original = "abracadeba"
> 
> root> after sort... (?)
> 
> root> $sorted = "abbacadera                            "
> 
> root> I want to do this with a minimum of code.
> 
> Smells like homework.  What's the context of this question?
> 



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

Date: Mon, 07 May 2001 18:30:04 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Sort String
Message-Id: <MQBJ6.8985$po.36251@typhoon.sonic.net>

How about this:

my ($sorted, %hash, @snips);
$original = "abracadeba";
@snips = split /(\w\w)/,$original;
foreach (@snips)
   {
   $hash{$_} = 1;
   }


foreach (sort keys %hash)
   {
   $sorted .= $_;
   }


print $sorted,"\n";







"root" <root@root.com> wrote in message
news:3af6e549$1@addressworks2.umassd.edu...
> Hi,
>
> Here's a little challenge.  I want to sort an alpha string grouped by two
> characters. Example:
>
> $original = "abracadeba"
>
> after sort... (?)
>
> $sorted = "abbacadera                            "
>
> I want to do this with a minimum of code.
>
> Thanks.
>
> Thomas.




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

Date: Mon, 07 May 2001 18:32:47 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Sort String
Message-Id: <slrn9fdo9i.dsd.trammell@bayazid.hypersloth.net>

On Mon, 7 May 2001 14:07:42 -0400, root@root.com <root@root.com> wrote:
> I want to sort an alpha string grouped by two characters.
[snip]

[ ~ ] perl -ne 'print sort /(..)/g; print "\n"'
foobar
arfoob
abracadabra
abbrcadara
^D
[ ~ ]

-- 
Rule #0: Spam is theft.


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

Date: 07 May 2001 11:37:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m1g0ehdmzq.fsf@halfdome.holdit.com>

>>>>> "root" == root  <root@root.com> writes:

root> Trust me it's not homework.  :-) 

Try posting from a real address when you say that.

And stop top-posting.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 07 May 2001 11:38:27 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m1bsp5dmxo.fsf@halfdome.holdit.com>

>>>>> "Dave" == Dave  <djm@spamfree.mcoe.k12.ca.us> writes:

Dave> How about this:
Dave> my ($sorted, %hash, @snips);
Dave> $original = "abracadeba";
Dave> @snips = split /(\w\w)/,$original;
Dave> foreach (@snips)
Dave>    {
Dave>    $hash{$_} = 1;
Dave>    }


Dave> foreach (sort keys %hash)
Dave>    {
Dave>    $sorted .= $_;
Dave>    }


Dave> print $sorted,"\n";

That's one hard way.

Easier:

my $result = join "", sort $original =~ /(..)/g;

But I still hate doing someone's homework for them. :(

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 7 May 2001 14:36:39 -0400
From: Thomas Van de Velde <thomasvdv@yucom.be>
Subject: Re: Sort String
Message-Id: <3af6ec12$1@addressworks2.umassd.edu>

??  I don't get this

John Joseph Trammell wrote:

> On Mon, 7 May 2001 14:07:42 -0400, root@root.com <root@root.com> wrote:
>> I want to sort an alpha string grouped by two characters.
> [snip]
> 
> [ ~ ] perl -ne 'print sort /(..)/g; print "\n"'
> foobar
> arfoob
> abracadabra
> abbrcadara
> ^D
> [ ~ ]
> 



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

Date: Mon, 7 May 2001 11:43:35 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Sort String
Message-Id: <3af6ecd7$1@news.microsoft.com>

"root" <root@root.com> wrote in message
news:3af6e549$1@addressworks2.umassd.edu...
> Hi,
>
> Here's a little challenge.  I want to sort an alpha string grouped by two
> characters. Example:
> $original = "abracadeba"
> after sort... (?)
> $sorted = "abbacadera                            "
> I want to do this with a minimum of code.

Well, the only interesting part is obviously how to split the string into
two-letter elements:
    $sorted = join '', sort grep($_, split /(..)/, $original);

Anyone wants to play golf on this?

jue




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

Date: Mon, 07 May 2001 18:48:37 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Sort String
Message-Id: <96CJ6.8987$po.36141@typhoon.sonic.net>

> my $result = join "", sort $original =~ /(..)/g;

Wow, that is some excellent code!  I just found this newsgroup today and
already you guys have come up with some great answers in less then 30
minutes!  This NG rocks!

-Dave

"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m1bsp5dmxo.fsf@halfdome.holdit.com...
> >>>>> "Dave" == Dave  <djm@spamfree.mcoe.k12.ca.us> writes:
>
> Easier:
>
> my $result = join "", sort $original =~ /(..)/g;





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

Date: Mon, 07 May 2001 11:45:27 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: Sort String
Message-Id: <3AF6ED47.E52C969F@ugs.com>

"Randal L. Schwartz" wrote:
[snipped]
> That's one hard way.
> 
> Easier:
> 
> my $result = join "", sort $original =~ /(..)/g;
> 
I don't get this?? Can someone explain??

Ron


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

Date: 07 May 2001 12:01:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m14ruxdlug.fsf@halfdome.holdit.com>

>>>>> "Jürgen" == Jürgen Exner <juex@deja.com> writes:

Jürgen>     $sorted = join '', sort grep($_, split /(..)/, $original);

What's the grep in there for?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 07 May 2001 15:13:42 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Sort String
Message-Id: <m3heyx0y6x.fsf@mumonkan.sunstarsys.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

> >>>>> "Jürgen" == Jürgen Exner <juex@deja.com> writes:
> 
> Jürgen>     $sorted = join '', sort grep($_, split /(..)/, $original);
> 
> What's the grep in there for?

Not that it matters too much, but I guess it's because half the items in 
the list returned by split are empty :-)

-- 
Joe Schaefer    "In order to form an immaculate member of a flock of sheep one
                                must, above all, be a sheep."
                                               --Albert Einstein


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

Date: Mon, 7 May 2001 12:15:01 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Sort String
Message-Id: <3af6f443$1@news.microsoft.com>

"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m14ruxdlug.fsf@halfdome.holdit.com...
> >>>>> "Jürgen" == Jürgen Exner <juex@deja.com> writes:
>
> Jürgen>     $sorted = join '', sort grep($_, split /(..)/, $original);
>
> What's the grep in there for?

Guess my Perl Golf handicap must be somewhere around 500 :-(

The grep was meant to remove the empty elements from the array (as returned
by the split (/../)).
However, you are right: this is unnecessary because the elements are join'ed
anyway.
And of course you don't need the split to begin with because a simple RE
/(..)/g works even better.

jue




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

Date: 07 May 2001 12:34:26 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sort String
Message-Id: <m1vgndc5rx.fsf@halfdome.holdit.com>

By the way, your email bounces... please update your mail header,
or make it clear that you have a spamproofed address.

>>>>> "Jürgen" == Jürgen Exner <juex@deja.com> writes:

Jürgen> And of course you don't need the split to begin with because a simple RE
Jürgen> /(..)/g works even better.

97% of the uses of split /(___)/ can be replaced by a cleaner /(___)/g
instead, in my observation.  I think the trouble is that we invented
this split /(..)/ idiom before Perl5 came along, and now nobody is
looking at the much cleaner m//g.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 07 May 2001 19:55:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Sort String
Message-Id: <tfdvd56mgqc605@corp.supernews.com>

root (root@root.com) wrote:
: Here's a little challenge.  I want to sort an alpha string grouped by two 
: characters. Example:
: 
: $original = "abracadeba"
: 
: after sort... (?)
: 
: $sorted = "abbacadera                            "

Not sure if all that trailing whitespace is meant to be significant;
doesn't make sense given your spec.  Assuming it is not supposed to be
there, here's my take:

  $sorted = join '', sort($original =~ /../g);

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 07 May 2001 20:14:54 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Sort String
Message-Id: <2nDJ6.8996$po.36237@typhoon.sonic.net>

> > my $result = join "", sort $original =~ /(..)/g;
> >
> I don't get this?? Can someone explain??

my $LocalVariable = (put "" between every instance provided by sort), sort
contains serveral matches of two letters over and over;

to understand this, you need to go from right to left.


/(..)/g   This regular expression looks for two characters, and the /g makes
it do it as many times as there are matches.  the result of .. is saved into
$1, a temporary variable, which is passed in list form (all of the $1's) are
passed to sort()

sort() is a list operator that takes the list --and, well, sorts them..
inside of the sort, is a statement that is true more then once, and
therefore returns more then one string, or a list.

Sort takes a list and spits out a list

Join() takes a list, and puts a scalar between each time it hits.  in this
case "" means put nothing between each instance.

The results of that join() are put into $result.

Said over again, but filled in:

1:    my $result = join "", sort $original =~ /(..)/g;
2:    my $result = join "", sort (ab, ra, ca, de, ba);
3::   my $result = join "",(ab, ba, ca, de, ra)
4:    my $result = "abbacadera"






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

Date: 07 May 2001 19:54:59 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Sort String
Message-Id: <8666fd9bos.fsf@jon_ericson.jpl.nasa.gov>

Ron Hill <hillr@ugs.com> writes:

> "Randal L. Schwartz" wrote:
> [snipped]
> > That's one hard way.
> > 
> > Easier:
> > 
> > my $result = join "", sort $original =~ /(..)/g;
> > 
> I don't get this?? Can someone explain??

Read it backwards:

my $original = "abracadeba";
my @temp = $original =~ /(..)/g;# extract into array (character pairs)
@temp = sort @temp;             # sort the array
my $result = join "", @temp;    # join into character string.

Randal avoided the @temp array by using the output of one step as the
input to the next.  (Kind of like piping one shell command to the
next.)  The first step is the most complicated because it relies on
the way regex captures work in perl.  Read perlretut/"Extracting
matches" for an explanation.

Jon


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

Date: Mon, 7 May 2001 20:04:37 +0000 (UTC)
From: David.Resnick@comverse.com ("Resnick, David")
Subject: Re: unicode support in perl 5.6 -- I'm trying to get it to work l
Message-Id: <CD0BA48D13A9D311A274009027C5B4B1017C9701@intm1.btrd.bostontechnology.com>

[... my original question about why isalpha wasn't working on unicode ...]

>You must use the "properties"  \p{IsAlpha}, \p{IsDigit}, and
>\p{IsPrint} for regexes (unfortunately this method produces
>error messages for certain characters...):

>    ### method (1)
>    $alpha++ if ($letter =~ /\p{IsAlpha}/);
>    $digit++ if ($letter =~ /\p{IsDigit}/);
>    $print++ if ($letter =~ /\p{IsPrint}/);

When I tried the things suggested (which seem like the right idea),
I get errors as follows:
Malformed UTF-8 character at /u/dresnick/bin/utf8-test-summary line 22

These occur if $letter is obtained by chr($i) when $i is between
0x80 and OxFF.  Are these being interpreted as Latin-1 or something?
Did you not see these warnings (was your perl invoked with a -w?)?

Anyway, thanks.  Though I'm quite bewildered why functions like
isalpha haven't migrated from byte to character arguments, as that
seems like the way the rest of perl is going and I see no downside...

-David

-- 
Posted from ns2.comverse.com [63.64.185.39] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: Mon, 7 May 2001 14:38:03 -0700
From: "Toni Vatcher" <tmvatcher@Xbigfoot.com>
Subject: Win32::ODBC hangs unless I run with "-d"
Message-Id: <9d75k0$6gm$1@nnrp1.phx.gblx.net>

The  nice people where I work just upgraded my PC to an 833MHz PC running
Windows 2000.

I'm trying to move all of my various (working) Perl tools over and am having
a problem with Win32:ODBC.

I am currently using ActiveState build 522 with their Perl Debugger.  If I
just run the script from the command prompt, it hangs in the ODBC call:

    my $DSN = "DSN=PCMS;UID=user;PWD=password";
    my $db = new Win32::ODBC($DSN);

If I use "-d" so that it brings up the ActiveState debugger, and then select
"run" (F5), it works correctly.

If anyone has any ideas, I'd appreciate it.  I'm stumped on this one.

Thanks!

Toni




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

Date: Mon, 07 May 2001 14:54:47 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: WTD: PERL SCRIPT writing for small task, payment no problem!
Message-Id: <iqrdftgcuki16hoqie70iotuher7qjpn8v@4ax.com>

On Sat, 05 May 2001 23:05:32 GMT, David <dbmartin5@home.com> wrote
wonderful things about sparkplugs:


***(to run on a Windows NT workstation)***

>You may wish to mention if this is DOS, Unix, etc.
>
>If unix either Perl or a shell script will do.
>
>On Wed, 2 May 2001 17:15:29 +0100, "Helen Greenacre"
><helen.greenacre@ntlworld.com> wrote:
>
>>Hi
>>
>>I do not know Perl myself and need a script writing, payment is no
>>problem...see below..
>>
>>The task
>>---------
>>A text file is produced from our system, it could contain a number of lines
>>(around 10-60) it looks something like this
>>
>>23456076, ee, 12,12,12, 31/10/2001
>>03046789, es, 33,12,12, 12/12/2001
>>03446889, es, 33,12,12, 12/12/2001
>>06049789, es, 33,12,12, 12/12/2001
>>13046789, es, 33,12,12, 12/12/2001
>>
>>etc etc...
>>
>>The beginning 8 numbers on each line represent a file which is actually a
>>PDF (so, example first line 23456076 is infact 23456076.pdf etc..)
>>
>>I need a Perl script that looks a the 'input' file and looks at the first 8
>>digits of each line, then looks at a mapped drive (one location) to find the
>>relevant files (which all end with .pdf), the script would then have to COPY
>>(not move) the pdf's into another mapped drive..
>>
>>A log file must be produced that displays the files that have been found and
>>those that have not (ie the ones that have errored or missing)
>>
>>I have a small program that constantly scans folders for input files and
>>then runs a certain command on them, the idea would be that the original
>>input text file is dropped into a 'hot' folder, the Perl script then runs
>>against this file etc....
>>
>>If anyone would be interested in writing this script ***(to run on a Windows NT
>>workstation)*** please E-mail me to discuss timescale/price etc..
>>
>>Thanks
>>
>>Helen
>>
>>
>>


--
print "\x{263a}" 


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

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


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