[18694] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 862 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 9 14:05:51 2001

Date: Wed, 9 May 2001 11:05:09 -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: <989431509-v10-i862@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 9 May 2001     Volume: 10 Number: 862

Today's topics:
    Re: $a . $a++ or Perl for vulcans? (Villy Kruse)
    Re: $a . $a++ or Perl for vulcans? <dan@tuatha.sidhe.org>
    Re: $a . $a++ or Perl for vulcans? <jbehren@gwdg.de>
    Re: $a . $a++ or Perl for vulcans? <dan@tuatha.sidhe.org>
        $self-option <sherlock@genome.stanford.edu>
    Re: $self-option <ren@tivoli.com>
    Re: another question nobull@mail.com
    Re: CGI=HASH(0x176ef80) Help Please! (Rudolf Polzer)
    Re: client server application nobull@mail.com
    Re: dbmopen and tie <SiStie@nuclear-network.com>
        RE: dynamically changing web page - help needed <kz15@MailAndNews.com>
    Re: dynamically changing web page - help needed <dan@nospam_dtbakerprojects.com>
    Re: file manipulations <giles.pepper@brunel.ac.uk>
    Re: HELP with @INC <dennis.kowalsk@daytonoh.ncr.com>
    Re: how can I insert into a open file <jurgenex@hotmail.com>
    Re: Idiom: the expression of a copied & substituted str nobull@mail.com
        Is this a (var name/tr) bug, can anyone verify it??? ("Richard Stands")
    Re: Is this a (var name/tr) bug, can anyone verify it?? <ren@tivoli.com>
    Re: Is this a (var name/tr) bug, can anyone verify it?? <elijah@workspot.net>
    Re: latest stable version of Perl <mischief@velma.motion.net>
        List equality <jimg@dcz.dods.org>
    Re: Passing references via recursion <temp133@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 May 2001 15:35:10 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <slrn9fiorv.t65.vek@pharmnl.ohout.pharmapartners.nl>

On Wed, 09 May 2001 14:32:14 GMT, Dan Sugalski <dan@tuatha.sidhe.org> wrote:
>Joerg Behrens <jbehren@gwdg.de> wrote:
>
>> Perl evaluates the following to "21":
>
>>    $a=1;print $a . $a++ . "\n";
>
>> Isn't this counterintuitive? I've expected "11" which is the result for
>
>>    $a=1; print $a + 0 . $a++  . "\n";
>
>> Is there a simple rule for this alien behaviour?
>
>Sure. The order that subexpressions in an expression get evaluated is
>undefined, subject to change, and likely odd due to optimization.
>Which is not what you wanted to hear, I'm sure.
>




Assume that the first argument is pased as a reference to $a and
the second argument is pased as a reference to a temp variable
which is given the valud of the previous value of $a; then the
effect of incremented $a is seen immidiately in the subroutine,
whereas the temp variable is left as is.  Thus the result would
be 21, even when the arguments are evaluated strictly left to right.

In the second example the first argument is also a temp variable (the
result of $a + 0) and therefore not influenced by the increment to $a
done later.

This mey not be true, but if it is true it may not be true in the next
release.  The explanation fits the observasion, though.


Try modify @_ from within a subroutine and see how that modifies
the argument in the calling program:


perl -we '
sub test {
	$_[0] = 10;
	print "arg list=@_\n";
}

$a = 1;
test $a, $a++;
print "a=$a\n";

$a = 1;
test $a + 0, $a++;
print "a=$a\n";

'

arg list=10 1
a=10
arg list=10 1
a=2



Villy



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

Date: Wed, 09 May 2001 15:45:27 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <rCdK6.52583$Ce4.4396875@news1.rdc1.ct.home.com>

