[21766] in Perl-Users-Digest
Perl-Users Digest, Issue: 3970 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 14 18:11:03 2002
Date: Mon, 14 Oct 2002 15:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Oct 2002 Volume: 10 Number: 3970
Today's topics:
Re: Small syntax utility function (Zachary Beane)
Re: Small syntax utility function <uri@stemsystems.com>
Re: Small syntax utility function (Zachary Beane)
Re: Small syntax utility function <bart.lateur@pandora.be>
Re: Small syntax utility function (Zachary Beane)
Re: Small syntax utility function <uri@stemsystems.com>
Re: Small syntax utility function <Tassilo.Parseval@post.rwth-aachen.de>
Re: Small syntax utility function <s_grazzini@hotmail.com>
Re: Small syntax utility function (Zachary Beane)
Re: Small syntax utility function <goldbb2@earthlink.net>
Re: Small syntax utility function <Tassilo.Parseval@post.rwth-aachen.de>
Re: Small syntax utility function <goldbb2@earthlink.net>
Re: Splitting CSV lines <goldbb2@earthlink.net>
Re: Switching from Python to Perl <goldbb2@earthlink.net>
Re: Thread::Queue; or variable scope? <occitan@esperanto.org>
Re: What purpose does eval{ ... } server? <jurgenex@hotmail.com>
Re: What purpose does eval{ ... } server? <Tassilo.Parseval@post.rwth-aachen.de>
Re: Where are command line arguments described? <cpryce@pryce.net>
Re: Where are command line arguments described? (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Oct 2002 18:45:21 GMT
From: xach@xach.com (Zachary Beane)
Subject: Re: Small syntax utility function
Message-Id: <slrnaqm494.a4u.xach@localhost.localdomain>
In article <aof0om$jst$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval wrote:
> Also sprach Zachary Beane:
>
>> I would like to have a function "foreachpair" that lets me to this:
>>
>> my @list = qw(a 1 b 2 b 9 c 3);
>>
>> foreachpair {
>> print "$a => $b\n";
>> } @list;
>>
>> and have it print out:
>>
>> a => 1
>> b => 2
>> b => 9
>> c => 3
>>
>> I tried doing this with dynamic scoping with "local", but that runs
>> into problems with package scoping. Is there any package-safe way
>> to write a "foreachpair" with the above behavior?
>
> You could use a hash and use each() to iterate over it. But it may not
> be the most efficient way and also you loose the sorting.
>
> Or you use splice(). Unfortunately splice() is destructive, so use it
> only on a copy of your data:
>
> my @tmp = @list;
> while (my ($i, $j) = splice @tmp, 0, 2) {
> print "$i - $j\n";
> }
I'm a little unclear on your intent. I'm trying to write a subroutine;
I know how to do the operation in inline perl.
For reference, here's the sub I tried to use
sub foreachpair (&@) {
my $sub = shift;
for (my $x = 0; $x < $#_; $x += 2) {
local ($a, $b) = @_[$x, $x + 1];
$sub->();
}
}
But this sub breaks when called from another package. I can't figure
out how to package and re-use it.
Zach
------------------------------
Date: Mon, 14 Oct 2002 18:53:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Small syntax utility function
Message-Id: <x7r8esett1.fsf@mail.sysarch.com>
>>>>> "ZB" == Zachary Beane <xach@xach.com> writes:
ZB> for (my $x = 0; $x < $#_; $x += 2) {
ZB> local ($a, $b) = @_[$x, $x + 1];
don't use $a and $b. they are special (see sort) and are scoped to the
current package.
ZB> But this sub breaks when called from another package. I can't figure
ZB> out how to package and re-use it.
rename those vars.
perl6 solves this very common issue in a general purpose way.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 14 Oct 2002 18:58:54 GMT
From: xach@xach.com (Zachary Beane)
Subject: Re: Small syntax utility function
Message-Id: <slrnaqm52h.a51.xach@localhost.localdomain>
In article <x7r8esett1.fsf@mail.sysarch.com>, Uri Guttman wrote:
>>>>>> "ZB" == Zachary Beane <xach@xach.com> writes:
>
> ZB> for (my $x = 0; $x < $#_; $x += 2) {
> ZB> local ($a, $b) = @_[$x, $x + 1];
>
> don't use $a and $b. they are special (see sort) and are scoped to the
> current package.
I was hoping to use them exactly because they are special; they don't
trigger failures under "use strict" and they also make foreachpair
seem more like a built-in function like sort.
If I use other variable names, will I need to predeclare them with
"use vars" in any script that uses foreachpair?
Zach
------------------------------
Date: Mon, 14 Oct 2002 19:12:46 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Small syntax utility function
Message-Id: <vj5mqu8guq5a9pbefjqoukp92plk9267rq@4ax.com>
Tassilo v. Parseval wrote:
>> my @list = qw(a 1 b 2 b 9 c 3);
>>
>> foreachpair {
>> print "$a => $b\n";
>> } @list;
>You could use a hash and use each() to iterate over it. But it may not
>be the most efficient way and also you loose the sorting.
>
>Or you use splice(). Unfortunately splice() is destructive, so use it
>only on a copy of your data:
>
> my @tmp = @list;
> while (my ($i, $j) = splice @tmp, 0, 2) {
> print "$i - $j\n";
> }
My thoughts exactly. However, there's a third way: using an explicit
array index and a hash slice:
for(my $i =0; $i < @list; $i += 2) {
my ($a, $b) = @list[$i, $i+1];
print "$a => $b\n";
}
--
Bart.
------------------------------
Date: Mon, 14 Oct 2002 19:33:00 GMT
From: xach@xach.com (Zachary Beane)
Subject: Re: Small syntax utility function
Message-Id: <slrnaqm72g.a56.xach@localhost.localdomain>
In article <vj5mqu8guq5a9pbefjqoukp92plk9267rq@4ax.com>, Bart Lateur wrote:
[snip]
>
> My thoughts exactly. However, there's a third way: using an explicit
> array index and a hash slice:
>
> for(my $i =0; $i < @list; $i += 2) {
> my ($a, $b) = @list[$i, $i+1];
> print "$a => $b\n";
> }
My primary concern isn't to achieve iterating through a list by pairs;
I know how to do that. I'm interested in abstracting that operation at
a syntactic level, so it requires less typing and less list indexing
to pull off.
Zach
------------------------------
Date: Mon, 14 Oct 2002 19:35:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Small syntax utility function
Message-Id: <x7n0pgerua.fsf@mail.sysarch.com>
>>>>> "ZB" == Zachary Beane <xach@xach.com> writes:
ZB> I was hoping to use them exactly because they are special; they don't
ZB> trigger failures under "use strict" and they also make foreachpair
ZB> seem more like a built-in function like sort.
ZB> If I use other variable names, will I need to predeclare them with
ZB> "use vars" in any script that uses foreachpair?
why not just pass two params to the callback sub? don't try to use $a
and $b like sort does.
and the 2 line loop with arrays sliced (posted to this thread) is almost
as easy as your code. i would stick with that
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 14 Oct 2002 20:03:05 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Small syntax utility function
Message-Id: <aof7tp$r67$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Zachary Beane:
> In article <x7r8esett1.fsf@mail.sysarch.com>, Uri Guttman wrote:
>>>>>>> "ZB" == Zachary Beane <xach@xach.com> writes:
>>
>> ZB> for (my $x = 0; $x < $#_; $x += 2) {
>> ZB> local ($a, $b) = @_[$x, $x + 1];
>>
>> don't use $a and $b. they are special (see sort) and are scoped to the
>> current package.
>
> I was hoping to use them exactly because they are special; they don't
> trigger failures under "use strict" and they also make foreachpair
> seem more like a built-in function like sort.
>
> If I use other variable names, will I need to predeclare them with
> "use vars" in any script that uses foreachpair?
Well, you could always turn this pair-thing into a module that exports
$A and $B. Copy the below stuff into a file called pair.pm:
package pair;
use strict;
use base qw(Exporter);
our @EXPORT = qw($A $B pair);
sub pair(&@) {
my ($code, @list) = @_;
no strict 'refs';
while (@list) {
(${caller()."::A"}, ${caller()."::B"}) = splice @list, 0, 2;
$code->();
}
}
1;
And in your scripts:
use pair;
pair { print "$A - $B\n" } 1, 2, 3, 4;
Don't forget to put pair.pm in one of the directories stored in @INC or
add a
use lib '/path/to/module';
to your scripts if pair.pm is actually /path/to/module/pair.pm.
This may look like a lot of work for such a short thing. But a module
makes it reusable code so from then on you can use it in whatever script
you intend to run locally.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 14 Oct 2002 14:37:47 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Small syntax utility function
Message-Id: <3dab2b1a@news.mhogaming.com>
Zachary Beane <xach@xach.com> wrote:
> I would like to have a function "foreachpair" that lets me to this:
>
> my @list = qw(a 1 b 2 b 9 c 3);
>
> foreachpair {
> print "$a => $b\n";
> } @list;
>
$a and $b are "taken" by sort, so you might want
to pick some other variables, or pass the next two
elements as arguments to the coderef.
sub foreachpair (&@) {
my $code = shift;
if (@_ % 2) {
warn "Odd number of elements to foreachpair()";
}
if (prototype $code) {
for (my $i=0; $i<@_; $i+=2) {
$code->($_[$i], $_[$i+1]);
}
}
else {
no strict 'refs';
my $caller = caller;
while (@_) {
${$caller."::a"} = shift;
${$caller."::b"} = shift;
$code->();
}
}
}
And you can package this functionality more nicely as
an iterator:
package PairIterator;
sub new {
my $cls = shift;
my $arr = UNIVERSAL::isa($_[0], 'ARRAY') ? shift : \@_;
bless { pos => 0, arr => $arr }, $cls;
}
sub next_pair {
my $this = shift;
local (*pos, *arr) = @{$this}{qw/pos arr/};
return if $pos > $#arr;
@arr[$pos++, $pos++];
}
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Mon, 14 Oct 2002 20:32:46 GMT
From: xach@xach.com (Zachary Beane)
Subject: Re: Small syntax utility function
Message-Id: <slrnaqmaii.a6l.xach@localhost.localdomain>
In article <aof7tp$r67$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval wrote:
> Also sprach Zachary Beane:
>
>> In article <x7r8esett1.fsf@mail.sysarch.com>, Uri Guttman wrote:
>>>>>>>> "ZB" == Zachary Beane <xach@xach.com> writes:
>>>
>>> ZB> for (my $x = 0; $x < $#_; $x += 2) {
>>> ZB> local ($a, $b) = @_[$x, $x + 1];
>>>
>>> don't use $a and $b. they are special (see sort) and are scoped to the
>>> current package.
>>
>> I was hoping to use them exactly because they are special; they don't
>> trigger failures under "use strict" and they also make foreachpair
>> seem more like a built-in function like sort.
>>
>> If I use other variable names, will I need to predeclare them with
>> "use vars" in any script that uses foreachpair?
>
> Well, you could always turn this pair-thing into a module that exports
> $A and $B. Copy the below stuff into a file called pair.pm:
>
> package pair;
>
> use strict;
> use base qw(Exporter);
> our @EXPORT = qw($A $B pair);
>
> sub pair(&@) {
> my ($code, @list) = @_;
> no strict 'refs';
> while (@list) {
> (${caller()."::A"}, ${caller()."::B"}) = splice @list, 0, 2;
> $code->();
> }
> }
> 1;
>
> And in your scripts:
>
> use pair;
>
> pair { print "$A - $B\n" } 1, 2, 3, 4;
[snip]
This definition leaks $A and $B into the rest of the script. With
local(), the variables are truly temporary and limited to the intended
block.
Thanks, everyone, for the responses. I've concluded that my wishlist
for this bit of syntactic abstraction isn't feasible. I would love to
be able to do this:
foreachpair ($key, $val) (@keyvalpairs) {
print "$key => $val\n";
}
which would translate into something like:
for ($x = 0; $x < $#keyvalpairs; $x += 2) {
my ($key, $val) = @keyvalpairs[$x, $x + 1];
print "$key => $val\n";
}
But that sort of syntactic rearrangement isn't even close to possible
with the current prototype stuff. My original post was an attempt to
get something similar, but simpler and more limited, than the above
example.
Zach
------------------------------
Date: Mon, 14 Oct 2002 16:52:57 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Small syntax utility function
Message-Id: <3DAB2EA9.20115B13@earthlink.net>
Zachary Beane wrote:
>
> I would like to have a function "foreachpair" that lets me to this:
>
> my @list = qw(a 1 b 2 b 9 c 3);
>
> foreachpair {
> print "$a => $b\n";
> } @list;
>
> and have it print out:
>
> a => 1
> b => 2
> b => 9
> c => 3
>
> I tried doing this with dynamic scoping with "local", but that runs
> into problems with package scoping. Is there any package-safe way
> to write a "foreachpair" with the above behavior?
From your comments elsewhere in this thread, it seems that your problem
is not with how to get two at a time, but how to handle $a and $b as
special variables.
I would suggest the following [untested] code:
sub foreachpair(&@) {
my $sub = shift;
my ($aref, $bref) = do {
no strict 'refs';
\${ caller . "::a" }, \${ caller . "::b" };
};
my ($locala, $localb) = ($$aref, $$bref);
while( ($$aref, $$bref) = splice @_, 0, 2 ) {
&$sub();
}
($$aref, $$bref) = ($locala, $localb);
}
There isn't any way to use local() on $a and $b with this type of code,
though ... if $sub dies, they'll have the wrong values. The only way to
avoid that might be with eval STRING... something like:
sub foreachpair(&@) {
my $sub = shift;
eval q[package ].caller.q[; local ($a, $b);
while( ($a, $b) = splice @_, 0, 2 ) {
&$sub();
}
1;
] or die $@;
}
This has the drawback of calling eval every time the sub is called.
A better alternative might be to have your import method create one such
sub per package which requests it:
sub import {
my $fp = do { no strict 'refs'; \*{ caller . "::foreachpair" } };
*$fp = eval q[package ].caller.[; sub {
my $code = shift;
local ($a, $b);
while( ($a, $b) = splice @_, 0, 2 ) {
&$code();
}
} ] || die $@;
}
[untested... plus, if you have to export other subs, you'll have to do
other stuff, to]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 14 Oct 2002 21:10:27 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Small syntax utility function
Message-Id: <aofbs3$1vn$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Zachary Beane:
> In article <aof7tp$r67$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval wrote:
>> Well, you could always turn this pair-thing into a module that exports
>> $A and $B. Copy the below stuff into a file called pair.pm:
>>
>> package pair;
>>
>> use strict;
>> use base qw(Exporter);
>> our @EXPORT = qw($A $B pair);
>>
>> sub pair(&@) {
>> my ($code, @list) = @_;
>> no strict 'refs';
>> while (@list) {
>> (${caller()."::A"}, ${caller()."::B"}) = splice @list, 0, 2;
>> $code->();
>> }
>> }
>> 1;
> This definition leaks $A and $B into the rest of the script. With
> local(), the variables are truly temporary and limited to the intended
> block.
I played a little with string-eval and now I have something that - on
first sight - behaves just like Perl's sort-thing in regards to $a and $b.
So my two special variables $A and $B will be undefined once you leave
the block of pair():
package pair;
use strict;
use base qw(Exporter);
our @EXPORT = qw($A $B pair);
sub pair(&@) {
my ($code, @list) = @_;
my $caller = caller();
my $c = <<EOCODE;
local (\$${caller}::A, \$${caller}::B) = splice \@list, 0, 2;
\$code->();
EOCODE
eval $c while @list;
}
1;
String-eval is needed here since you can't localize a reference in Perl
as I just discovered ("Can't localize through a reference", so perl told
me). Anyway:
ethan@ethan:~$ perl -Mstrict -w -I. -Mpair
pair { print "$A - $B\n" } 1, 2, 3, 4;
print $A;
__END__
1 - 2
3 - 4
Use of uninitialized value in print at - line 2.
Sure, you still have $A and $B as phantoms in your scripts. But this is
the same with $a and $b. They are also always there somehow.
> Thanks, everyone, for the responses. I've concluded that my wishlist
> for this bit of syntactic abstraction isn't feasible. I would love to
> be able to do this:
>
> foreachpair ($key, $val) (@keyvalpairs) {
> print "$key => $val\n";
> }
>
> which would translate into something like:
>
> for ($x = 0; $x < $#keyvalpairs; $x += 2) {
> my ($key, $val) = @keyvalpairs[$x, $x + 1];
> print "$key => $val\n";
> }
>
> But that sort of syntactic rearrangement isn't even close to possible
> with the current prototype stuff. My original post was an attempt to
> get something similar, but simpler and more limited, than the above
> example.
Perl6 will have it. :-) Yummie...
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 14 Oct 2002 17:25:12 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Small syntax utility function
Message-Id: <3DAB3638.49396959@earthlink.net>
Zachary Beane wrote:
[snip]
> Thanks, everyone, for the responses. I've concluded that my wishlist
> for this bit of syntactic abstraction isn't feasible. I would love to
> be able to do this:
>
> foreachpair ($key, $val) (@keyvalpairs) {
> print "$key => $val\n";
> }
Actually, this is almost doable.
Try this [untested] code:
sub foreachpair(\$\$\@&) {
my ($keyref, $valref, $aref, $code) = @_;
for my $i ( 0 .. @$aref / 2 ) {
($$keyref, $$valref) = @_[ $i * 2, $i * 2 + 1 ];
&$code();
}
}
Which would then be called as:
my ($key, $val);
foreachpair $key, $val, @keyvaluepairs, sub {
print "$key => $val\n";
};
Or even:
foreachpair my($key, $val), @keyvaluepairs, sub {
print "$key => $val\n";
};
Note that the \@ prototype character needs to get an argument which
starts with an @ character... if you want to pass a list, rather than a
named array, you would have to wrap it in @{[]}, like this:
foreachpair my($key, $val), @{[ 1..10 ]}, sub {
print "$key => $val\n";
};
Beware, though: since local() is not used, the values assigned to $key
and $val will leak slightly... that is:
my ($key, $val) = ("foo", "bar")
foreachpair $key, $val, @{[ 1..10 ]}, sub {
print "$key => $val\n";
};
print "[$key, $val]\n";
Will print "[9, 10]\n", not "[foo, bar]\n".
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 14 Oct 2002 16:30:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Splitting CSV lines
Message-Id: <3DAB2960.673A0F3A@earthlink.net>
Andrew Cashin wrote:
>
> If anyone is interested, or (even better) has suggested improvements,
> here is a code fragment which copes (somewhat) with CSV lines where
> individual elements may or may not be quoted, but will be quoted if
> they contain either quotes (which will be quoted by doubling i.e. "")
> or commas.
[snip]
> @elements=split(/,/);
[snip]
Hmm, first you split on commas, then you go and fix places where it was
the wrong thing to do? Why not try and do it right in the first place?
my $line = ....;
my @cols = $line =~ m[
(?:^|\G,) # anchor at beginning of line, or after comma.
(
" (?> (?:[^"]+|"")* ) "
| [^,]*
)
]xg;
s/^"(.*)"\z/$1/ and s/""/"/g for @cols;
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 14 Oct 2002 16:18:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Switching from Python to Perl
Message-Id: <3DAB2679.5D1C36CF@earthlink.net>
Derek Thomson wrote:
[snip]
> So, Java. Perl really can't win here, as Python has the amazing
> Jython.
How does Jython compare to JPL, "Java Perl Lingo"?
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 14 Oct 2002 22:31:51 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Thread::Queue; or variable scope?
Message-Id: <20021014223151.5cff163d.occitan@esperanto.org>
Hi Gord,
I haven't used threads, but as far as I understand...
Gord Shier <shier@shorcan.com> skribis:
> use Thread;
> use Thread::Queue;
use Thread::Shared;
> use vars qw($queue);
> my $queue ;
our $queue : shared;
> my $val ;
> my $thr1;
> my $thr2;
> my $queue = new Thread::Queue;
you're hiding your first $queue here, with another my :-)
coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
--
-- http://dapfy.bei.t-online.de/sawfish/
--
------------------------------
Date: Mon, 14 Oct 2002 12:49:33 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <3dab1fdc@news.microsoft.com>
Paul Tomlinson wrote:
> What purpose does eval{ ... } server?
>
> Nice and simple. And when should eval be used?
It is THE way to run self-modifiying code. And therefore if at all it should
be used with great care only.
jue
------------------------------
Date: 14 Oct 2002 20:14:20 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <aof8is$roj$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Jürgen Exner:
> Paul Tomlinson wrote:
>> What purpose does eval{ ... } server?
>>
>> Nice and simple. And when should eval be used?
>
> It is THE way to run self-modifiying code. And therefore if at all it should
> be used with great care only.
Well, that would be true if the OP hat mentioned eval "...". 'eval
BLOCK' can't be used for self-modifying code, insofar it is safe.
Odd, that half of the people contributing to this thread (all being
quite competent Perl-programmers from what I have seen so far) mixed
that up. It only confirms my feelings that some of the Perl-keywords
have an unfortunate nomenclature. 'goto &FUNC' should have been 'call
&FUNC' or so while 'eval BLOCK' would have better been named 'trap BLOCK'.
All these seeming twins don't have that much in common and are used for
very different purposes.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 14 Oct 2002 13:21:16 -0500
From: cp <cpryce@pryce.net>
Subject: Re: Where are command line arguments described?
Message-Id: <B9D0754B.101F5%cpryce@pryce.net>
in article 3DAB099F.1030701@nospam.com, C2F46 at C2F46@nospam.com wrote on
10/14/02 1:14 PM:
> I've looked at the man page, info page, FAQ and could not find the
> description of perl command line options anywhere. This sucks.
>
> I have -U in my scripts like this:
> #!/usr/bin/p5 -U
>
> and could not find -U description anywhere. Any tips?
>
perldoc perlrun
-U allows Perl to do unsafe operations. Currently the
only "unsafe" operations are the unlinking of
directories while running as superuser, and running
setuid programs with fatal taint checks turned into
warnings. Note that the -w switch (or the "$^W"
variable) must be used along with this option to
actually generate the taint-check warnings
cp
------------------------------
Date: Mon, 14 Oct 2002 13:29:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Where are command line arguments described?
Message-Id: <slrnaqm390.1mt.tadmc@magna.augustmail.com>
C2F46 <C2F46@nospam.com> wrote:
> I've looked at the man page, info page, FAQ and could not find the
> description of perl command line options anywhere. This sucks.
perldoc perlrun
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 3970
***************************************