[17017] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4429 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 26 00:05:24 2000

Date: Mon, 25 Sep 2000 21:05:06 -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: <969941106-v9-i4429@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 25 Sep 2000     Volume: 9 Number: 4429

Today's topics:
        [ANNOUNCE] HTTP::Monkeywrench 1.0 (new package) <derek@cnation.com>
    Re: attachment not in body of email  (Gwyn Judd)
    Re: Candidate for the top ten perl mistakes list (Abigail)
    Re: checking for a valid date-time (Gwyn Judd)
    Re: checking for a valid date-time (Martien Verbruggen)
    Re: deamonize <amonotod@netscape.net>
        flock shared and exclusive, when to use it <jjk@onlink.net>
    Re: flock shared and exclusive, when to use it <rick.delaney@home.com>
    Re: flock shared and exclusive, when to use it (Martien Verbruggen)
    Re: Help with REGEX for newbie <ren.maddox@tivoli.com>
    Re: MD5 Apache Password Encryption? <biow@verity.com>
    Re: New to PERL <usenet@hank.org>
    Re: New to PERL (Abigail)
    Re: parameter passing problem (Abigail)
    Re: References and local (Daniel Chetlin)
    Re: References and local (Martien Verbruggen)
    Re: West Chester, PA 19380 Perl Users Group? (Abigail)
    Re: When to use \ ? <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 25 Sep 2000 18:02:15 -0700
From: Derek Cline <derek@cnation.com>
Subject: [ANNOUNCE] HTTP::Monkeywrench 1.0 (new package)
Message-Id: <st0295o8fb7mdb@corp.supernews.com>

The URL:
 
http://sourceforge.net/project/showfiles.php?group_id=7560&release_id=11
892

has entered CPAN as:
    file: $CPAN/authors/id/C/CN/CNATION/Monkeywrench-1.0.tar.gz
    size: 14849 bytes
     md5: 89e5c6aab819ad7781f842cf566f9acd

  HTTP::Monkeywrench is a web site testing utility.

See
 http://opensource.cnation.com/projects/Monkeywrench/ for more
information.

 - Although Monkeywrench is not written as a mod_perl application, it
is tremendously useful to mod_perl developers.  We developed
Monkeywrench specifically because we needed to test our dynamic
mod_perl sites.

 - Monkeywrench is a command line based application built for testing
static or dynamic websites under development to test their integrity
and report errors.

 - Monkeywrench works by letting you create 'test scenarios' which can
be run against the site again and again. Test scenarios closely mimic a
user going through your site performing specific actions like filling
out a registration form, or ordering a product. It can then make sure
each page had the desired results.




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

Date: Tue, 26 Sep 2000 01:35:40 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: attachment not in body of email 
Message-Id: <slrn8svvb9.310.tjla@thislove.dyndns.org>

I was shocked! How could Hugo Bouckaert <hugo@fractalgraphics.com.au>
say such a terrible thing:
>Hi 
>
>I have been trying forever now to have a perl script that sends email
>with attachments not displayed in the body of the email. It just does
>not want to work!! This is very frustrating. 
   
>This is virtually identical to what is in perldoc Lite
>
>BUT IT DOES NOT WORK! The mail and attachment(s) are sent, but all
>attachments, including the image, are in the body of the email

Beats me. Yours looks like it should work to my limited knowledge. Are
you sure it's not a MUA issue? Some mailers will display any attachments
that they know about.

>As I said, an actual working perl script would be most welcome, then I
>can compare a working version with mine and see what goes wrong. I
>really don't seem to get this one. 

Here is a "works for me" script that attaches a gif downloaded from a
site on the internet into a document:

#!/usr/bin/perl -w
# get a userfriendly image and mail it

use LWP::Simple;
use MIME::Lite;
use strict;

my $arg = shift;
my $debug = 0;

if (defined $arg && $arg eq '-d')
{
    print "setting debug option\n";
    $debug = 1;
}

select STDOUT; $| = 1; # make unbuffered
select STDERR; $| = 1;

