[23577] in Perl-Users-Digest
Perl-Users Digest, Issue: 5784 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 12 00:05:55 2003
Date: Tue, 11 Nov 2003 21:05:11 -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: 5784
Today's topics:
Re: Creating and submitting POST form in Perl (Tad McClellan)
how to erase \r or \015 in win32? <luke@program.com.tw>
Re: how to erase \r or \015 in win32? <noreply@gunnar.cc>
Re: how to erase \r or \015 in win32? <usenet@MarcDashevsky.com>
Re: LWP::UserAgent and SSL is it impossible? (Pierre Asselin)
Re: newbie 4th JaPH <hexkid@hotpop.com>
ppm error <luke@program.com.tw>
Re: print statement spanning multiple lines <voitec@zzzzzzzzz.com>
Re: Problems with Sendmail <noreply@gunnar.cc>
Re: simplify this if loop <pinyaj@rpi.edu>
Re: simplify this if loop <tore@aursand.no>
Re: simplify this if loop <tore@aursand.no>
Re: simplify this if loop <uri@stemsystems.com>
Re: small dbi help <spam@thecouch.homeip.net>
Re: Sorting a multi-dimensional hash (ifiaz)
Re: Style question: map versus foreach <usenet@morrow.me.uk>
Re: Style question: map versus foreach <grazz@pobox.com>
Re: Style question: map versus foreach <usenet@morrow.me.uk>
Re: went to 5.8.1 and now I can't access object data dy (Sophie Miron)
Re: Win32::OLE and CDO Message Filters (Jay Tilton)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 11 Nov 2003 19:18:32 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Creating and submitting POST form in Perl
Message-Id: <slrnbr32j8.f91.tadmc@magna.augustmail.com>
J.P. <john.p.zurilgen@saic.com> wrote:
> To anyone who might be able to help here,
Here is some help:
Check the Perl FAQ *before* posting to the Perl newsgroup.
> I've been seeking a way to create a POST form in Perl and handling the
> auto-submission. But, how can I do this?
perldoc -q form
How do I automate an HTML form submission?
> I've
> been going in circles now for 3 days, trying to scour the web and
> books for answers.
You will be disappointed to discover that the answer was already
on your very own hard disk then...
> Thank you VERY much in advance for any help!
Follow netiquette and prosper.
Ignore netiquette and waste 3 days plus the time of thousands of
other people around the world.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 12 Nov 2003 10:11:00 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: how to erase \r or \015 in win32?
Message-Id: <bos4qq$5rm@netnews.hinet.net>
i want to erase ^M in then end of lines.
but i can do this in win32.
$_=~s/\r//g; #but \r still exist
$e=\x0D;
$_=~s/$e//g; #have the same result
===================================
------------------------------
Date: Wed, 12 Nov 2003 03:20:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to erase \r or \015 in win32?
Message-Id: <bos5p3$1i24qu$1@ID-184292.news.uni-berlin.de>
news.hinet.net wrote:
> i want to erase ^M in then end of lines.
> but i can do this in win32.
>
> $_=~s/\r//g; #but \r still exist
Not for me.
$_ = "First line\r\nSecond line\r\n";
print length, "\n";
s/\r//g;
print length, "\n";
Printed result:
25
23
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 12 Nov 2003 02:36:36 GMT
From: Marc Dashevsky <usenet@MarcDashevsky.com>
Subject: Re: how to erase \r or \015 in win32?
Message-Id: <MPG.1a1b671e69defd949897c2@netnews.comcast.net>
luke@program.com.tw says in article <bos4qq$5rm@netnews.hinet.net>:
> i want to erase ^M in then end of lines.
> but i can do this in win32.
>
> $_=~s/\r//g; #but \r still exist
>
> $e=\x0D;
> $_=~s/$e//g; #have the same result
Maybe you don't have \r at the end of the lines, maybe
you really have the two characters "^M".
--
Marc Dashevsky -- Put "usenet" in Subject if you want me to read e-mail.
------------------------------
Date: Tue, 11 Nov 2003 20:39:19 -0500
From: pa@invalid.invalid (Pierre Asselin)
Subject: Re: LWP::UserAgent and SSL is it impossible?
Message-Id: <703sob.99a.ln@brick.verano.sba.ca.us>
Paul Lemmons <paul@not2bspammed.com> wrote:
> 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.
>
> [ ... ]
>
> $req = new HTTP::Request 'POST' =>
> 'https://xxx.yyy.com/_mem_bin/verifpwd.asp';
>
> [ ... ]
>
> $req->header('Content-Type' => 'application/x-www-form-urlencoded');
> $req->header('Content' => $content);
My HTTP is rusty but, are you sure about this 'Content: ' header?
I thought the form data had to go in the request body, after the headers
and separated from them by a blank line. So,
$req->content($content);
You could also use the convenience functions in HTTP::Request::Common .
------------------------------
Date: 11 Nov 2003 23:24:12 GMT
From: Pedro Graca <hexkid@hotpop.com>
Subject: Re: newbie 4th JaPH
Message-Id: <borr2s$1i2lg1$1@ID-203069.news.uni-berlin.de>
Michele Dondi wrote:
> On 10 Nov 2003 17:28:06 GMT, Pedro Graca <hexkid@hotpop.com> wrote:
>
>>I'm trying to understand Your JaPH.
>>All those dots are really obfuscating me ... but I'm not giving up!
>
> Oh, it's not that difficult:
Thank you for the analysis.
I know now why your JaPH has "hacker" with a lowercase "h" :)
Maybe you could have used one of the 107..117 for an "H" (maybe 109)
... but then your code would get even more complicated
> [...] change eval() to print() and you'll see a
> "less obfuscated core", modulo an extra "," at the end.
That stupid "," -- it isn't doing _anything_ !!!!
I even thought it might get into the substitutions or something, took me
a long time to discard it.
--
@ "=qw f Jt ss x_x am os hd q y_y Pd rk z_z Hab kd q f; $
_ =join "",(map ++ $ _, @ "); s/1/ /g and print; print $/
------------------------------
Date: Wed, 12 Nov 2003 10:10:04 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: ppm error
Message-Id: <bos4p2$5ib@netnews.hinet.net>
when i reinstall activestate perl v5.8
and use command ppm to do some thing
i got
Error: neither
'HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PPM//InstallLocation' no
r 'HKEY_CURRENT_USER/SOFTWARE/ActiveState/PPM//InstallLocation' found in
registr
y at D:\Perl\bin\PPM.bat line 29.
------------------------------
Date: Wed, 12 Nov 2003 04:27:17 GMT
From: "Voitec" <voitec@zzzzzzzzz.com>
Subject: Re: print statement spanning multiple lines
Message-Id: <FEisb.7553$aT.2479@news-server.bigpond.net.au>
*snip*
> No, I believe the first example is what the OP wanted. He wants to
> indent the code, not the output.
>
> Thus;
>
> print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
> "bbbbbbbbbbbbbbbbbbbbbb";
>
> would indeed seem to do the trick.
>
> Z
Thanks. I guess I could have been a little clearer, sorry.
But the intention was to indent the code not the output so the comma
character is exactly what I was looking for.
Thanks to all for the suggestions :c)
Voitec
------------------------------
Date: Wed, 12 Nov 2003 01:26:33 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problems with Sendmail
Message-Id: <borv30$1h0ac8$1@ID-184292.news.uni-berlin.de>
Brad Baxter wrote:
> On Tue, 11 Nov 2003, Gunnar Hjalmarsson wrote:
>> Phantom_guitarist wrote:
>>> If any one knows of any issues that I am maybe overlooking your
>>> help would be very much appreciated.
>>
>> open(MAIL,'|$mailprog -t')|| &error("Cant locate mail program");
>> -------------------------^^^
>
> Also:
>
> open(MAIL,"|$mailprog -t")|| &error("Cant locate mail program");
Yes, I overlooked that there was single quotes instead of double
quotes. Thanks for pointing it out.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 11 Nov 2003 18:17:32 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: simplify this if loop
Message-Id: <Pine.SGI.3.96.1031111181612.120233C-100000@vcmr-64.server.rpi.edu>
On 11 Nov 2003, Roy Johnson wrote:
> for my $i ( $m-1..$#data ) {
> print $i+1, " ", $data[$i], " ", avg( @data[ $i - ( $m - 1 ) .. $i ]), "\n";
> }
And then:
for my $i (--$m .. $#data) {
print $i+1, " $data[$i] ", avg(@data[$i - $m .. $i]), "\n";
}
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Wed, 12 Nov 2003 02:49:50 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: simplify this if loop
Message-Id: <pan.2003.11.11.23.30.37.351036@aursand.no>
On Tue, 11 Nov 2003 09:18:22 +0100, Tore Aursand wrote:
>> my $m = 2;
>> sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
>> for ( my $i = $m - 1; my @group = @data[ $i - ( $m - 1 ) .. $i ], $i < @data; ++$i ) {
>> print $i + 1, " ", $group[ -1 ], " ", avg( @group ), "\n";
>> }
> Damn. It's fast, too! :-) Seems like it's 26% faster than "my" method,
> which in turn was 34% faster than the OP's method.
Luckily, I was wrong. :-) Caught myself in commenting out the line which
prints out the result, and that line is calling the avg() subroutine. *g*
So. The method above is _not_ faster. The OP wanted a cleaner _and_ a
faster method, remember? Still nice code above, though.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Wed, 12 Nov 2003 02:56:51 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: simplify this if loop
Message-Id: <pan.2003.11.12.01.56.48.854803@aursand.no>
On Tue, 11 Nov 2003 18:17:32 -0500, Jeff 'japhy' Pinyan wrote:
> And then:
>
> for my $i (--$m .. $#data) {
> print $i+1, " $data[$i] ", avg(@data[$i - $m .. $i]), "\n";
> }
Still, it's quite slower than the previous suggested method;
#!/usr/bin/perl
#
use strict;
use warnings;
use Benchmark qw( cmpthese );
my @data = qw( 1 2 3 4 5 6 7 8 9 );
cmpthese(30_000, {
'Method #1' => \&method_1,
'Method #2' => \&method_2,
});
sub method_1 {
my ($i, $m) = (0, 2);
for my $idx ( 0 .. (@data - $m) ) {
my $avg;
my $to = ( $idx + $m ) - 1;
$avg += $_ for ( @data[$idx .. $to] );
$avg /= $m;
#print $idx + $m . ' ' . $data[$idx + 1] . ' ' . $avg . "\n";
}
}
sub method_2 {
my $m = 2;
sub avg { my $tot; $tot += $_ for @_; $tot / @_ }
for my $i (--$m .. $#data) {
my $avg = avg( @data[$i - $m .. $i] );
#print $i+1, " $data[$i] ", avg(@data[$i - $m .. $i]), "\n";
}
}
Gives me these results on my AMD Athlon 750 MHz running Red Hat 9.0
(2.4.20) with Perl 5.8.2:
Rate Method #2 Method #1
Method #2 10989/s -- -27%
Method #1 15152/s 38% --
Gotta love benchmarking, though. :-)
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Wed, 12 Nov 2003 04:45:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: simplify this if loop
Message-Id: <x7smkuw5xy.fsf@mail.sysarch.com>
>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:
TA> Luckily, I was wrong. :-) Caught myself in commenting out the line
shouldn't that be commentating out the line? :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 11 Nov 2003 23:29:36 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: small dbi help
Message-Id: <8Gisb.71620$861.2102218@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
debraj wrote:
> Hi,
>
> Just wanted a small help. I have a perl script (OS:Linux) in which I
> am repeatedly evoking sqlplus, for connecting to the database(Oracle)
> because the select statement changes often(about 500 times) and its
> taking a lot of time. Now, I know this much that DBI helps in
> connecting to the database and can do SQL queries but how much will it
> improve the performance?
The answer is yes, it will definately improve the performance. At a bare minimum it will illiminate
the forking (very expensive) and the pipes between your process and sqlplus.
> The query is very simple only that the select
> clause changes.
>
> OR is there any better way to do it?
Yes - use DBI and DBD::Oracle
>
> Example: select * from emp where emp_no=****;
> The above is the query and in a loop the emp_no changes about 500
> times.
1. Make sure the emp_no column is indexed
2. See perldoc DBI, especially the section on "placeholders" - it will allow you to prepare the SQL
statement once and execute it multiple times with different values
3. Try "where emp_no in ('x', 'y', 'z', . . .)" - I don't know how efficient oracle is with this
type of query, but it might be worth a shot while you're benchmarking.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/sbc1eS99pGMif6wRAjzqAJ9bykpxVKAxVbdw8K32q3aQhLe9KwCggL91
+3o3K5PmDASrrW2/+44FKaE=
=9J9e
-----END PGP SIGNATURE-----
------------------------------
Date: 11 Nov 2003 18:36:44 -0800
From: ifiaz@hotmail.com (ifiaz)
Subject: Re: Sorting a multi-dimensional hash
Message-Id: <93c1947c.0311111836.368640a6@posting.google.com>
> No. What follows is pseudo-code. You improve your chances of getting
> useful replies when you post runnable code.
>
> > $Fnd{$Lic}{$cF}{mFullScanTime} = $mFullScanTime; #20030317090000 (Sample data)
> 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.
Thanks for pointing out. I will follow accordingly.
> You mean, sorting the hash *keys*.
I think by value. i.e. $Fnd{$Lic}{$cF}{mFullScanTime} = "20030317090000"
so I need to sort by the scan times on the right hand side of equal sign.
> > 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;
>
One typical example is
$Fnd{"00123"}{"1"}{mFullScanTime} = ...
$Fnd{"00123"}{"2"}{mFullScanTime} = ...
$Fnd{"00123"}{"3"}{mFullScanTime} = ...
$Fnd{"00123"}{"4"}{mFullScanTime} = ...
$Fnd{"12345"}{"1"}{mFullScanTime} = ...
$Fnd{"12346"}{"1"}{mFullScanTime} = ...
Since, $cF is a variable that changes everytime, I don't know how
to pass the $cF inside the sort routine. So, I need to know how
I can pass the $cF inside the sort routine, so that the sort routine
can refer to each and every mFullScanTime of $Lic and $cF put
together and return the sorted result.
I am completely new to this. If my question is not phrased correctly
above, I apologise.
------------------------------
Date: Tue, 11 Nov 2003 23:18:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Style question: map versus foreach
Message-Id: <borqnu$2pb$1@wisteria.csv.warwick.ac.uk>
Steve Grazzini <grazz@pobox.com> wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote:
> > Darin McBride <dmcbride@naboo.to.org.no.spam.for.me> wrote:
> >> Abigail wrote:
> >> > map in void context has never returned anything. No function in void
> >> > context has ever returned anything.
> >>
> >> sub foo()
> >> {
> >> return qw(this is a small array);
> >> }
> >>
> >> foo();
> >>
> >> And you're saying something in void context doesn't return anything?
> >
> > my $x = foo();
> >
> > And you're saying that this returns a list?
>
> I can't answer for Darin, but I think it does return a list.
>
> % perl -Dts -le 'sub f { "one", "two", "three" } f()'
<snip>
> This is void context, of course, and commas instead of qw(), but it
> works just like your example. The subroutine returns a list and a
> list in void or scalar context evaluates [pp.c: pp_list] to its last
> element.
I'm afraid I can't really follow that: which line is supposed to be
'the return value'?; but it makes no difference anyway. We are talking
about the conceptual return value, ie. about what Perl returns; if
perl in fact builds a list only to discard all but the last element
this is a bug, like the one in map was.
> I suppose it would also be possible to say that the subroutine returns
> the *result* of evaluating a list in void context. And likewise, that
> this one returns the result of evaluating an array in scalar context:
>
> % perl -Ds -le 'sub f { @INC } scalar f()'
>
> But I'd rather say that this returns an array.
But that would be quite wrong. In Perl, a function *cannot* return an
array, only a list if in list context or a scalar if in scalar. For
instance, what about this
% perl -le'sub f { caller } print scalar f'
? Would you say this returns 'the caller function', which is then
evaluated in scalar context? It certainly doesn't return a list:
according to you, the result of 'evaluating a list in scalar context'
is its last element, which is not what is returned.
In fact, as Randal keeps saying, there is *no such thing* as 'a list
in scalar context'.
> The more common explanation -- that the comma operator in scalar
> context works "like it does in C", i.e. evaluating and discarding its
> LHS and returning its RHS -- also fits the result, but it's not quite
> as accurate.
OK, the comma operator in scalar context builds a list and then
discards all but the last element. Just out of interest (my perl isn't
built with DEBUGGING), what does this do
% perl -Dts -le'scalar (1, 2, 3)'
? Is the whole list built, or are the values discarded as it goes
along?
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Wed, 12 Nov 2003 03:47:05 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Style question: map versus foreach
Message-Id: <Z2isb.14053$hB5.13295@nwrdny02.gnilink.net>
Ben Morrow <usenet@morrow.me.uk> wrote:
> Steve Grazzini <grazz@pobox.com> wrote:
>> I suppose it would also be possible to say that the subroutine
>> returns the *result* of evaluating a list in void context. And
>> likewise, that this one returns the result of evaluating an array
>> in scalar context:
>>
>> % perl -Ds -le 'sub f { @INC } scalar f()'
>>
>> But I'd rather say that this returns an array.
>
> But that would be quite wrong. In Perl, a function *cannot* return
> an array, only a list if in list context or a scalar if in scalar.
That's true, of course. I think I got it right earlier: f() returns
the result of evaluating @INC in scalar context when it's called in
scalar context, and the result of evaluating @INC in list context when
it's called in list context. Condensing this to "f() returns @INC" is
less precise, but maybe it's close enough to be useful, assuming that
we all know you can't *really* return an array from a subroutine and
do "push foo(), $elt" or whatever.
> For instance, what about this
>
> % perl -le'sub f { caller } print scalar f'
>
> ? Would you say this returns 'the caller function', which is then
> evaluated in scalar context?
Well, no. That would be silly. :-)
> It certainly doesn't return a list:
It certainly doesn't!
> according to you, the result of 'evaluating a list in scalar context'
> is its last element, which is not what is returned.
That's because (as you must know) caller() doesn't return a list in
scalar context. Since there's no list, this doesn't have anything
to do with the behavior of a list in scalar context.
> In fact, as Randal keeps saying, there is *no such thing* as 'a list
> in scalar context'.
That's a simplification, too. It's probably the best thing to tell
people who are trying to figure out what a built-in does in scalar
context based on what it does in list context. But it's not the whole
story -- perldata explains this more accurately:
If you evaluate an array in scalar context, it returns the length
of the array. (Note that this is not true of lists, which return
the last value, like the C comma operator, nor of built-in functions,
which return whatever they feel like returning.)
> OK, the comma operator in scalar context builds a list and then
> discards all but the last element. Just out of interest (my perl
> isn't built with DEBUGGING), what does this do
>
> % perl -Dts -le'scalar (1, 2, 3)'
>
> ? Is the whole list built, or are the values discarded as it goes
> along?
Neither. :-)
Here the compiler knows that the potential list is in scalar context,
and it puts the "1" and "2" in void context, since they're just going
to be discarded. Constants in void context can be optimized away
(i.e. discarded at compile-time) and that's what happens here.
This is the zen-like "There Is No List..." scenario from the FAQ:
As a side note, there's no such thing as a list in scalar con-
text. When you say
$scalar = (2, 5, 7, 9);
you're using the comma operator in scalar context, so it uses
the scalar comma operator. There never was a list there at
all! This causes the last value to be returned: 9.
And perlfunc:
A named array in scalar context is quite different from what would
at first glance appear to be a list in scalar context. You can't
get a list like "(1,2,3)" into being in scalar context, because the
compiler knows the context at compile time. It would generate the
scalar comma operator there, not the list construction version of
the comma. That means it was never a list to start with.
And they're correct, more or less, for the examples they give. But the
bit about the "scalar comma operator" seems to be misguided. If any of
the earlier elements of those lists were variables, a list really would
be created at runtime.
% perl -Dts -le 'scalar($$, 42, 43)'
EXECUTING...
=>
(-e:0) enter
=>
(-e:0) nextstate
=>
(-e:1) pushmark
=> *
Here's the list (note the missing "42").
(-e:1) gvsv(main::$)
=> * IV(14592)
(-e:1) const(IV(43))
=> * IV(14592) IV(43)
Here's the op that evaluates the list in scalar context.
(-e:1) list
And here's the result.
=> IV(43)
(-e:1) leave
--
Steve
------------------------------
Date: Wed, 12 Nov 2003 04:45:50 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Style question: map versus foreach
Message-Id: <bosdtu$an0$1@wisteria.csv.warwick.ac.uk>
Steve Grazzini <grazz@pobox.com> wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote:
> > Steve Grazzini <grazz@pobox.com> wrote:
> >> I suppose it would also be possible to say that the subroutine
> >> returns the *result* of evaluating a list in void context. And
> >> likewise, that this one returns the result of evaluating an array
> >> in scalar context:
> >>
> >> % perl -Ds -le 'sub f { @INC } scalar f()'
> >>
> >> But I'd rather say that this returns an array.
> >
> > But that would be quite wrong. In Perl, a function *cannot* return
> > an array, only a list if in list context or a scalar if in scalar.
>
> That's true, of course. I think I got it right earlier: f() returns
> the result of evaluating @INC in scalar context when it's called in
> scalar context, and the result of evaluating @INC in list context when
> it's called in list context. Condensing this to "f() returns @INC" is
> less precise, but maybe it's close enough to be useful, assuming that
> we all know you can't *really* return an array from a subroutine and
> do "push foo(), $elt" or whatever.
OK.
>
> > For instance, what about this
> >
> > % perl -le'sub f { caller } print scalar f'
> >
> > ? Would you say this returns 'the caller function', which is then
> > evaluated in scalar context?
>
> Well, no. That would be silly. :-)
Well.... I don't quite see as it's sillier than saying the sub above
returns @INC. This returns the result of evaluating caller() in list
context when in list context, and the result of evaluating caller() in
scalar context when in scalar context.
Both are simply a constructive use of sloppy language.
> > according to you, the result of 'evaluating a list in scalar context'
> > is its last element, which is not what is returned.
>
> That's because (as you must know) caller() doesn't return a list in
> scalar context. Since there's no list, this doesn't have anything
> to do with the behavior of a list in scalar context.
But my point was that neither was there a list in the @INC
case. '@INC' doesn't return a list in scalar context either: it
returns the number of elements it contains.
And, to get back to the original argument :), neither does map()
return a list in void context. It returns nothing.
<snip pods about lists and scalar ,>
> But the bit about the "scalar comma operator" seems to be misguided.
> If any of the earlier elements of those lists were variables, a list
> really would be created at runtime.
>
> % perl -Dts -le 'scalar($$, 42, 43)'
>
> EXECUTING...
>
> =>
> (-e:0) enter
> =>
> (-e:0) nextstate
> =>
> (-e:1) pushmark
> => *
>
> Here's the list (note the missing "42").
>
> (-e:1) gvsv(main::$)
> => * IV(14592)
> (-e:1) const(IV(43))
> => * IV(14592) IV(43)
>
> Here's the op that evaluates the list in scalar context.
>
> (-e:1) list
>
> And here's the result.
>
> => IV(43)
> (-e:1) leave
Interesting.....
So a better statement of all this is perhaps:
There is no 'scalar comma operator'. The comma operator builds a
list. A list evaluated in scalar context evaluates each of its members
in void context; except the last which is evaluated in scalar context
and returned. This may be optimized away at compile time (as usual).
Hmmm. This applies at complie time, not at run time. In
sub c {...}
my $x = (c, c);
the elements of the list are 'call sub c', rather than the results of
those calls; rather like returning 'the caller function' above :).
Very functional, and not at all suitable as a way of explaining it to
people :).
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: 11 Nov 2003 16:14:31 -0800
From: groups@mironloeb.org (Sophie Miron)
Subject: Re: went to 5.8.1 and now I can't access object data dynamically
Message-Id: <7f1a1d9f.0311111614.432e7d74@posting.google.com>
Thanks Jay. That was exactly the problem.
tiltonj@erols.com (Jay Tilton) wrote:
> So one of the methods is returning undef when you expect it to return an
> object.
[snip]
> I wonder what the reason was for making that change to Class::Struct.
It says that it caused problems when the included class didn't have a
"new" method. Still, that's rare. They should have changed it to
work both ways, IMHO. Now the example in the perltoot tutorial is
incorrect.
> Backpedal to an older Class::Struct version, or have your code
> initialized the nested objects itself.
Yes. What I did was add an initialize() method and then called it
every time I called new() Here's the code for anyone who has a
similar problem and finds this thread:
sub initialize {
my $self = shift;
foreach my $station (@stations ) {
$self->$station(Station->new());
$self->$station->initialize();
}
}
> : Is what I'm doing using symbolic references?
>
> Technically, yes, but Perl resolves method names symbolically anyway.
> Pay no attention to that man behind the curtain.
Noone ever pays attention to him until things go wrong...
Thanks again.
Sophie Miron ( smiron..at..mironloeb.org )
------------------------------
Date: Tue, 11 Nov 2003 23:31:56 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Win32::OLE and CDO Message Filters
Message-Id: <3fb16cd8.4933820@news.erols.com>
"Shaun Clowes" <delius@no.spam.for.me.progsoc.org> wrote:
: I'm having some trouble trying to set the properites of the MessageFilter
: (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_
: olemsg_messagefilter_object.asp) object in a CDO messages collection using
: Win32::OLE. Nothing I do seems to be able to change any of the properties.
: print "We have a folder of type " . Win32::OLE->QueryObjectType($Folder) .
: "\n";
: print "The filter is of type " .
: Win32::OLE->QueryObjectType($Folder->Messages->Filter) . "\n";
: print "Currently filtering for size " . $Folder->Messages->Filter->Size .
: "\n";
: $Folder->{"Messages"}->{"Filter"}->{"Size"} = 12;
: print "Currently filtering for size " . $Folder->Messages->Filter->Size .
: "\n";
: $Folder->Messages->Filter->LetProperty('Size', 12);
: print "Currently filtering for size " . $Folder->Messages->Filter->Size .
: "\n";
: $Folder->Messages->Filter->SetProperty('Size', 12);
: print "Currently filtering for size " . $Folder->Messages->Filter->Size .
: "\n";
[snip]
: The output with -w:
:
: The filter is of type MessageFilter
: OLE exception from "Collaboration Data Objects":
:
: [Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]
:
: Win32::OLE(0.17) error 0x8004010f
: in METHOD/PROPERTYGET "Size" at AssignPrNumbers.pl line 65
: Use of uninitialized value in concatenation (.) or string at
: AssignPrNumbers.pl
: line 65.
[truncated]
You have three different techniques for assigning a value to the
object's property. OLE is not complaining about any of them.
You have one technique for looking at the property's value. Each time
that technique is used, OLE complains about a missing "Size" method, and
perl complains about printing uninitialized values.
Reasonably, the problem is not that you cannot assign values, but that
you are using the wrong syntax for looking at them.
A look at the MessageFilter object docs says "Size" is a property of the
object, not a method.
print $Folder->Messages->Filter->{Size};
------------------------------
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 5784
***************************************