Villy Kruse <vek@pharmnl.ohout.pharmapartners.nl> wrote:
> On Wed, 09 May 2001 14:32:14 GMT, Dan Sugalski <dan@tuatha.sidhe.org> wrote:
>>Joerg Behrens <jbehren@gwdg.de> wrote:
>>
>>> Perl evaluates the following to "21":
>>
>>>    $a=1;print $a . $a++ . "\n";
>>
>>> Isn't this counterintuitive? I've expected "11" which is the result for
>>
>>>    $a=1; print $a + 0 . $a++  . "\n";
>>
>>> Is there a simple rule for this alien behaviour?
>>
>>Sure. The order that subexpressions in an expression get evaluated is
>>undefined, subject to change, and likely odd due to optimization.
>>Which is not what you wanted to hear, I'm sure.

> Assume that the first argument is pased as a reference to $a and
> the second argument is pased as a reference to a temp variable
> which is given the valud of the previous value of $a; then the
> effect of incremented $a is seen immidiately in the subroutine,
> whereas the temp variable is left as is.  Thus the result would
> be 21, even when the arguments are evaluated strictly left to right.

> In the second example the first argument is also a temp variable (the
> result of $a + 0) and therefore not influenced by the increment to $a
> done later.

That's more or less true, though perl-level references aren't involved.
That behaviour *can't* be counted on, however, and is fully subject
to change at any point. (Which is one of the reasons I didn't give
the explanation... :)

You shouldn't write programs that count on this behaviour, as they're
likely to break at some point in the future.

					Dan


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

Date: 09 May 2001 18:56:39 +0200
From: Joerg Behrens <jbehren@gwdg.de>
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <qg66fazcjc.fsf@umpp41.gwdg.de>


Having the possibility to encounter an equivalence of $a+0 != $a
in the context of integers (occupied by common human interpretation)
doesn't really make Perl an intuitive language, IMHO. Use of this
feature by mistake might be hard to discover without debugger.

Jörg


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

Date: Wed, 09 May 2001 17:18:38 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: $a . $a++ or Perl for vulcans?
Message-Id: <OZeK6.52599$Ce4.4403416@news1.rdc1.ct.home.com>

Joerg Behrens <jbehren@gwdg.de> wrote:

> Having the possibility to encounter an equivalence of $a+0 != $a
> in the context of integers (occupied by common human interpretation)
> doesn't really make Perl an intuitive language, IMHO. Use of this
> feature by mistake might be hard to discover without debugger.

Well, I don't know exactly how this relates to the original problem,
but I don't see that it's something that should be unexpected. If
you do a "use integer;", or any other pragma, you're changing the
behaviour of perl. If that changed behaviour is something you find
difficult to wrap your brain around then don't do that.

Perl's as intuitive a language as any other I've come across. It
just requires a different intuition than you might be used to.

					Dan


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

Date: Wed, 09 May 2001 09:21:01 -0700
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: $self-option
Message-Id: <090520010921011645%sherlock@genome.stanford.edu>

Hi,
   I'm having an odd problem (using perl 5.004 on solaris).  I have a
GenePage object, that also has a base class.  The base class is being
used to catch any undefined methods in its autoload, and instead look
if there's a cgi parameter that corresponds.  If I try and do this with
$self->option, it never uses AUTOLOAD to try and resolve the method,
even though option() is not defined in either the class or its parent. 
If I do $self->choice, it works just fine.  Stangely, if I say:

print $self->option();  (with or without the parentheses) it prints : 

GenePage=HASH(0xbe918)

is there anything special about the word option?

Cheers,
Gavin


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

Date: 09 May 2001 11:48:51 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: $self-option
Message-Id: <m3y9s6pix8.fsf@dhcp9-172.support.tivoli.com>

On Wed, 09 May 2001, sherlock@genome.stanford.edu wrote:

> Hi, I'm having an odd problem (using perl 5.004 on solaris).  I have
> a GenePage object, that also has a base class.  The base class is
> being used to catch any undefined methods in its autoload, and
> instead look if there's a cgi parameter that corresponds.  If I try
> and do this with $self->option, it never uses AUTOLOAD to try and
> resolve the method, even though option() is not defined in either
> the class or its parent.  If I do $self->choice, it works just fine.
> Stangely, if I say:
> 
> print $self->option(); (with or without the parentheses) it prints :
> 
> GenePage=HASH(0xbe918)

