[17561] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4981 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 28 18:05:58 2000

Date: Tue, 28 Nov 2000 15:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975452715-v9-i4981@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Nov 2000     Volume: 9 Number: 4981

Today's topics:
    Re: basic keys question <mjcarman@home.com>
    Re: basic keys question (Andrew N. McGuire)
    Re: Can anyone help me with this script??? (Martien Verbruggen)
    Re: checking variable type <iltzu@sci.invalid>
        Compile script to exe on many platforms <berube@odyssee.net>
    Re: Compile script to exe on many platforms fallenang3l@my-deja.com
        FAQ 4.18:   How do I unescape a string? <faq@denver.pm.org>
        Gotta weird problem...disappearing variables <dbohling@newsfactor.com>
    Re: HHHHEEEELLLLLPPPPPPPPPPPPP!!!!!! (Andrew N. McGuire)
    Re: How do you install packages manually without PPM (A fallenang3l@my-deja.com
    Re: How to find what is between n'th and the next tab? <bart.lateur@skynet.be>
        How to get directory name where script is located and i dnshtern@my-deja.com
    Re: How to get directory name where script is located a (Flint Slacker)
    Re: how to test if cgi-script was shift-reloaded by bro <elijah@workspot.net>
        Manipulating File Modification Time <garcia868@yahoo.com>
        perl dll for gui test tools ? cfrjlr@my-deja.com
    Re: Perl, Mysql and large datasets <no@spam.net>
    Re: PLEASE HELP ME???!!!! <bart.lateur@skynet.be>
    Re: PLEASE HELP ME???!!!! <joe+usenet@sunstarsys.com>
    Re: PLEASE HELP ME???!!!! <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Nov 2000 08:31:10 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: basic keys question
Message-Id: <3A23C1AE.1BDEA30D@home.com>

nougat wrote:
> 
> I'm in need of some clarification as to the order in which the keys
> operator unwinds a hash when used in a foreach loop.

Let's not confuse the issue; keys() and foreach() are different
operators and are not related. They're just often used together.

If you peruse the docs, you'll discover that keys() returns things in an
"apparently random" order. It isn't really random, of course. It's
determined by the hashing algorithm, but that could change without
notice so you shouldn't rely on it. (It's just an "implementation
detail" of Perl). The only thing you are guaranteed is that keys(),
values(), and each() will always return things in the same order.

> %fields = ("REG" => "Regular", "WIN" => "Window");
> 
> foreach $field_key (keys %fields) {
>      $type_field = $fields{$field_key};
> }
> 
> When I do this, the first value assigned to $field_key is "WIN", 
> not "REG". [...] What I'm trying to accomplish is some way to
> initialize the hash so that I can return the keys in a 
> predictable order.
[...]
> When I preface the keys operator with the sort operator, all is 
> fine, as they're returned sorted alphabetically. However, not 
> every instance in which I need to do something like this can be
> resolved that way.

I've found that 99.9% of the time, I either don't care about the order,
or I want to sort() it in some particular way anyway. Remember, you can
build an arbitrarily complex sort sub -- it doesn't have to be just
'sort keys(%hash)'.

Once in a blue moon, I actually want keys() to return things in the
order in which they were added to the hash. (i.e. an ordered hash) For
those rare circumstances, use the Tie::IxHash module.

-mjc


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

Date: 28 Nov 2000 13:35:00 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: basic keys question
Message-Id: <871yvv51qz.fsf@hawk.ce.mediaone.net>

>>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:

TM> nougat <kulabocca69@hotmail.com> wrote:
>> Subject: basic keys question
TM>           ^^^^^

TM> You might expect that "basic" Questions are Asked Frequently.

[ snip ]

I have not seen a question about BASIC here yet, oh, wait..
_basic_.  Sorry.

[ fleeing for cover, sorry could not resist ]

anm
-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Tue, 28 Nov 2000 22:55:03 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Can anyone help me with this script???
Message-Id: <slrn928dqm.br5.mgjv@verbruggen.comdyn.com.au>

On Tue, 28 Nov 2000 15:07:31 -0000,
	Ross <patelro@viacode.com> wrote:
> Hi All!
> 
> I'm desperately hoping that their is some kind should out there that can
> help me!!

The documentation can help you. Learn to use it. Read it.

> What I'm trying to create is a program that will use the /etc/dict (or other
> wordfile) and pick random words from this file and insert them into a