sub print_mess
{
    my $mess = shift or return;

    print $mess if $debug;
}

# get a file
sub http_get_file
{
    my $file = shift;
    
    my $data = get $file or die "Could not get $file: $!\n";

    $data;
}

# You can change these according to the image that you want to grab
my $document = 'http://www.userfriendly.org/static/index.html';
my $mail_addr = 'gwyn@thislove.dyndns.org';

my $page = &http_get_file($document);

# this is the section that parses out the correct URL
my @link = split /ALT="Latest Strip"/, $page;
my @getlink = split />/, $link[1];
my @findlink = split /SRC="/, $getlink[0];
my @pullend = split /">/, $findlink[1];
$pullend[0] =~ s/"//;
my $the_file = $pullend[0];

&print_mess("file to get looks like $the_file\n");

my $data = &http_get_file($the_file);

my $msg = MIME::Lite->new(
                From => 'userf@localhost',
                To => $mail_addr,
                Subject => 'A new userfriendly image!',
                Type => 'multipart/mixed'
);

$msg->attach(Type => 'TEXT',
      Data => "Attached please find the latest userfriendly cartoon\n",
);

$msg->attach(Type => 'image/gif',
             Data => $data,
             Filename => 'userfriendly.gif'
);

$msg->send;

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
About all some men accomplish in life is to send a son to Harvard.


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

Date: 26 Sep 2000 01:22:33 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <slrn8svugd.lo9.abigail@alexandra.foad.org>

Craig Berry (cberry@cinenet.net) wrote on MMDLXXXIII September MCMXCIII
in <URL:news:ssvqiskrlsckc1@corp.supernews.com>:
@@ Logan Shaw (logan@cs.utexas.edu) wrote:
@@ [snip]
@@ : Well then, since "<=" and ">=" are opposites, logically what we really
@@ : should have is "=<" as the opposite of "=>".  So,
@@ : 
@@ : 	push @array =< $value;
@@ : 
@@ : Pretty, isn't it?
@@ 
@@ Both pretty and kinky.  I vote yes!  But we need to come up with some

Of course, =< already has a meaning in Perl. < is the start of a glob,
or a handleread, and the lexer will skip to the next >.

@@ additional, non-obvious, and context-dependent ways for it to differ from
@@ =>, in order to give it that Perl feel.
@@ 
@@ :   - Logan, who wants to know when the ":-)" operator will be added[1].
@@ : 
@@ : [1]  And who is trying to think what its semantics would be if it
@@ :      were[2].
@@ 
@@ I would make it an alternative for the : in the ?: operator.  The
@@ semantics would be that in
@@ 
@@   a ? b :-) c
@@ 
@@ if a evaluated true, then the value would be b -- *unless* b evaluated
@@ false, in which case it would be c.  The idea would be 'a is true?  Okay,
@@ pick b -- wait, just kidding!  It's c.'

But that's as long as:

    a && b || c;