This looks suspiciously like the value of $self, which also happens to
be the only argument that will be passed to option() or AUTOLOAD().

> is there anything special about the word option?

Not normally, but perhaps the base class thinks otherwise?  In any
event, here is some sample code that demonstrates that both "choice"
and "option" behave the same with respect to AUTOLOAD:

#!/usr/bin/perl
use warnings;
use strict;

package Junk;

sub AUTOLOAD {
  our $AUTOLOAD;
  print "Called for $AUTOLOAD with arguments: @_\n";
}

package main;

my $self = {};
bless $self, "Junk";
$self->option;
$self->option();
$self->choice;
$self->choice();
__END__


-- 
Ren Maddox
ren@tivoli.com


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

Date: 09 May 2001 17:50:06 +0100
From: nobull@mail.com
Subject: Re: another question
Message-Id: <u97kzqlb5t.fsf@wcl-l.bham.ac.uk>

"Chris" <cobrasun@yahoo.de> writes:

> thanks for the Info.

 ...and then procedes to spit in my face by asking a question I've
already answered and compounds this rudeness by bottom-quoting the
entirity of my post, including the sig and, of course, the answer to
his question.

Oh and the selfishly uninformative subject line is rude too.

I'm not ammused by this rudeness.

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


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

Date: Wed, 9 May 2001 20:47:18 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: CGI=HASH(0x176ef80) Help Please!
Message-Id: <slrn9fj45m.7at.eins@www42.t-offline.de>

Malte Ubl <ubl@schaffhausen.de> wrote:
> 
> 
> Octavo schrieb:
> > 
> > Hallo!
> > I have set up a flat file database cgi script (which is posted below).
> > When I run the script from my browser the data that gets input and
> > returned is
> > 
> > First Name: CGI=HASH(0x176ef80)->param('fname')
> > Quiz1 Score: CGI=HASH(0x176ef80)->param('quiz1')
> > Quiz2 Score: CGI=HASH(0x176ef80)->param('quiz2')
> 
> Method calls are not interpolated in a double quote string. You need to do
> something like this instead:
> 
> print 'bla',$query->param("fname"),"bla";

Or, in here-documents, use

@{[ $query-param ("fname") ]}

instead.

-- 
#!/usr/bin/perl -- prints all files of current dir.
open H,"|a2ps -1R";for(sort<*>){print H"$_:\n";open
X,"<$_";print H map{chomp;"> $_\n"}<X>;print H"\n"}


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

Date: 09 May 2001 17:44:01 +0100
From: nobull@mail.com
Subject: Re: client server application
Message-Id: <u9ae4mlbfy.fsf@wcl-l.bham.ac.uk>

"alik blochin" <alikbm@tx.technion.ac.il> writes:

> Subject: client server application
> Newsgroups: comp.lang.perl.misc

So we would expect a question about using Perl in client-server
applications...

[snip javascript question]

WTF!?

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


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

Date: Wed, 9 May 2001 19:53:56 +0200
From: Simon Stiefel <SiStie@nuclear-network.com>
Subject: Re: dbmopen and tie
Message-Id: <Pine.LNX.4.31.0105091949510.1535-100000@server.stiefel.priv>

On 7 May 2001, Anno Siegel wrote:

> According to Simon Stiefel  <SimonStiefel@nuclear-network.com>:
> > Hi,
> >
> > I have to use "dbmopen" and "tie" at the same time (for a convert-scrip=
t).
> > But when I use the DB_File-module, dbmopen doesn't work.
> > I need "DB_File" for "tie".
>
> Why do you think you need both?  I can't think of anything you can
> do with dbmopen that can't be done with tie.

Because I have one database (*.pag & *.dir) which I want to make to a
single file (like craeting a database with tie).

So, how can I open a database with tie which is created with dbmopen (2
files)?


> Anno


Mit freundlichen Gr=FC=DFen,        .~.     Open Minds.
with best regards               /V\             Open Sources.
                               // \\                    Open Future!
