[23573] in Perl-Users-Digest
Perl-Users Digest, Issue: 5780 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 11 09:05:51 2003
Date: Tue, 11 Nov 2003 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 11 Nov 2003 Volume: 10 Number: 5780
Today's topics:
Re: Calling a sub in main script from module <matthias_weckman@hotmail.com>
Re: Calling a sub in main script from module (Anno Siegel)
Re: LWP::UserAgent and SSL is it impossible? <kuujinbo@hotmail.com>
my command (sorry newbe question) (Torch)
Re: my command (sorry newbe question) <ak+usenet@freeshell.org>
Re: my command (sorry newbe question) <kaspREMOVE_CAPS@epatra.com>
Re: Sort array of objects using a method (Marcus)
Sorting a multi-dimensional hash (ifiaz)
Re: Sorting a multi-dimensional hash (Anno Siegel)
Re: Style question: map versus foreach <calle@cyberpomo.com>
Re: Style question: map versus foreach <tassilo.parseval@rwth-aachen.de>
Re: Style question: map versus foreach <abigail@abigail.nl>
Re: Tool to embed images (or other binaries) in your P (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 11 Nov 2003 12:45:24 +0100
From: Matthias Weckman <matthias_weckman@hotmail.com>
Subject: Re: Calling a sub in main script from module
Message-Id: <3fb0cbd3$0$50813$c4fe714e@dreader10.xs4all.nl>
fatted wrote:
> Having called a function from a module, I'd like that module function
> to call a function from the main script, but I can't figure out how
> (had a look through perlsub, perlmod,...)
You call fully qualified subs like this:
package::subroutine(@arguments);
> Simple Example:
>
[snip]
> ###### Readable.pm
>
> package Readable;
> use Exporter;
> @ISA = ('Exporter');
> @EXPORT = qw(&file_readable);
>
> sub file_readable
> {
> my $file = shift;
> open(IN,"<",$file) or $main::write_log("No thanks");
> }
>
> 1;
>
> ######
>
> When I run script.pl, I get:
> syntax error at Readable.pm line 9, near "$main::write_log("
> Compilation failed in require at ./script.pl line 5.
> BEGIN failed--compilation aborted at ./script.pl line 5.
That's right. $main::write_log would be a variable, so $v(...) is
syntactically incorrect.
Remove the $ sign from that call.
> Whats the correct way to do this?
main::write_log(...).
While you're asking... A correct way of testing if a file is readable is
using the -r or -R file test. (See the first entry in the Alphabetical
section of perlfunc).
You don't have to open the file to see if you can read from it:
sub file_readable
{
my $file = shift;
-f $file and -r $file or main::write_log("No thanks");
}
> While we're here, if, use strict; use warnings; are used in a script
> does this apply to any modules which are included by the script (via
> use)?
No, use strict; and use warnings; are lexically scoped. This means they
are valid only in the current file (or block, so you can turn them off
in specific places if you have to). The nice thing about that is that
you can specify the level of strictness or warnings within each module.
See perlmodlib, first section, for more details
Matthias
------------------------------
Date: 11 Nov 2003 12:14:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Calling a sub in main script from module
Message-Id: <boqjqo$aoh$1@mamenchi.zrz.TU-Berlin.DE>
fatted <obeseted@yahoo.com> wrote in comp.lang.perl.misc:
> Having called a function from a module, I'd like that module function
> to call a function from the main script, but I can't figure out how
You can do that -- your error below is trivial -- but the big question
is *why* would you want to do that.
The purpose of building a module (instead of putting everything in the
main program) is to make a set of functions independent of the main
program. When the module calls a function from the main program, that
independence is lost, so you might as well keep everything in one file.
> (had a look through perlsub, perlmod,...)
> Simple Example:
>
> ####### script.pl
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Readable;
>
> my $file = 'not_there.txt';
>
> file_readable($file);
>
> sub write_log
> {
> my $msg = shift;
> print $msg."\n";
> }
>
> ###### Readable.pm
>
> package Readable;
> use Exporter;
> @ISA = ('Exporter');
> @EXPORT = qw(&file_readable);
>
> sub file_readable
> {
> my $file = shift;
> open(IN,"<",$file) or $main::write_log("No thanks");
^
What is the "$" doing there? That's no way to call a program.
(Then again, you may have been clairvoyant. See below.)
open(IN,"<",$file) or main::write_log("No thanks");
> }
>
> 1;
>
> ######
>
> When I run script.pl, I get:
> syntax error at Readable.pm line 9, near "$main::write_log("
> Compilation failed in require at ./script.pl line 5.
> BEGIN failed--compilation aborted at ./script.pl line 5.
>
> Whats the correct way to do this?
There is no one correct way, but a better way to call back into the
main program is for the module to have a method (not necessarily in
the OO sense) for the main program to *tell* the module which subroutine
to call. Change Readable.pm like this:
package Readable;
use Exporter;
@ISA = ('Exporter');
@EXPORT = qw(&file_readable &set_logger);
my $logger;
sub set_logger {
$logger = shift;
}
sub file_readable
{
my $file = shift;
open(IN,"<",$file) or $logger->("No thanks");
}
1;
(You even get the dollar on the sub call back :)
Now the main program becomes:
#!/usr/bin/perl
use strict; use warnings; $| = 1; # @^~`
use Readable;
set_logger( sub {
my $msg = shift;
print $msg."\n";
}
);
my $file = 'not_there.txt';
file_readable($file);
The point of the changes is that now Readable.pm no longer has to know
how the logging routine is named in the main program, so it can again
work with a variety of main programs. Consequently, the logging routine
doesn't even have a name anymore, though you could use a named one
as well.
> While we're here, if, use strict; use warnings; are used in a script
> does this apply to any modules which are included by the script (via
> use)?
No, they don't propagate. A file is a lexical unit (block) of itself,
and the effects of "use strict" and "use warnings" are confined to
the current lexical scope.
Anno
------------------------------
Date: Tue, 11 Nov 2003 21:41:50 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: LWP::UserAgent and SSL is it impossible?
Message-Id: <boqlk5$lbv$1@pin3.tky.plala.or.jp>
Paul Lemmons wrote:
> I have spent most of the day trying to get this to work. I have visited
> hundreds of web pages and it appears to be a common frustration but
> nobody seems to be posting any solutions I am beginning to wonder if it
> is impossible.
>
> I want to script a login to a secure web site in perl. The web site is
> using session cookies and SSL. It is not using basic authentication. No
> matter what I try I always get "Authentication failed!" returned from
> the server.
>
> If I understand correctly how this should work, I would get a successful
> response from this request along with a cookie that I would use for all
> subsequent requests. I am not getting that cookie because I am not
> getting success.
>
> If this truly is impossible, please, someone say so so I can quit
> beating my head against this. If you have actually gotten this to work I
> would be thrilled if you could share your solution!
>
> Thank you!!
[snip code]
I'm not sure if this will solve your problem, but since you're using the
as_string() method for debugging anyway, you might as well try the
previous() method too. As documented in HTTP::Response:
==DOCUMENTATION
$r->previous([$previousResponse])
...
The previous attribute is used to link together chains of responses. You
get chains of responses if the first response is redirect or unauthorized.
==END QUOTE
I would guess that since you're getting an 'Authentication failed' page,
you might also be getting a redirect/unauthorized response before that.
(the user agent automatically follows redirects) So something like the
following should give you the full chain of responses (in reverse
order), which might help you figure out what's missing:
*untested*
## same as your code - LAST response
print join("\n", "STATUS LINE:", $res->status_line), "\n\n";
print join("\n", "REQUEST:", $res->as_string), "\n\n";
## this will cover any response due to redirect or unauthorized
{
my $res = $res;
while (my $previous = $res->previous) {
print join("\n", "STATUS LINE:", $previous->status_line), "\n\n";
print join("\n", "REQUEST:", $previous->as_string), "\n\n";
$res = $previous;
}
}
use strict;
use warnings;
might also help :)
HTH - keith
------------------------------
Date: 11 Nov 2003 03:26:53 -0800
From: rvw_torch@hotmail.com (Torch)
Subject: my command (sorry newbe question)
Message-Id: <d774347.0311110326.22e9d628@posting.google.com>
I just started a little perl programming. I noticed a lot of "my"
commands before declaring a variable. I was under the impression that
the "my" command was only used to declare a variable locally (like for
instance in a subroutine). I noticed from a code I got that in some
cases "my" was used and in other cases not. Can somebody help me with
understanding when to use "my" and when not to use "my"
------------------------------
Date: Tue, 11 Nov 2003 11:32:13 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: my command (sorry newbe question)
Message-Id: <slrnbr1i5p.dbc.ak+usenet@vinland.freeshell.org>
In article <d774347.0311110326.22e9d628@posting.google.com>, Torch wrote:
[cut]
> cases "my" was used and in other cases not. Can somebody help me with
> understanding when to use "my" and when not to use "my"
Maybe these articles could help you a tiny bit:
http://perl.about.com/library/weekly/aa022101a.htm
http://perl.about.com/library/weekly/aa022801a.htm
--
Andreas Kähäri
------------------------------
Date: Tue, 11 Nov 2003 18:51:55 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: my command (sorry newbe question)
Message-Id: <boqnpp$1hqlfs$1@ID-191136.news.uni-berlin.de>
Make the following two lines as the first lines of your code and you will
know when to use my or not. Its a very helpful and also a good practice!
use strict;
use warnings;
--
------------------------------
Date: 11 Nov 2003 03:48:21 -0800
From: bayrazone@web.de (Marcus)
Subject: Re: Sort array of objects using a method
Message-Id: <e4e6bd06.0311110348.18ef1218@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7llqo11d0.fsf@mail.sysarch.com>...
> >>>>> "M" == Marcus <bayrazone@web.de> writes:
>
> M> Hello, I'am a newbee in Perl and in Newsgroups. But I hope for some
> M> help.
>
> M> I have a array of Objekts and i want to sort these Objekts by using a
> M> Objektmethod.
>
> M> I tried this:
> M> certainly the Objektstore ist filled with Objekts !!!
>
> M> @unsortedObjektstore
>
> M> @sortedObjekts = sort {$unsortedObjektstore->getNumber() <=>
> M> $unsortedObjektstore->getNumber()} @unsortedObjektstore;
>
> where did $unsortedObjektstore get its value? sort doesn't put it there.
>
> M> I thougt it works like an example in perldoc:
> M> # sort numerically descending
> M> @articles = sort {$b <=> $a} @files;
>
> so do the same as sort. note that $a and $b are special variable that
> sort uses to assign pairs of values to be compared. your code assumed
> your own variable name which is wrong.
>
> so use use $a and $b as the objects and call your methods like you did:
>
> @sortedObjekts = sort { $a->getNumber() <=> $b->getNumber()}
> @unsortedObjektstore;
>
> uri
Hey, it works.
The hint with the special variable was the key.
Thanks a lot.
-Marcus
------------------------------
Date: 11 Nov 2003 04:53:33 -0800
From: ifiaz@hotmail.com (ifiaz)
Subject: Sorting a multi-dimensional hash
Message-Id: <93c1947c.0311110453.56728fee@posting.google.com>
Problem:
I populate a hash %Fnd with the following data
it loops through the file with 300000 lines of data.
###CODE
while (<>) {
if ( something == somethingelse) {
$Fnd{$Lic}{Count}++;
$cF = $Fnd{$Lic}{Count};
$Fnd{$Lic}{$cF}{ScanTimeDt} = substr($mScanTimeDt, 6, 2);
$Fnd{$Lic}{$cF}{ScanTime} = $ScanTime; #090000 (Sample Data)
$Fnd{$Lic}{$cF}{mFullScanTime} = $mFullScanTime; #20030317090000 (Sample data)
$Fnd{$Lic}{$cF}{IUMethod} = $IUMethod;
$Fnd{$Lic}{$cF}{IU} = $IU;
$Fnd{$Lic}{$cF}{Carrier} = $Carrier;
$Fnd{$Lic}{$cF}{CarCode} = $CarCode;
$Fnd{$Lic}{$cF}{FlightNo} = $FlightNo;
$Fnd{$Lic}{$cF}{Chute} = $Chute;
$Fnd{$Lic}{$cF}{TiltTimeDt} = substr($mTiltTimeDt, 6, 2);
$Fnd{$Lic}{$cF}{mTiltTimeDy} = $mTiltTimeDy;
$Fnd{$Lic}{$cF}{mTiltTime} = $mTiltTime;
$Fnd{$Lic}{$cF}{TStamp} = $TStamp;
}
}
###Looping through files end here.
## After the %Fnd is populated, I do a display of
## it in the appropriate format.
foreach $tmpLic (sort keys %Fnd) {
# do a display of the %Fnd hash one by one
}
__END__
Initially above loop was used to display, but later I
realize that I need to sort the hash not by the $Lic
in $Fnd{$Lic} but by the $Fnd{$Lic}{$Cf}{mFullScanTime}.
How can I have the hash sorted by my requirement?
I have tried various ways from newsgroups examples, etc.
but eventually fail. Could someone please help with
layman terms?
I am able to sort the hash when it is just one or two
dimensions but not more. I get utterly confused when
the gets more than two dimension.
I am newbie to perl actually to programming itself.
Thanks.
------------------------------
Date: 11 Nov 2003 13:31:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting a multi-dimensional hash
Message-Id: <boqobk$e3k$1@mamenchi.zrz.TU-Berlin.DE>
ifiaz <ifiaz@hotmail.com> wrote in comp.lang.perl.misc:
> Problem:
>
> I populate a hash %Fnd with the following data
> it loops through the file with 300000 lines of data.
>
> ###CODE
No. What follows is pseudo-code. You improve your chances of getting
useful replies when you post runnable code.
> while (<>) {
>
> if ( something == somethingelse) {
>
> $Fnd{$Lic}{Count}++;
>
> $cF = $Fnd{$Lic}{Count};
>
> $Fnd{$Lic}{$cF}{ScanTimeDt} = substr($mScanTimeDt, 6, 2);
> $Fnd{$Lic}{$cF}{ScanTime} = $ScanTime; #090000 (Sample Data)
> $Fnd{$Lic}{$cF}{mFullScanTime} = $mFullScanTime; #20030317090000 (Sample data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> $Fnd{$Lic}{$cF}{IUMethod} = $IUMethod;
> $Fnd{$Lic}{$cF}{IU} = $IU;
> $Fnd{$Lic}{$cF}{Carrier} = $Carrier;
> $Fnd{$Lic}{$cF}{CarCode} = $CarCode;
> $Fnd{$Lic}{$cF}{FlightNo} = $FlightNo;
> $Fnd{$Lic}{$cF}{Chute} = $Chute;
> $Fnd{$Lic}{$cF}{TiltTimeDt} = substr($mTiltTimeDt, 6, 2);
> $Fnd{$Lic}{$cF}{mTiltTimeDy} = $mTiltTimeDy;
> $Fnd{$Lic}{$cF}{mTiltTime} = $mTiltTime;
> $Fnd{$Lic}{$cF}{TStamp} = $TStamp;
Why let everyone wade through all these lines? The only one relevant
to the problem is the one I highlighted.
> }
>
> }
Please learn how to indent properly. Again, the more readable your code
is, the better are your chances that someone will actually read it.
> ###Looping through files end here.
>
> ## After the %Fnd is populated, I do a display of
> ## it in the appropriate format.
>
> foreach $tmpLic (sort keys %Fnd) {
>
> # do a display of the %Fnd hash one by one
>
> }
>
> __END__
>
> Initially above loop was used to display, but later I
> realize that I need to sort the hash not by the $Lic
> in $Fnd{$Lic} but by the $Fnd{$Lic}{$Cf}{mFullScanTime}.
You mean, sorting the hash *keys*.
> How can I have the hash sorted by my requirement?
By supplying the corresponding comparison routinei (untested):
sort { $Fnd{$a}{$Cf}{mFullScanTime} <=> $Fnd{$b}{$Cf}{mFullScanTime} }
keys %Fnd;
Anno
------------------------------
Date: Tue, 11 Nov 2003 12:08:32 +0100
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: Style question: map versus foreach
Message-Id: <86wua7upqn.fsf@ulthar.bisexualmenace.org>
>>>>> "Darin" == Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> writes:
> The only real difference between map and foreach is that map returns a
> value, while foreach doesn't [1]. Thus, if you intend on ignoring the
> return, don't create it in the first place and just use foreach.
But map *doesn't* create a list to return when you use it in a void
context. So the choice between map or foreach does become one of
simple personal preference.
> No - it means that the perlstyle authors (who are probably more
> proficient in perl than the both of us put together) thought this
> would be obvious and unneeding of justification.
Argumentation by appeal to authority is pretty weak. That you're also
wrong only makes it worse, Abigail knows at least as much about Perl
as whoever wrote perlstyle (TomC probably, since it doesn't have any
author information in it).
--
Calle Dybedahl <calle@lysator.liu.se>
"I like darkness, because it shows us light" -- Victoria McManus
------------------------------
Date: 11 Nov 2003 12:03:04 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Style question: map versus foreach
Message-Id: <boqj5o$e4m$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Calle Dybedahl:
>>>>>> "Darin" == Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> writes:
>> No - it means that the perlstyle authors (who are probably more
>> proficient in perl than the both of us put together) thought this
>> would be obvious and unneeding of justification.
>
> Argumentation by appeal to authority is pretty weak. That you're also
> wrong only makes it worse, Abigail knows at least as much about Perl
> as whoever wrote perlstyle (TomC probably, since it doesn't have any
> author information in it).
Minor correction: as whoever wrote perl. :-)
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Nov 2003 12:46:30 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Style question: map versus foreach
Message-Id: <slrnbr1mh5.fcf.abigail@alexandra.abigail.nl>
Darin McBride (dmcbride@naboo.to.org.no.spam.for.me) wrote on MMMDCCXXIV
September MCMXCIII in <URL:news:grWrb.362981$pl3.319787@pd7tw3no>:
@@ Abigail wrote:
@@
@@ > Darin McBride (dmcbride@naboo.to.org.no.spam.for.me) wrote on MMMDCCXXIII
@@ > September MCMXCIII in <URL:news:RKQrb.361373$6C4.143831@pd7tw1no>:
@@ > :: Abigail wrote:
@@ > ::
@@ > :: > If you're going to assume the maintainer doesn't know basic concepts
@@ > :: > of Perl, all bets are off. Then one might want to avoid hashes and
@@ > :: > regexes too.
@@ > ::
@@ > :: True to a point. However, there is no cleaner way to do hashes or
@@ > :: regexes. There is a clearer way to do map in void context: foreach.
@@ >
@@ > But could you give an objective reason why foreach is "clearer" than
@@ > map (after defining what "clearer" is)? Or is it your own preference?
@@
@@ <sigh> I thought I had. Let me try again:
@@
@@ The only real difference between map and foreach is that map returns a
@@ value, while foreach doesn't [1]. Thus, if you intend on ignoring the
@@ return, don't create it in the first place and just use foreach.
map in void context has never returned anything. No function in void
context has ever returned anything. How could it - if it returned
something, it couldn't have been in void context. Now, up to 2 versions
ago, map created a temporary list, even if it didn't need it. That has
now been fixed.
@@ [1] Foreach actually returns the same way any block does - the last
@@ statement executed in the last time through the loop is the return
@@ value. But this is not generally useful. It only makes perl more
@@ consistant.
@@
@@ > What makes foreach cleaner than while? Or is while cleaner than
@@ > foreach? Which one ought to go? Or can we have foreach, for, while,
@@ > until, goto, and bare blocks, but not map in void context?
@@
@@ While vs foreach is another discussion (I wish we'd stick to a single
@@ topic, but that's not generally possible on usenet, I suspect). If the
@@ only data I have to work with is whether we're in void context or not,
@@ then neither while nor foreach are different. However, they have other
@@ strengths which would come up should we actually debate those. Again,
@@ use whichever one makes the most readable sense.
The latter is a good remark. That's why I sometimes use while, sometimes
for/foreach, and sometimes map in void context. See, there is a difference
how you read them:
map ACTION DATA;
for DATA ACTION;
If I want to have the focus on the action, I prefer map. If I want to
focus on the action, I prefer for. But focus isn't the only thing that's
important for readability. I prefer shorter things before larger things.
So, if my block is large, I'll prefer to use for. But if the data is
coming from a long and complex expression, I'll favour map.
@@ Until vs while is easy - again, the most readable one wins. If your
@@ assertion is positive, use while, if it is negative, use until.
So, you decide on for vs while and while vs until on a case by case
basis. That's good. However, you dismiss map right away.
@@ > :: The main point of map is the return value. The main point of foreach
@@ > :: is the iteration over an array (no return value implied).
@@ > ::
@@ > :: o Avoid using grep() (or map()) or `backticks` in a void
@@ > :: context, that is, when you just throw away their
@@ > :: return values. Those functions all have return val-
@@ > :: ues, so use them. Otherwise use a foreach() loop or
@@ > :: the system() function instead.
@@ > ::
@@ > :: I think this is the whole debate. Unfortunately, there's no real
@@ > :: explicit justification here.
@@ >
@@ > Which makes it just the personal preference of one man, doesn't it?
@@
@@ No - it means that the perlstyle authors (who are probably more
@@ proficient in perl than the both of us put together) thought this would
@@ be obvious and unneeding of justification.
Well, apparently it isn't obvious, and in dire need of a justification.
But I don't think Larry is going to do that. Some fragments of perlstyle:
Larry has his reasons for each of these things, but he
doesn't claim that everyone else's mind works the same as
his does.
o Just because you CAN do something a particular way
doesn't mean that you SHOULD do it that way. Perl is
designed to give you several ways to do anything, so
consider picking the most readable one. For instance
open(FOO,$foo) || die "Can't open $foo: $!";
is better than
die "Can't open $foo: $!" unless open(FOO,$foo);
because the second way hides the main point of the
statement in a modifier. On the other hand
print "Starting analysis\n" if $verbose;
is better than
$verbose && print "Starting analysis\n";
because the main point isn't whether the user typed -v
or not.
See? Larry thinks that it's important that you mention the main point
first. So, if the main point is the action, not the data it acts upon,
you would write:
map ACTION DATA;
and not
for DATA ACTION;
@@ > :: Given that map and foreach do almost exactly the same thing with only
@@ > :: the desired contexts being different, it makes sense to me that one
@@ > :: would use the version one desires based on that context difference.
@@ > :: Thus, when I see map in void context, the first thought in my mind is
@@ > :: "they didn't get the return from map!".
@@ >
@@ > Ah, yes. Logical. There are thousands and thousands of user defined
@@ > functions whose return value isn't collected. There are many Perl
@@ > defined functions and operators whose return value isn't collected.
@@ >
@@ > Noone ever makes a fuss. But if the function of which the return
@@
@@ I do. If there are two user defined functions that do exactly the same
@@ thing, but one allocates and returns an array, and the other does not
@@ but has the same desired side effects, I would expect people to use the
@@ appropriate one depending on whether they want the array returned or
@@ not. I don't see any difference.
There are two points against that:
1) map in void context *doesn't* allocated an array whose
values remained unused.
2) it goes against all ideas of encapsulation. If in order
to use a module, I would first have to study the implementation
of its functions, why bother? I could write my own. But you
go further, you require people to first have studied the
implementation of perl before they can pick the "right way".
I presume you have carefully studied all the libraries Perl
links in as well?
@@
@@ > value isn't collected is called "map", hundreds of Perl programmer
@@ > brains go into overload, and the programmers start running around
@@ > like chickens without their heads. "They didn't get the return from
@@ > map! They didn't get the return from map! Keep your daughters inside!
@@ > Keep your daughters inside! The end of times in coming! The antichrist
@@ > has arrived!"
@@
@@ I'm not sure that the Six Degrees of Godwin game would have anticipated
@@ this as "legitimate topic drift".
@@
@@ > I really don't get it. map in void context isn't doing anything else
@@ > than the countless of other functions in void context that are called
@@ > because of their side effects. Yet it sparks gigabytes of discussions.
@@
@@ Only because there is an exact duplicate of map functionally that is
@@ there for void context.
There is also an exact duplicate of 'unless' (which even takes less
characters to type). Should 'unless' be avoided as well? The functionality
of while() can also exactly be duplicated with bare blocks. Should
while() be avoided? If the answers are 'no', then why is it so bad
there's another way of doing a map in void context?
@@
@@ > :: In general, side
@@ > :: effects make code harder to understand.
@@ >
@@ > Then you shouldn't be programming in Perl. Because in Perl, you can't
@@ > do much useful without side effects.
@@
@@ Hmmm... I dunno - I've managed to do a lot of useful stuff without side
@@ effects in perl.
Really? Could you show some code? Remember, assignment and print are
only useful because of their side effects.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: 11 Nov 2003 11:39:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Tool to embed images (or other binaries) in your Perl source.
Message-Id: <boqhqd$988$1@mamenchi.zrz.TU-Berlin.DE>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On Fri, 07 Nov 2003 18:44:21 GMT, Marc Dashevsky <m_arc@world.std.com>
> wrote:
[...]
> >it's fine for people to program in "baby Perl" (can't remember the quote
> >exactly, but lurk long enough on clpm and you'll see it in someone's sig).
>
> No, it's not in anyone's .sig currently, but IIRC it's somewhere in
> the docs or some site of easy access on the web. I know what you're
> referring to!
There are a lot of remarks to that effect throughout Perl writings,
by Larry and by others (the words "Officially Okay" usually appear
near there), but there doesn't seem to be one compact quote that puts
it succinctly.
This one, from _Programming Perl_, says it all:
Speakers of a natural language are allowed to have differing skill
levels, to speak different subsets of the language, to learn as they
go, and generally, to put the language to good use before they know
the whole language. You don't know all of Perl yet, just as you don't
know all of English. But that's Officially Okay in Perl culture.
...but that won't fit in a sig.
This, from _Natural Language Principles in Perl_, is shorter, but it's
palpably taken out of context:
You'd like to be able to talk baby talk and be understood. It's okay
if a language is difficult to learn, as long as you don't have to
learn it all at once.
Anno
------------------------------
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 5780
***************************************