Perl FAQ, section 5, question 'How do I select a random line from a
file?'.

> textfile, replacing each instance of 'ZZZZ' with one of these random words.

open the file, loop over the lines, use s/ZZZZ/$word/g to replace
them. 

Perl FAQ, Section 5, question 'How do I change one line in a
file/delete a line in a file/insert a line in the middle of a
file/append to the beginning of a file?'

> Finally, when the string 'ZZZX' is encountered, a random word is used to

See above.

> replace this value and the new file is saved under a unique name.  The
> process then starts again using the original file with all the ZZZZ values
> etc, creating a number of these output documents all with unique names.

lather, rinse, repeat.

> What I've created so far is a (semi-buggy) file copying program.  It's

Why don't you show us what you've done? We're generally quite
receptive to people who SHOW us that they've done some things, read
the documentation, and are asking for pointers. We generally are less
helpful to people who just ask us to write a program.

> designed to handle most errors or exceptions, and copy a buffer full of data
> to a designated file (if it doesn't exist the file is created).
> I just can't quite get it to do what I want (grrrrr....).

Show us what you have, and we'll dissect.

> If anyone can help, I'd be most appreciative and will post you a pint!
> Alternatively, I'll happily donate my copy of MS Windows 2000 to anyone who
> can save me!

Ugh, no thanks. I still have an unused one that came with my laptop. I
don't need another one of these horrors.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: 28 Nov 2000 21:24:10 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: checking variable type
Message-Id: <975445500.5134@itz.pp.sci.fi>

In article <u98zq4os4a.fsf@wcl-l.bham.ac.uk>, nobull@mail.com wrote:
>
>>   my $foo = "1.5";
>>   my $bar = 1 + $foo;
>>   print "What the heck happened to \$foo???\n" if ~$foo ne ~"$foo";
>
>So using a variable in a numeric context can change its type if it is
>a canonical representation of a number.  This is interesting but
>doesn't alter the answer to question 3.

Worse than that, actually.

  my $foo = "150.00e-002";
  my $bar = 0 + $foo;
  print "$foo is a ", (~$foo ne ~"$foo" ?'number':'string'), ".\n";
  print "$bar is a ", (~$bar ne ~"$bar" ?'number':'string'), ".\n";


>> "Get real!  This is a discussion group, not a helpdesk.  You post
>>  something, we discuss its implications.  If the discussion happens to
>>  answer a question you've asked, that's incidental." -- nobull in clpm
>
>Hmmm... sounds familiar :-)

It's a piece of advice that IMHO bears repeating in this newsgroup.
The fact that is also serves as an amusing .sigquote is incidental.

I do have a nice collection of quotes accumulating from catching up
with rasfc.  Maybe I ought to use one of those once in a while..

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"Saying something doesn't suit the demands of the present market may well
 mean, 'Nobody's buying badly-written hackwork right now.'"
                        -- Lawrence Watt-Evans in rec.arts.sf.composition



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

Date: Tue, 28 Nov 2000 15:22:41 -0500
From: "Neb" <berube@odyssee.net>
Subject: Compile script to exe on many platforms
Message-Id: <DsUU5.275$s8.21196@news.globetrotter.net>

Hi,

I have a script that I want to compile to exe on different platform (Unix
and Windows).  Is it possible?

thanks,

neb





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