Simon Stiefel                 /(   )\_ I N U X
                               ^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.com   |  http://www.nuclear-network.com |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |



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

Date: Wed, 9 May 2001 11:59:06 -0400
From: Zoltan Kandi <kz15@MailAndNews.com>
Subject: RE: dynamically changing web page - help needed
Message-Id: <3B135F91@MailAndNews.com>

>Oh you're using frames.

I thought I would use frames since I have no clue how I could get on without 
them...

>Set the target for the form to the second frame.

Will try.

><news:comp.infosystems.www.authoring.cgi> comes to mind. If you're new
>to that newsgroup, watch out: it is automoderated, and you need to jump
>through some hoops in order to get your first post getting through.

Will check. Thanks for the thorough explanation.

Regards,

Zoltan



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

Date: Wed, 09 May 2001 17:29:15 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: dynamically changing web page - help needed
Message-Id: <3AF97D08.91C666D3@nospam_dtbakerprojects.com>



Zoltan Kandi wrote:
> 
> OK, that's clear. Let's imagine the following HTML layout:
> 
> +-------------+-------------+---------------+
> |frame1       |frame2       |frame 3        |
> | combo box 1 | combo box 2 | more input    |
> |             | updated upon| plus submit   |
> |             | changing 1  | button        |
> +-------------+-------------+---------------+
> |frame 4                                    |
> |                                           |
> |                                           |
> |       here's where you get your results   |
> |                                           |
> |                                           |
> +-------------------------------------------+
----------------------------------------------------------------

you are going to HAVE to use some client-side java script to drive the
choice updates between your frames 
OR 
design this more serially and break the process in a more procedurally
oriented interface that builds one page after the other based on your
choices. i.e. the submit from page1 builds page 2, etc.

 Web-driven app interfaces can rarely be as compact and speedy as a
local app, but if you separate into several dynamic pages that build
each other, it will probably be MUCH faster than a multi-frame page that
has to load lots of javascript and go get the choices between frames
anyway.

D


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

Date: Wed, 9 May 2001 16:52:32 +0100
From: "gdp" <giles.pepper@brunel.ac.uk>
Subject: Re: file manipulations
Message-Id: <9dbooa$qc5$1@mimas.brunel.ac.uk>

thanks all again....problem solved......