Abigail
-- 
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${${@}}[$#{@{${@}}}]'
#    A raven in the
#    branches of a peach tree. A crawling
#    beetle. A Bard.


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

Date: Tue, 26 Sep 2000 01:47:41 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: checking for a valid date-time
Message-Id: <slrn8t001r.310.tjla@thislove.dyndns.org>

I was shocked! How could Dan and Shelly <wedeking@msa.attmil.ne.jp>
say such a terrible thing:
>Does anyone know a better way than this:
>
>start:
>$a = <STDIN>;
>chomp($a);
>if ("$a" =~ /(\d{2})(\d{2})(\d{2})/) {
> $days = $1;
> $hours = $2;
> $minutes = $3;
>} else { print "$a isn't valid.\n" }
>
>if ($days < 32 && $hours < 24 && $minutes < 60) {
> print "$a is valid\n";
>} else { print "$a isn't valid\n" }
>goto start

Well you could use a while(1) loop instead of the goto and you don't
need to stringify $a in the match and for that matter you could use a
better variable name than $a (which is special anyway, see perdoc -f
sort) like $input or something but what I think you want to know is:

perldoc Time::ParseDate
perldoc -f localtime

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
   :self-reference: n.  See {self-reference}.
From "The New Hackers Dictionary", version 4.2


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

Date: Tue, 26 Sep 2000 03:40:40 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: checking for a valid date-time
Message-Id: <slrn8t06lj.m9.mgjv@verbruggen.comdyn.com.au>

On Mon, 25 Sep 2000 23:21:26 +0900,
    Dan and Shelly <wedeking@msa.attmil.ne.jp> wrote:
> Does anyone know a better way than this:
> 
> start:
> $a = <STDIN>;
> chomp($a);
> if ("$a" =~ /(\d{2})(\d{2})(\d{2})/) {
>  $days = $1;
>  $hours = $2;
>  $minutes = $3;
> } else { print "$a isn't valid.\n" }
> 
> if ($days < 32 && $hours < 24 && $minutes < 60) {
>  print "$a is valid\n";
> } else { print "$a isn't valid\n" }
> goto start


#!/usr/local/bin/perl -w
use strict;

while (<STDIN>)
{
    chomp;
    my ($day, $hour, $minute) = /^(\d\d)(\d\d)(\d\d)$/;
    
    print "$_ is ", 
      !$minute || $day > 31 || $hour > 24 || $minute > 60 ? 'not ' : '',
      "valid\n";
}

Note however, that this is slightly different from yours. Yours
matches the first six digits in a string, mine insists that the only
strings allowed have to have six digits and no more. Also note that
the check on '$day' is slightly weak, because for example, February
doesn't have 31 days. Without knowing anythjng about the month
however, you can't make it more specific.

Notes: mainly on style: Do use -w and the strict pragma. They'll help
you debug programs better. Don't use $a or $b unless you are in a sort
subroutine. They're special. Don't use gotos unless you are prepared
to justify it, and can come up with a damned good reason. Properly
indent your code; it's just too hard to read this way.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd.   | selective about its friends.
NSW, Australia                  | 


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

Date: Tue, 26 Sep 2000 02:52:54 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: deamonize
Message-Id: <8qp31u$7gr$1@nnrp1.deja.com>

In article <8qop25$4rr$1@provolone.cs.utexas.edu>,
  logan@cs.utexas.edu (Logan Shaw) wrote:
> In article <%syy5.245$hs2.11039@news.globetrotter.net>,
> Neb <berube@odyssee.net> wrote:
> >information about their OS version.  How can I get it ?
>
> From the shell, just type "uname -sr".
>
> From a CGI, just do:
>
> 	#! /usr/local/bin/perl -w
>
> 	use CGI;
>
> 	$q = new CGI;
>
> 	print $q->header,
> 		$q->start_html ("OS Version"),
> 		"Your OS version seems to be",
> 		$q->pre (qx{uname -sr}),

Wrong!  Try this:
 		$q->pre ( $^O ),  # <--This is the Perl way

> 		"Have a nice day!\n";
>
> Hope that helps.
>
>   - Logan
>
HTH, too!
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


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


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

Date: Mon, 25 Sep 2000 19:30:20 -0400
From: "Jonah" <jjk@onlink.net>
Subject: flock shared and exclusive, when to use it
Message-Id: <8qotv4$269u$1@onlink3.onlink.net>

I just want to make sure of something here...

I've been installing cgi scripts on various servers
and I've noticed that roughly 1% of them give me a
"bad file descriptor" error.

After searching through this newsgroup I found out that it's not
usually a good idea to flock (FILE, 2) on a file that is open as read only
because it causes the above error on some systems.

I also read a recommendation to use the constants in case the flock values
get
changed, although this is highly unlikely (apparently).

example:

use Fcntl ':flock';
# use LOCK_SH, LOCK_EX and LOCK_UN. And LOCK_NB if you want it.

#open file blah blah
flock (FILE, LOCK_ EX);  #instead of flock (FILE, 2);
#close file

2 questions:

1) Should I change my code so that it does a shared lock when the file is
open for reading,
and an exclusive lock for writing so it works on those quirky systems? Will
that affect how
it works on the majority of other servers or is this the best way to go for
max compatibility?
Or should I have 2 versions of my script...one with shared locks and one
with exclusive locks?