Date: Tue, 28 Nov 2000 20:48:52 GMT
From: fallenang3l@my-deja.com
Subject: Re: Compile script to exe on many platforms
Message-Id: <9015nh$d59$1@nnrp1.deja.com>

In article <DsUU5.275$s8.21196@news.globetrotter.net>,
  "Neb" <berube@odyssee.net> wrote:
> Hi,
>
> I have a script that I want to compile to exe on different platform
(Unix
> and Windows).  Is it possible?
>
> thanks,
>
> neb
>
>

http://www.indigostar.com/perl2exe.htm


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


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

Date: Tue, 28 Nov 2000 19:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ 4.18:   How do I unescape a string?
Message-Id: <NwTU5.148$QX6.171059712@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 unescape a string?

    It depends just what you mean by ``escape''. URL escapes are dealt with
    in the perlfaq9 manpage. Shell escapes with the backslash (`\')
    character are removed with:

        s/\\(.)/$1/g;

    This won't expand `"\n"' or `"\t"' or any other special escapes.

- 

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 comming 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.

If you are not able to find this or other Perl documentation from
your installation you may access it via the web by following the
appropriate links from one of the addresses listed below.

    http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
    http://www.perldoc.com
    http://www.cpan.org
    http://www.perl.com

Answers to questions about LOTS of other stuff, mostly not related to
Perl, can be found at

    news:news.answers

and in the many thousands of other useful Usenet news groups.

The perlfaq manual pages contain the following copyright notice.

  AUTHOR AND COPYRIGHT

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

    When included as an integrated part of the Standard
    Distribution of Perl or of its documentation (printed or
    otherwise), this work is covered under Perl's Artistic
    License.  For separate distributions of all or part of
    this FAQ outside of that, see the perlfaq manpage.

    Irrespective of its distribution, all code examples here
    are public domain.  You are permitted and encouraged to
    use this code and any derivatives thereof in your own
    programs for fun or for profit as you see fit.  A simple
    comment in the code giving credit to the FAQ would be
    courteous but is not required.

-- 
    This space intentionally left blank


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

Date: Tue, 28 Nov 2000 17:58:29 -0500
From: Daniel Bohling <dbohling@newsfactor.com>
Subject: Gotta weird problem...disappearing variables
Message-Id: <975452543.2117840293@isp-east.usenetserver.com>

This one blows me away...
the variable $body contains a news story on one line
it is suddenly undefined on the next
then reappears.


sub index {
	my $self = shift;
	my $id = shift;
	my $title = shift;
	my $body = shift;
	
	print "id:\t$id\n" if $self->{print};
	print "title:\t$title\n" if $self->{print};
	
	print "Body:\t|$body|\n" if $self->{print}; 
#^^^^^^^^^^^prints $body just fine
	unless ($body) { $self->die_gracefully("Missing body:$body"); }
#^^^^^^^^^^^$body is undefined here?
	print "Body:\t|$body|\n" if $self->{print};
#^^^^^^^^^^^prints $body just fine again
	$self->die_gracefully("Missing or incorrect id no.") unless ($id  =~ /^\d+$/);
	$self->die_gracefully("Missing title.") unless $title;
#^^^^^^^^^^^the two lines above work fine as well





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

Date: 28 Nov 2000 14:38:30 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: HHHHEEEELLLLLPPPPPPPPPPPPP!!!!!!
Message-Id: <87y9y33k8p.fsf@hawk.ce.mediaone.net>

>>>>> """ == "-"  <jt2000@jt2000.it> writes:

"> This is a multi-part message in MIME format.
"> ------=_NextPart_000_0004_01C0596E.BEBCE920
"> Content-Type: text/plain;
"> 	charset="iso-8859-1"
"> Content-Transfer-Encoding: quoted-printable

No good can come of this...

"> I've Oracle8i and I'm trying to connect from a perl-script, but I'm not =
"> be able to make the connect, which is the right command
"> to connect an Oracle db.
"> The Oracle8i is installed in a Win98 pc but I've also one in a WinNT =
"> (The error is the same)
"> PLEASE, ANYONE CAN HELP ME ?

Yes.

1.  Do not post multi-part MIME messages.
2.  "HHHHEEEELLLLLPPPPPPPPPPPPP!!!!!!" is a horrible subject line.
3.  Perl subs/ops are not 'commands'.
4.  PEOPLE DO NOT LIKE TO BE YELLED AT.
5.  Check the online documentation for the DBI module. Search for connect.
6.  If the docs do not satisfy you needs, post code (minimal) that
    illustrates your problem, also post errors.

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Tue, 28 Nov 2000 20:52:27 GMT
From: fallenang3l@my-deja.com
Subject: Re: How do you install packages manually without PPM (ActiveState WinNT)...
Message-Id: <9015u8$dfu$1@nnrp1.deja.com>

In article <_VRU5.1598$Pe4.177313@juliett.dax.net>,
  "Lee Francis Wilhelmsen" <leefw@c2i.net> wrote:
> Hi
>
> Can anyone tell me how do I install packages manually without PPM
> (ActiveState WinNT)
>
> ... the machine I'm using isn't connected to the net.
>
> regards
> Lee
>
>

How can I use modules from CPAN?
As of version 5.005, ActivePerl supports the MakeMaker utility. This
allows you to install modules from CPAN, but requires you to have a
make utility, such as nmake or dmake. Modules are generally distributed
in gzipped tar files, such as Data-Dumper-2.08.tar.gz.

However, ActivePerl includes the Perl Package Manager (PPM), a utility
that allows you to install modules, including modules that contain
binary extensions. You should consider using PPM to install a module,
as this greatly simplifies the management of modules.

Nevertheless, there are times when it is necessary to build a module
from source. Typically, an installation session goes something like
this:

Extract the module. This creates a directory based on the name of the
archive.

    gzip -d -c Data-Dumper-2.08.tar.gz | tar xvf -

Change directory to the module's directory.

    cd Data-Dumper-2.08

Consult the README file.

    more < README

Run the Makefile.PL script. This uses the MakeMaker module to build a
makefile you can build the extension with.

    perl Makefile.PL

Run your make utility. This prepares the module for installation, and
compiles any extension if one is present.

    nmake

If this module has tests, run them.

    nmake test

If the tests succeeded, install the module.

    nmake install

See Where can I find Win32 ports of UNIX tools? for information on the
availability of tools like gzip and tar.


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

Where do I get make for Win32?
nmake
nmake is a 'make' like program for Win32 systems by Microsoft. It is
available from ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe



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


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

Date: Tue, 28 Nov 2000 21:30:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to find what is between n'th and the next tab?
Message-Id: <kv882tom36pc6goang7rvp8824cjutpbfv@4ax.com>

Anno Siegel wrote:

>That is an interesting property of closures.  It is hard to see,
>however, how this can be realized without repeated compilation
>of the regex.

It needs to be compiled only once per column. So, if you want the 17th
column of each record, you get one closure for this column, and call it
for each line.

-- 
	Bart.


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

Date: Tue, 28 Nov 2000 22:03:27 GMT
From: dnshtern@my-deja.com
Subject: How to get directory name where script is located and is run from?
Message-Id: <901a3b$h6v$1@nnrp1.deja.com>

I am using Perl under Win98. Environment
variable, %ENV, does not contain the information.
Could anyone help me with the problem?

Thanks,
DS


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


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

Date: Tue, 28 Nov 2000 22:24:14 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: Re: How to get directory name where script is located and is run from?
Message-Id: <3a2a303a.16398655@news.tcn.net>


You might be able to use Cwd, not sure on windows....

use Cwd;
$dir = cwd();

Flint


On Tue, 28 Nov 2000 22:03:27 GMT, dnshtern@my-deja.com wrote:

>I am using Perl under Win98. Environment
>variable, %ENV, does not contain the information.
>Could anyone help me with the problem?
>
>Thanks,
>DS
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.



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

Date: 28 Nov 2000 19:36:36 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: how to test if cgi-script was shift-reloaded by browser?
Message-Id: <eli$0011281424@qz.little-neck.ny.us>

In comp.lang.perl.misc, Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Gert Brinkmann wrote in comp.lang.perl.misc:
> > i need to know if a CGI-script was 
> > 
> > a) loaded normally called by clicking an link or typing it manually,
> > b) reloaded by using the right-mouse-menu-reload-item or the
> > toolbar-reload-button,
> > c) <SHIFT>-reloaded by one of these.
> The answer to your question is : you can't. You can examine carefully
> the behavior of a specific version of a browser on a specific version of
> an OS and try to deduce heuristics from there. But you will not get
> reliable data.

Case in point:

I've written a page fetch tool that knows the headers used by 16
different user agents (five each different platforms/versions of
Netscape and Explorer, three text-only browsers, plus Opera, iCab,
and lwp-request). Any tool that attempts to use request header
sniffing to identify this user agent will fail. Mere playing with
the User-Agent: header I leave to lessor tools. :^)

The difference in headers is dramatic. In my set lynx (2.8.1) has
the largest headers, due to insane Accept*: headers. IE 5.0 the
smallest (excluding lwp-request) partially because of a very
accepting 'Accept: */*' header.

Elijah
------
still needs to capture headers for Netscape 6, IE 5.5, Mosaic, wget, emacs...


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

Date: Tue, 28 Nov 2000 12:17:58 -0800 (PST)
From: J Garcia <garcia868@yahoo.com>
Subject: Manipulating File Modification Time
Message-Id: <20001128201758.14865.qmail@web1607.mail.yahoo.com>

I know how to use stat(filename) to access file
modification time ($mtime) and then use
localtime($mtime) to get exact HHMMSS info for a file.
After trying to substitute new values for HHMMSS, I
found out that the file time was not modified. I have
tried several things including opening and closing
file and trying to modify file time in between.

Is it possible to modify file modification times with
Perl and is there some neat trick that I have
overlooked? Thanks for helping out.

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/


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

Date: Tue, 28 Nov 2000 19:43:13 GMT
From: cfrjlr@my-deja.com
Subject: perl dll for gui test tools ?
Message-Id: <9011sf$9m7$1@nnrp1.deja.com>



Has anybody compiled perl into a DLL which can be called by an
automated gui test tool, such as winrunner, Visual Test or Silk Test ?

It would be great to access the perl functions that way.


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


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

Date: Tue, 28 Nov 2000 20:39:36 GMT
From: "Misanthrope" <no@spam.net>
Subject: Re: Perl, Mysql and large datasets
Message-Id: <cKUU5.12266$II2.1235893@newsread2.prod.itd.earthlink.net>


200..300 ain't large.

In any case, learn to use the MySQL version of the SELECT statement LIMIT
clause.

You can pass the start and stop point back and forth using standard CGI
techniques.


"Hazi Gharagozlou" <hazi@blackeyes.org> wrote in message
news:3A223D9E.B2662B2D@blackeyes.org...
> Thanks for the reply. I am not going to debate the merits of Mysql (your
comments are deja on record).
>
> Let's say that my dataset returns between 200 to 300 records (thumbnails
of pictures included) My script does a count of the number of records and
> determins that all the records will be over 20 html pages. Next I execute
the query and have all the dataset stored in an array and proceed to do next
> and previous page navigation. I would think this is a big waste of
bandwidth if the user decides that what he or she is looking is on the first
page.
>
> Maybe I am hoping but I am looking for a more elegant solution.
>
> Abigail wrote:
>
> > On Mon, 27 Nov 2000 10:16:01 +0100, Hazi Gharagozlou
(hazi@blackeyes.org) wrote in comp.lang.perl.misc <URL:
news:<3A222651.A7E0F264@blackeyes.org>>:
> > ++ I have finally gotten things under control (CGI, Perl and Mysql) what
a
> > ++ diffrent world from Client-Server database application development.
> > ++
> > ++ However I will thank anybody in advance if they can shed light on how
to
> > ++ handle large datasets.
> >
> > Well, if I would have to handle large datasets, I wouldn't be using
mysql.
> >
> > ++ In the past I controlled the result of a query by using database
> > ++ cursors. From my understanding Mysql does not support cursors and on
top
> > ++ of that the my Perl script is connected to the database while the
script
> > ++ is running. Once the page is on the client the database has been
> > ++ disconneceted.
> >
> > Cursors are *not* the way to handle large datasets. Avoid cursors
> > at all costs if performance is an issue.
> >
> > ++ I have come with a solution of saving the query result on the
server's
> > ++ hard disk, but this seems to be a big waste of bandwidth if the user
> > ++ decides to abandon the query after the first page.
> >
> > "abandon the query after the first page"? What do you mean with that?
> >
> > Abigail
>
>




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

Date: Tue, 28 Nov 2000 21:43:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <hb982ts4o4chonep8u3e6q713d8i7slj90@4ax.com>

Ross wrote:

>What I'm trying to create is a program that will use the /etc/dict (or other
>wordfile) and pick random words from this file and insert them into a
>textfile, replacing each instance of 'ZZZZ' with one of these random words.

Wrong newsgroup. There no module in sight. Follow-ups set to
comp.lang.perl.misc.

Assuming @words contains the list of words,

	s/ZZZZ/$words[rand @words]/ge;


If anybody can explain me this: if you don't use the /e option (you
shouldn't need it because what is in brackets is executed anyway), you
get the same word for every replacement, in the whole string. Huh? Does
this not look like memoization (funcion value caching)?

-- 
	Bart.


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

Date: 28 Nov 2000 16:56:00 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <m3wvdn7ocv.fsf@mumonkan.sunstarsys.com>

Bart Lateur <bart.lateur@skynet.be> writes:

> Assuming @words contains the list of words,
> 
> 	s/ZZZZ/$words[rand @words]/ge;
> 
> 
> If anybody can explain me this: if you don't use the /e option (you
> shouldn't need it because what is in brackets is executed anyway), you
> get the same word for every replacement, in the whole string. Huh? Does
> this not look like memoization (funcion value caching)?
> 
> -- 
> 	Bart.

Interesting- I don't know why, but it looks like some sort of optimization
is going on. Try these variants too:

   s/(ZZ)ZZ/$words[rand @words]/ge; # remove e and behaves same as above
   s/(ZZ)ZZ/$words[rand @words]$1/ge; # remove e and nothing changes!

No apparent difference between 5.005_03 and 5.6 on linux.

-- 
Joe Schaefer



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

Date: Tue, 28 Nov 2000 22:41:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <x7g0kbbtyt.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:


  BL> 	s/ZZZZ/$words[rand @words]/ge;

  BL> If anybody can explain me this: if you don't use the /e option (you
  BL> shouldn't need it because what is in brackets is executed anyway), you
  BL> get the same word for every replacement, in the whole string. Huh? Does
  BL> this not look like memoization (funcion value caching)?

well, think about it this way, the replacement string is interpolated
once and used for the global replacement. if no variables have changed
then it won't reinterpolate. this is also true (and more well known) for
creating the regex itself. it doesn't get recompiled unless a variable
has changed. this is one reason /o is not used as much (another being
qr//).

try this:

@l = qw( aaa bbb ccc ) ;

$x = 'h1h2h3' ;

$x =~ s/(h)/$1$l[rand @l]/g ;

print "$x\n" ;

that will randomly replace h as the $1 'changes' in each iteration of
/g. so /e will force a complete execution each time which is a solution
if you have no changing variables.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


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


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