"Dodger" <dodger@necrosoft.net> wrote in message
news:wUaK6.62$WT4.60454@news1.rdc2.pa.home.com...
> opendir DIR, '.';
> my @spacefiles = grep !-d, grep / /, readdir DIR;
> closedir DIR;
> for (@spacefiles) {
>     my $newname;
>     ($newname = $_) =~ s/ file://g;
>     my $ok;
>     if (-e $newname) {
>         warn "$newname: File Exists. Overwrite?\n";
>         $ok = uc substr <STDIN>, 0, 1;}
>     else {
>         $ok = 'Y';}
>     system 'mv', $_, $newname and warn "Cannot rename file $_ to $newname:
> $!\n" if $ok eq 'Y';}
>
> --
> Dodger
> www.dodger.org
> www.necrosoft.net
> www.gothic-classifieds.com
> "gdp" <giles.pepper@brunel.ac.uk> wrote in message
> news:9d881t$cfu$1@mimas.brunel.ac.uk...
> > Hi....
> >
> > I have a directory (linux) with a hundred or so files.  Some of these
> > filenames contain spaces which I want to remove.  Can anyone give me a
> clue
> > as to how I would use a perl script to go through the directory and
check
> > and rename if neccessary the file.  I have used a bit of perl for other
> > things but have not had experience of this sort of thing.  Any help
> > appreciated.
> > Regards
> >
> > GDP
> >
> >
>
>




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

Date: Wed, 9 May 2001 11:44:25 -0400
From: "Dennis Kowalski" <dennis.kowalsk@daytonoh.ncr.com>
Subject: Re: HELP with @INC
Message-Id: <3af965d9$1@rpc1284.daytonoh.ncr.com>


The MYPERLLIB variable is set and exported in my .profile at logon.

I no longer had the old use lib line in my test code. I guess I deleted it
will trying things.

Well, I tried the use lib $ENV{MYPERLLIB} and it worked.

Maybe I had a typo in my old code.

I also tried the PERL5LIB variable and it works also.

I can not get the BEGIN ( push @INC, $ENV{MYPERLLIB}) to work though.

I will stick to the other methods.

Thanks for the help

Ren Maddox <ren@tivoli.com> wrote in message
news:m31ypzshtn.fsf@dhcp9-172.support.tivoli.com...
> On Tue, 8 May 2001, dennis.kowalsk@daytonoh.ncr.com wrote:
>
> > I have an environmental variable called MYLIB set to /dira/dirb and
> > the following does not work
>
> Did you export the environment variable?
>
> > #!/bin/perl -I$MYLIB
>
> No, I wouldn't expect that to work.
>
> > neither does
> >
> > #!/bin/$ENV{MYLIB}
>
> And certainly not that.
>
> > The $MYLIB text is added to @INC.
>
> What do you mean here?  It is added by one of the above but the module
> still doesn't work?
>
> > I have also tried the following
> >
> > use lib $ENV{MYLIB}
> >
> > That does not work either.
>
> Now that *should* work.  Yup, I verified that it does work.  Again,
> the environment variable must be exported (for Bourne-shell
> derivatives).
>
> > I have also tried
> >
> > push @INC, $ENV{MYLIB};
> >
> > That does not work either.
>
> That one only works if it is placed inside a BEGIN block so that it
> happens before the "use", which has an implicit BEGIN block.
>
> > When it fails I get a BEGIN failed message saying x.pm could not be
> > found.
> >
> > The use x.pm follows all of the variations I have shown you.
>
> "use" happens at compile time, as if it were in a BEGIN block, so
> having it later in the script doesn't accomplish anything unless the
> other code is *also* in a BEGIN block.
>
> Now wait a minute....  You are trying to "use x.pm"?  Surely not, as
> that would give a syntax error.  "use x" is what you meant, I assume.
>
> > Can someone tell me how to add the contents of an environmental
> > variable to @INC ??
>
> The OTW (One True Way -- often, the answer is that TINOTW: There Is No
> One True Way, but in this case, I don't think that applies) is:
>
> use lib $ENV{MYLIB};
> use x;
>
> I take it back, there is another way.  Use the environment variable
> PERL5LIB, which is automatically included on @INC...  but you'll still
> need to export it.
>
> --
> Ren Maddox
> ren@tivoli.com




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

Date: Wed, 9 May 2001 09:13:38 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how can I insert into a open file
Message-Id: <3af96cb3@news.microsoft.com>

<u153839111@spawnkill.ip-mobilphone.net> wrote in message
news:l.989396178.1287261962@[202.106.159.34]...
> I only know append data in a open file ,but how can I insert into a open
file. thank you very much

Perl is a programming language, not an editor.
For a detailed explanation please see the PerlFAQ5:
    "How do I [...] insert a line in the middle of a file [...]"

jue




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

Date: 09 May 2001 17:42:57 +0100
From: nobull@mail.com
Subject: Re: Idiom: the expression of a copied & substituted string
Message-Id: <u9bsp2lbhq.fsf@wcl-l.bham.ac.uk>

Benjamin Goldberg <goldbb2@earthlink.net> writes:

> Here's a slightly rewritten [but untested] apply.
> 
> sub apply (&) {
> 	my $sub = shift;
> 	my @copy = @_;
> 	$sub->() for(@copy); # for() binds to $_
> 	wantarray ? @copy : $copy[0];
> }

Appart from the typo in the prototype this is nearly identical to what
I posted earlier in this thread.

Oh, and I prefer the &$sub idiom over $sub->() when calling a
subroutine that is interacting with its caller via shared variables
(such as $_) rather than via formal arguments and return value. 

There's also a _small_ efficiency gain but advocate this primarily for
clarity rather than efficiency.

use Benchmark; 
my $sub = sub { 1; };
timethese(1000000, {
    noargs => sub { &$sub; },
    nullargs => sub { $sub->(); }
});
__END__
Benchmark: timing 1000000 iterations of noargs, nullargs...
    noargs:  2 wallclock secs ( 3.00 usr + -0.18 sys =  2.82 CPU) @ 354609.93/s (n=1000000)
  nullargs:  7 wallclock secs ( 4.50 usr +  0.24 sys =  4.74 CPU) @ 210970.46/s (n=1000000)

I'm now looking for some help re-writing apply() in XS - anyone who
can help please mosey on over to the thread in c.l.p.moderated.

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


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

Date: Wed, 9 May 2001 16:12:03 +0000 (UTC)
From: rstands@hotmail.com ("Richard Stands")
Subject: Is this a (var name/tr) bug, can anyone verify it???
Message-Id: <F188KWQTHL2bti2SbPk00001244@hotmail.com>

<html><DIV>I am running Activestate Perl ver. 5.6.0 on Win NT SP5. The following code:</DIV>
<DIV>&nbsp;</DIV>
<DIV>#!/perl -w</DIV>
<DIV>use strict;<BR>my $foo = "one\ttwo\tthree\tfour\tfive";<BR>my $tab = "\t";<BR>print(scalar($foo =~ tr/\t/\t/));</DIV>
<DIV>print(scalar($foo =~ tr/$tab/$tab/));<BR>print(scalar($foo =~ tr/\t/$tab/));<BR>print(scalar($foo =~ tr/$tab/\t/));<BR></DIV>
<DIV>gives the following result:</DIV>
<DIV>&nbsp;</DIV>
<DIV>4246</DIV>
<DIV>&nbsp;</DIV>
<DIV>However, the following code:</DIV>
<DIV>&nbsp;</DIV>
<DIV>#!/perl -w</DIV>
<DIV>use strict;<BR>my $foo = "one\ttwo\tthree\tfour\tfive";<BR>my $TAB = "\t";<BR>print(scalar($foo =~ tr/\t/\t/));<BR>print(scalar($foo =~ tr/$TAB/$TAB/));<BR>print(scalar($foo =~ tr/\t/$TAB/));<BR>print(scalar($foo =~ tr/$TAB/\t/));</DIV>
<DIV>&nbsp;</DIV>
<DIV>gives the following result:</DIV>
<DIV>&nbsp;</DIV>
<DIV>4044</DIV>
<DIV>&nbsp;</DIV>
<DIV>I understand from reading the documentation about the transliteration operator that it "is built at compile time, neither the SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote interpolation". But, that does not explain the different results based, I'm assuming, on the case of the variable name TAB! What exactly is going on here???</DIV>
<DIV>&nbsp;</DIV>
<DIV>-Rich<BR></DIV><br clear=all><hr>Get your FREE download of MSN Explorer at <a href="http://explorer.msn.com">http://explorer.msn.com</a><br></p></html>

-- 
Posted from [63.66.71.66] by way of f188.law11.hotmail.com [64.4.17.188] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: 09 May 2001 11:37:07 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Is this a (var name/tr) bug, can anyone verify it???
Message-Id: <m34ruuqy18.fsf@dhcp9-172.support.tivoli.com>

On Wed, 9 May 2001, rstands@hotmail.com wrote:

> my $foo = "one\ttwo\tthree\tfour\tfive";
> my $tab = "\t";

tr/// does not do variable expansion, so:

> print(scalar($foo =~ tr/\t/\t/));

This is correct.

> print(scalar($foo =~ tr/$tab/$tab/));

This translates the four characters "$", "t", "a" and "b" to
themselves and returns 2 since there are two "t"-s and none of the
others.

> print(scalar($foo =~ tr/\t/$tab/));

This translates the four tabs to "$" and returns 4.

> print(scalar($foo =~ tr/$tab/\t/));

This translates the four "$"-s from the previous step, as well as the
two "t"-s, to tabs and returns 6.

The difference here:

> my $foo = "one\ttwo\tthree\tfour\tfive";
> my $TAB = "\t";
> print(scalar($foo =~ tr/\t/\t/));
> print(scalar($foo =~ tr/$TAB/$TAB/));

is that none of these characters are in the original string, so 0 is
returned.

> print(scalar($foo =~ tr/\t/$TAB/));

Again, four tabs are translated to "$" and 4 is returned.

> print(scalar($foo =~ tr/$TAB/\t/));

And again, four "$"-s are translated to tabs and 4 is returned (since
none of the "T", "A" or "B" are present.

> I understand from reading the documentation about the
> transliteration operator that it "is built at compile time, neither
> the SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote
> interpolation". But, that does not explain the different results
> based, I'm assuming, on the case of the variable name TAB! What
> exactly is going on here???

I hope it is clear now.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 9 May 2001 17:29:33 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Is this a (var name/tr) bug, can anyone verify it???
Message-Id: <eli$0105091326@qz.little-neck.ny.us>

In comp.lang.perl.misc, Richard Stands <rstands@hotmail.com> wrote:
> I am running Activestate Perl ver. 5.6.0 on Win NT SP5. The following code:

I've got 5.6.0 on Linux.

> #!/perl -w
> use strict;
> my $foo = "one\ttwo\tthree\tfour\tfive";
> my $tab = "\t";
> print(scalar($foo =~ tr/\t/\t/));
> print(scalar($foo =~ tr/$tab/$tab/));
> print(scalar($foo =~ tr/\t/$tab/));
> print(scalar($foo =~ tr/$tab/\t/));
> gives the following result:
>  
> 4246

You don't understand tr///: it is not a double-quote-ish context. Print
the strings after each modification:

#!/perl -w
use strict;
my $foo = "one\ttwo\tthree\tfour\tfive";
my $tab = "\t";
print(scalar($foo =~ tr/\t/\t/) . ": $foo\n");
print(scalar($foo =~ tr/$tab/$tab/) . ": $foo\n");
print(scalar($foo =~ tr/\t/$tab/) . ": $foo\n");
print(scalar($foo =~ tr/$tab/\t/) . ": $foo\n");
__END__
:r! perl -x %
4: one	two	three	four	five
2: one	two	three	four	five
4: one$two$three$four$five
6: one		wo		hree	four	five

Elijah
------
use eval() if you need variable interpolation in tr///


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

Date: Wed, 09 May 2001 17:14:53 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: latest stable version of Perl
Message-Id: <tfiuodentkuo72@corp.supernews.com>

Robert Lopez <Robert.Lopez@abq.sc.philips.com> wrote:
> abigail@foad.org (Abigail) writes:

>> None. Every version of Perl I've used had its problems in one way or the
>> other. Just because Randal doesn't want to use 5.6.1 on his production

> "None." Is this to say abigail has never implemented a production
> program in perl?  Teasing or serious?

Not that I'd dare to speak for Abigail, but I took it to mean that
there's no single version of Perl Abigail would consider to be of
penultimate stability and more fit for production than all other
versions.

Personally, I use 5.5.3 (5.005_03) for production for programs
I don't maintain on a regular basis and 5.6.0 for programs I'm
currently writing or upgrading, since unlike Randal I'm just as
likely to break something as is a dot-zero release of Perl. In
short, I leave things alone that are known to be working, but
as long as I'm working on the code anyway, I might as well get
used to the newer version. I'll be replacing 5.6.0 with 5.6.1
in a few weeks, in my 'copious free time' *cough*.

Chris
 
-- 
Where there's a will, there's a lawyer.



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

Date: Wed, 09 May 2001 17:54:41 +0000
From: James Gallagher <jimg@dcz.dods.org>
Subject: List equality
Message-Id: <3AF98461.18B73263@dcz.dods.org>

Is there an operator or function built into Perl (or a common idiom)
that tests if two lists are equal? It's not that hard to write, but I
thought maybe there was something I've overlooked.

Thanks,
James
-- 
__________________________________________________________________________
James Gallagher		         The Distributed Oceanographic Data System
jgallagher@gso.uri.edu              
http://unidata.ucar.edu/packages/dods
Voice: 541.757.7992					 Fax: 541.758.3254


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

Date: Wed, 9 May 2001 09:20:19 -0700
From: "Arvin Portlock" <temp133@hotmail.com>
Subject: Re: Passing references via recursion
Message-Id: <9dbqo9$qku$1@agate.berkeley.edu>

Ah, so that's what a closure is. It's great seeing it used
for an actual application I'm doing. It's a little more complex
than passing a variable reference but I like it better.

Thanks!


Samuel Kilchenmann <skilchen@swissonline.ch> wrote in message
news:9d4oui$ged7g$1@ID-13368.news.dfncis.de...
> "Arvin Portlock" <temp133@hotmail.com> schrieb im Newsbeitrag
> news:9d41jp$h6j$1@agate.berkeley.edu...
> >
> > As for Mr. Kilchenmann's code, [...]
> > The problem with your code though, is that it customizes
> > recurse to do a specific thing: append lines. I have too many
> > instance in older code of subroutines like recurse1, recurse2,
> > recurse3, and such. I never want to have to do that again.
> >
> You are right. But then you might want to try out the famous closures.
> See the higher order functions "make_location_appender" and
> "make_list_pusher" below. Both return a list of two closures. The
> first one does the desired work, the second one returns the
> accumulated result of the work done so far.
>
> #!/usr/bin/perl -w
> use strict;
>
> sub print_locations {
>   my $root = shift;
>   my ($do_append, $get_locations) = make_location_appender(' ');
>   recurse ($root, $do_append);
>   print $get_locations->(), "\n";
> }
>
> sub get_location_list {
>   my $root = shift;
>   my ($list_push, $get_list) = make_list_pusher();
>   recurse($root, $list_push);
>   return $get_list->();
> }
>
> sub recurse {
>   my ($node, $subref) = @_;
>   if (defined($node)) {
>     $subref->($node);
>     recurse($node->{sub}, $subref);
>     recurse($node->{next}, $subref);
>   }
> }
>
> sub make_location_appender {
>   my $separator = shift || '';
>   my $locations = '';
>
>   my $do_append =  sub {
>     my $node = shift;
>     if ($locations) {
>       $locations .= ($separator . $node->{place});
>     }
>     else {
>       $locations = $node->{place};
>     }
>   };
>
>   my $get_locations = sub {
>     return $locations;
>   };
>
>   return ($do_append, $get_locations);
> }
>
> sub make_list_pusher {
>   my @list = ();
>
>   my $list_push = sub {
>     my $node = shift;
>     push(@list, $node->{place});
>   };
>
>   my $get_list = sub {
>     return \@list;
>   };
>
>   return ($list_push, $get_list);
> }
>
> my $root = {
>   place => "first",
>   sub   => {
>     place => "second",
>     sub   => undef,
>     next  => {
>       place => "third",
>       sub   => {
>         place => "third_sub",
>         sub   => undef,
>         next  => {
>           place => "third_sub_next",
>           sub   => undef,
>           next  => undef,
>         },
>       },
>       next  => {
>         place => "third_next",
>         sub   => {
>           place => "third_next_sub",
>           sub   => undef,
>           next  => undef,
>         },
>         next  => undef,
>       }
>     },
>   },
>   next  => {
>     place => "fourth",
>     sub   => {
>       place => "fifth",
>       sub   => undef,
>       next  => undef,
>     },
>     next  => undef,
>   },
> };
>
> print_locations($root);
> print "\n";
> print join("\n", @{get_location_list($root)});
>
> __END__
>
> output:
> first second third third_sub third_sub_next third_next third_next_sub
> fourth fifth
>
> first
> second
> third
> third_sub
> third_sub_next
> third_next
> third_next_sub
> fourth
> fifth
>
>
>




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

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


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