2) Is it really worth the trouble of using the constants instead of the
values?
(4000 lines to go through)

Ok so that was 5 questions...

Thanks for your help.





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

Date: Tue, 26 Sep 2000 02:09:47 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: flock shared and exclusive, when to use it
Message-Id: <39D00819.D03E3167@home.com>

[posted & mailed]

Jonah wrote:
> 
> "bad file descriptor" error.
> 
> After searching through this newsgroup I found out that it's not
> usually a good idea to flock (FILE, 2) on a file that is open as read 
> only because it causes the above error on some systems.

Yes.
 
> I also read a recommendation to use the constants in case the flock 
> values get changed, although this is highly unlikely (apparently).

Yes and yes.

> example:
> 
> use Fcntl ':flock';
> # use LOCK_SH, LOCK_EX and LOCK_UN. And LOCK_NB if you want it.
> 
> #open file blah blah
> flock (FILE, LOCK_ EX);  #instead of flock (FILE, 2);

Yes, except you should alway check the return value of flock.

> #close file
> 
> 2 questions:
> 
> 1) Should I change my code so that it does a shared lock when the file 
> is open for reading, and an exclusive lock for writing so it works on 
> those quirky systems? 

You should use a shared lock when open RDONLY because there is no point
blocking others from reading at the same time.  Think of the "quirky
systems" as having the strict pragma in effect to prevent you from doing
something silly.

> Will that affect how it works on the majority of other servers or is
> this the best way to go for max compatibility?

The other boxes should have no trouble with shared locks.  You can still
use 'my' with 'no strict' you know.

> Or should I have 2 versions of my script...one with shared locks and 
> one with exclusive locks?

Not if you can help it.
 
> 2) Is it really worth the trouble of using the constants instead of 
> the values? 

It is if you get burnt.  Still, you could wait until you do...

> (4000 lines to go through)

Now you see why it's recommended you use them in the first place.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 26 Sep 2000 03:55:58 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: flock shared and exclusive, when to use it
Message-Id: <slrn8t07i9.m9.mgjv@verbruggen.comdyn.com.au>

On Mon, 25 Sep 2000 19:30:20 -0400,
	Jonah <jjk@onlink.net> wrote:
> I just want to make sure of something here...
> 
> I've been installing cgi scripts on various servers
> and I've noticed that roughly 1% of them give me a
> "bad file descriptor" error.
> 
> After searching through this newsgroup I found out that it's not
> usually a good idea to flock (FILE, 2) on a file that is open as read only
> because it causes the above error on some systems.
> 
> I also read a recommendation to use the constants in case the flock values
> get
> changed, although this is highly unlikely (apparently).
> 
> example:
> 
> use Fcntl ':flock';
> # use LOCK_SH, LOCK_EX and LOCK_UN. And LOCK_NB if you want it.
> 
> #open file blah blah
> flock (FILE, LOCK_ EX);  #instead of flock (FILE, 2);

You should check the return value of flock.

> 2 questions:
> 
> 1) Should I change my code so that it does a shared lock when the
> file is open for reading, and an exclusive lock for writing so it
> works on those quirky systems?

Yes. Not only on quirky systems, but always (also see comment to next
question). Only ask for an exclusive lock when you need it. In other
words: use LOCK_SH when you intend to read, and LOCK_EX when you
intend to write.

>                                Will that affect how it works on the
> majority of other servers or is this the best way to go for max
> compatibility?

No, it won't affect how it works, at least, it won't break how it
works.  If anything, it'll make things slightly faster. A LOCK_SH
doesn't prohibit other processes from obtaining a LOCK_SH. It does
prevent other processes from obtaining a LOCK_EX. A LOCK_EX excludes
any other lock another process might want. 

Yes, and No. It's not a compatibility issue per se. It's just about
using the calls correctly.

>                 Or should I have 2 versions of my script...one with
> shared locks and one with exclusive locks?

definitely No.

> 2) Is it really worth the trouble of using the constants instead of
> the values?  (4000 lines to go through)

Yes. More portable, easier to maintain and read.

You could just do some search and replace stuff.

Oh, also: Don't use LOCK_UN if you plan on closing the file
immediately afterwards. It should be safe to do so on recent perls,
but on older ones you open yourself up for a race condition. 

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: 25 Sep 2000 18:09:40 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Help with REGEX for newbie
Message-Id: <m3itrkrruz.fsf@dhcp11-177.support.tivoli.com>

Shawn and Francine <flsq@home.com> writes:

> I want to use REGEX to scan a string and find a single digit followed by
> any two charecters followed by a white space and delete only that
> digit.  The snipet I have below deletes everything, digit charecters and
> white space.  I have tried several variations.  Couls someone throw me a
> bone?
> 
> foreach $cycle (@contents)
> {
>      $cycle =~ s/[0-9]..\s//g;
> }
> 

As always, TMTOWTDI.  Here are two:

1. s/\d(..\s)/$1/g for @contents;
2. s/\d(?=..\s)//g for @contents;

My quick little one-off benchmark has the second version as nearly
three times as fast as the first, albeit for a *very* limited data
set.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 25 Sep 2000 21:36:31 -0400
From: Christopher Biow <biow@verity.com>
Subject: Re: MD5 Apache Password Encryption?
Message-Id: <peuvsso0smludbtfsih1frma1nu6kqa98e@4ax.com>

"William A. Rowe, Jr." <wrowe@rowe-clan.you.know.why.net> wrote:

>My answer was in PasswdMD5.pm from CPAN

>Thanks for the help, however, and hopefully someone searching deja
>will find this reminder.

On behalf of Deja searchers present and future, let me applaud your
self-followup! Deja, even in its present shrunken form, has saved me dozens
of posts, in the cases where posters have *not* wound up with an
uninformative "found the solution".

-- 
A: Hello, tech support.
B: Hi, my software doesn't work.
A: What goes wrong?
B: It doesn't work.


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

Date: Mon, 25 Sep 2000 17:46:19 -0700
From: Bill Moseley <usenet@hank.org>
Subject: Re: New to PERL
Message-Id: <MPG.143991b531c5573098969b@news.newsguy.com>

On 25 Sep 2000 19:42:18 GMT Abigail (abigail@foad.org) remarked...
> All warnings and error Perl throws at you are explained in the perldiag
> man page, part of the large set of manpages that comes with every 
> distribution of Perl. Use it.

This one caught me the other day.  
package 'vars' not registered for warnings at Test123.pm line 7

> fgrep registered `perldoc -l perldiag`
>


-- 
Bill Moseley


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

Date: 26 Sep 2000 03:01:41 GMT
From: abigail@foad.org (Abigail)
Subject: Re: New to PERL
Message-Id: <slrn8t04a8.lo9.abigail@alexandra.foad.org>

Bill Moseley (usenet@hank.org) wrote on MMDLXXXIII September MCMXCIII in
<URL:news:MPG.143991b531c5573098969b@news.newsguy.com>:
:: On 25 Sep 2000 19:42:18 GMT Abigail (abigail@foad.org) remarked...
:: > All warnings and error Perl throws at you are explained in the perldiag
:: > man page, part of the large set of manpages that comes with every 
:: > distribution of Perl. Use it.
:: 
:: This one caught me the other day.  
:: package 'vars' not registered for warnings at Test123.pm line 7

That's because it's a warning from a module, and not from the core
language. Most warnings from modules aren't in perldiag, but it can
be argued that they should be there.



Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_;
sub   _   {push         @_ => /::(.*)/s and goto &{ shift}}
sub shift {print shift; @_              and goto &{+shift}}
Hack ("Just", "Perl ", " ano", "er\n", "ther "); # 20000925


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

Date: 26 Sep 2000 01:40:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: parameter passing problem
Message-Id: <slrn8svvhm.lo9.abigail@alexandra.foad.org>

orassilv (ssilv@rochester.rr.com) wrote on MMDLXXXIII September MCMXCIII
in <URL:news:KpSz5.30241$O37.4529917@typhoon.nyroc.rr.com>:
?? Environment:
?? nt4.0,
?? perl is in my path,
?? running from a msdos command line.
?? 
?? Have a file called test.pl with the following:
??    print "Hello world \n";
??    print "@ARGV \n";
??    print "First arg: $ARGV[0] \n";
??    print "Second arg: $ARGV[1] \n";
?? 
?? When I call it with test.pl p1 p2 from the command line I get:
?? Hello world
?? 
?? First arg:
?? Second arg:

Apparently, you're using some kind of magic that allows NT to determine
that if you execute the file.pl, it should start perl, and give it
the file to execute. Most likely, said magic is broken, as it doesn't
pass the parameters as well.

Notice that the above paragraph contains both the words 'NT' and 'broken'.

?? When I call it with perl test.pl p1 p2 from the command line I get:
?? Hello world
??  p1 p2
?? First arg: p1
?? Second arg: p2

In that case, perl is called with three arguments, the first one being
the program; the rest of its arguments are passed as arguments to the
program.

?? Why do I need to explicity call test.pl using "perl test.pl p1 p2" in order
?? to get my parameters passed correctly into test.pl?


Because you run Redmondware?



Abigail
-- 
sub J::FETCH{Just   }$_.='print+"@{[map';sub J::TIESCALAR{bless\my$J,J}
sub A::FETCH{Another}$_.='{tie my($x),$';sub A::TIESCALAR{bless\my$A,A}
sub P::FETCH{Perl   }$_.='_;$x}qw/J A P';sub P::TIESCALAR{bless\my$P,P}
sub H::FETCH{Hacker }$_.=' H/]}\n"';eval;sub H::TIESCALAR{bless\my$H,H}


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

Date: 26 Sep 2000 02:01:53 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: References and local
Message-Id: <8qp02h012rj@news1.newsguy.com>

On Mon, 25 Sep 2000 22:02:44 GMT,
 Martien Verbruggen <mgjv@verbruggen.comdyn.com.au> wrote:
[snip]
>What I imagine to be the truth (and also see the historical perl 2
>documentation that I posted earlier), is that the _intention_ always
>was to only make _values_ local. In perls up to 5 it made perfect
>sense to implement that by making a local copy of the variable, and
>accessing that. With the coming of perl 5 and references, that no
>longer worked, but nobody noticed that it didn't work, or nobody even
>saw a problem. If the intention always was to provide a local copy of
>a variable, then why is it explicitly stated in the documentation that
>that is not what happens?

This is a very reasonable argument -- I'm far from convinced of my
disagreement. In fact, I do think it's very possible that it was always
intended to work the other way around.

>perlfunc:local is a bit ambiguous, but perlsub clearly states:
>
>       Temporary Values via local()
>               
>[SNIP]
>       A `local' modifies its listed variables to be "local" to
>       the enclosing block, `eval', or `do FILE'--and to any
>       subroutine called from within that block.  A `local' just
>       gives temporary values to global (meaning package)
>       variables.  It does not create a local variable.
>                           ^^^
>
>(Emphasis present in original)

Hmm, this emphasized part isn't convincing to me -- what is meant here,
I'm almost positive, is that it means it doesn't create a lexical
variable. The docs are very careful to never give people the impression
that local does anything but save a variable (or value, if you wish) to
be reinstated later, _rather_ than creating a "local variable" (which
you do with my). The part about giving temporary values is indeed
concerning, however. I still think it's an error in the docs, but like I
said it may be an error in the implementation.

>As I said before, I think that only one of the original perl2
>developers could tell us what was intended, if they still remember, and
>resolve that particular problem.

Well, sure, it's all conjecture. Still, it's fun to talk about.

>If the implementation is wrong, the current developers will then have
>to make a decision on whether they believe it's worth changing or not.
>I don't pretend to have enough knowledge of perl's internals to be able
>to see the ramifications of changing this, or the influence on speed of
>execution, or the amount of breakage that would occur.

I have a decent knowledge of the internals, I suppose. I certainly can't
claim that I know exactly what will happen, but here is my view on the
ramifications:

  * Currently, if you want to "follow along" with how a global variable
    changes, you can do it with a soft reference or a reference to a
    glob, whereas if you want to hang on to the initial value regardless
    of any use of local, you do it with a hard reference. Making the
    change that may very well have been what was originally intended
    will make it impossible to hang on to the original value when local
    is used. It will go away completely until the end of the block or
    scope. IMO, regardless of the initial intention for local's
    behavior, taking away this flexibility is not a win.

  * In either way of implementing local, a new scalar will have to be
    created. The difference is that once that new variable is created,
    in the current implementation all that must be done is to make the
    symbol table entry point to that new variable. In the "new value"
    implementation, all of the data from the original value must be
    copied to the new variable, and then copied back at the end of the
    block/scope. To me, this seems like it will pretty clearly slow
    things down. Of course, we can't know unless it's benchmarked.

  * I honestly have no concept of how many existing programs rely on the
    current behavior. I'm inclined to think it's not too many, but still
    a few. But since plenty of other things have broken backwards
    compatibility, this aspect doesn't worry me too much.

>We can go on discussing this here, but I think the only sensible thing
>to do would be to submit a bug report, and to let the developers make a
>decision (Abigail, are you still reading this? Have you submitted a bug
>report). We are both second-guessing what the real behaviour should be,
>and neither of us really knows.

Sure, I have no objections to taking it to p5p. However, I'm skeptical
that this will really produce the discussion of it that we'd want. I
think there's a decent chance it'd just be ignored, unfortunately. p5p
has been like that lately.

Here's my biggest reason for thinking that this is at least a known and
decided-upon thing: I find it very hard to believe that this has never
come up before. Taking a reference to something, using local on that
something, and then discovering that the reference refers to the
original value is not that bizarre of a thing to do. I disbelieve that
it's never been talked about before.

I just spent 2 hours reading through p5p archives on xray.
Unfortunately, I didn't find exactly what we're looking for (although I
sure learned a lot of interesting stuff) -- xray is IMO extremely
difficult to use to search for a specific topic. I still stand by the
claim that this is at least known and a concious decision, but like you
say several times, there's no way to really know.

-dlc


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

Date: Tue, 26 Sep 2000 03:20:34 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: References and local
Message-Id: <slrn8t05ft.m9.mgjv@verbruggen.comdyn.com.au>

On 26 Sep 2000 02:01:53 GMT,
	Daniel Chetlin <daniel@chetlin.com> wrote:
> On Mon, 25 Sep 2000 22:02:44 GMT,
>  Martien Verbruggen <mgjv@verbruggen.comdyn.com.au> wrote:
> >
> >       Temporary Values via local()
> >               
> >[SNIP]
> >       A `local' modifies its listed variables to be "local" to
> >       the enclosing block, `eval', or `do FILE'--and to any
> >       subroutine called from within that block.  A `local' just
> >       gives temporary values to global (meaning package)
> >       variables.  It does not create a local variable.
> >                           ^^^
> >
> >(Emphasis present in original)
> 
> Hmm, this emphasized part isn't convincing to me -- what is meant here,
> I'm almost positive, is that it means it doesn't create a lexical
> variable. The docs are very careful to never give people the impression

Hmmm.. You could be right, although the docs also are quite good at
saying 'lexical' when they mean lexical scope, and 'dynamic' or
'local' when they mean dynamic scope. But yes, the whole naming of
this area has been confused and confusing in the past, and old
documentation used 'wrong' terminology when lexical scoping became
possible. Even though work has been done to clean all that up, there
may still be remnants around.

> that local does anything but save a variable (or value, if you wish) to
> be reinstated later, _rather_ than creating a "local variable" (which
> you do with my). The part about giving temporary values is indeed
> concerning, however. I still think it's an error in the docs, but like I
> said it may be an error in the implementation.

*nod* We'll just have to agree to disagree here :)

>   * In either way of implementing local, a new scalar will have to be
>     created. The difference is that once that new variable is created,
>     in the current implementation all that must be done is to make the
>     symbol table entry point to that new variable. In the "new value"
>     implementation, all of the data from the original value must be
>     copied to the new variable, and then copied back at the end of the
>     block/scope. To me, this seems like it will pretty clearly slow
>     things down. Of course, we can't know unless it's benchmarked.

That sounds like it may be a significant cost. 

\begin[facetious]{comment}

But.. It is already documented that using local is slower than using
my. All that needs to be added is the word 'much' :)

\end{comment}

> Sure, I have no objections to taking it to p5p. However, I'm skeptical
> that this will really produce the discussion of it that we'd want. I
> think there's a decent chance it'd just be ignored, unfortunately. p5p
> has been like that lately.

Yes, well.. They are the only people that really can make any
decisions about whether it was intended behaviour or not, and whether
it should be changed or not. I've stopped reading p5p quite a while
ago, for several reasons, so I don't really know what the current
atmosphere there is.

Maybe it would be beneficial to get some opinions of other people on
this newsgroup in the thread as well.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I took an IQ test and the results
Commercial Dynamics Pty. Ltd.   | were negative.
NSW, Australia                  | 


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

Date: 26 Sep 2000 01:24:22 GMT
From: abigail@foad.org (Abigail)
Subject: Re: West Chester, PA 19380 Perl Users Group?
Message-Id: <slrn8svujq.lo9.abigail@alexandra.foad.org>

David Steuber (nospam@david-steuber.com) wrote on MMDLXXXIII September
MCMXCIII in <URL:news:m3wvg03ts9.fsf@solo.david-steuber.com>:
[] Does anyone know of any Perl users groups in the West Chester PA area?
[] Zipcode 19380.


West Chester isn't that far from Philly, which has quite an active
users group, meeting twice a month, (and they used to have a reading
group in the weeks there wasn't a meeting).



Abigail
-- 
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
          q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'


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

Date: 25 Sep 2000 18:00:39 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: When to use \ ?
Message-Id: <m3lmwgrsa0.fsf@dhcp11-177.support.tivoli.com>

"Webscot5" <webscot@uswestmail.net> writes:

> I am new to Perl. I wish to post some form results on an HTML page after
> submission of the form. I continue to get a 500 Error for Barewords when
> writing statements like this one:
> 
> Bareword found where operator expected at order2.cgi line 264, near ""0"
> cellpadding"
>  (Missing operator before cellpadding?)
> syntax error at order2.cgi line 264, near ""0" cellpadding"
> Bareword found where operator expected at order2.cgi line 264, near ""0"
> width"
>  (Missing operator before width?)
> 
> I get the same error for either format of the statements below (with or
> without the \).

That shouldn't be.  They way you have corrected it with the
backslashes appears to be correct.  Further more, if I execute the
second version, it works fine.  Are you sure that the error is the
same in both cases?

> --For the following partial statement--
> 
> print "<body bgcolor=\"#FFFFFF\">\n";
> print "<table border="0" cellspacing="0" cellpadding="0" width="100%">\n";
> 
> When do I know to add a \ in the above statement?
> Such as here:
> 
> print "<body bgcolor=\"#FFFFFF\">\n";
> print "<table border=\"0\" cellspacing=\"0\" width=\"100%\">\n";
> 
> Or what else might be causing the error? Similar commands exist in the
> script with no mention of a line error.

Note that Perl offers better ways to handle this type of string.  Here
are a couple of them:

print <<EOD;
<body bgcolor="#FFFFFF">
<table border="0" cellspacing="0" width="100%">
EOD

-or-

print qq(<body bgcolor="#FFFFFF">\n);
print qq(<table border="0" cellspacing="0" width="100%">\n);

Furthermore, all of this can be a lot cleaner through the use of the
CGI module. (For more information, see: perldoc CGI).

HTH,
-- 
Ren Maddox
ren@tivoli.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 4429
**************************************


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