[18153] in Perl-Users-Digest
Perl-Users Digest, Issue: 321 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 20 14:05:41 2001
Date: Tue, 20 Feb 2001 11: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)
Message-Id: <982695910-v10-i321@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 20 Feb 2001 Volume: 10 Number: 321
Today's topics:
Re: (OFF TOPIC) Re: This is driving me nuts and I need <mischief@velma.motion.net>
Re: Array length <peb@bms.umist.ac.uk>
Re: Array length <bart.lateur@skynet.be>
Re: Array length (Peter J. Acklam)
Can't get a value from microsoft access using win32::OD <mortarandpestle@hotmail.com>
Cannot write quatation marks to html... <fabian@markisspecialisten.com>
Re: Cannot write quatation marks to html... <bmb@ginger.libs.uga.edu>
Re: Cannot write quatation marks to html... (Jon Bell)
covert "=?ISO-8859-1?Q?=F8Y=22?=" (embeded hex) to F89F <leinfidel@netscape.net>
Re: Examples of Using HTML Parser (Randal L. Schwartz)
How to print a...? <gop@gop.com>
Re: IT Security Game <mellissa@intrapromote.com>
Re: IT Security Game <lmoran@wtsg.com>
MacPerl help for a newbie <michael.beardsley@dartmouth.edu>
Re: perl irc channel <kperrier@blkbox.com>
Re: perl irc channel (Randal L. Schwartz)
Re: Specifying the length of regular expression (Abigail)
Re: Specifying the length of regular expression (Greg Bacon)
Re: striping HTML <gerard@NOSPAMlanois.com>
Re: Well, looks like ANOTHER bug in perl-5.6.0 <joe+usenet@sunstarsys.com>
Re: Well, looks like ANOTHER bug in perl-5.6.0 (Abigail)
Re: What's wrong with this script? <ge@do.com>
Win32::OLE Excel Chart sizes <davemci@americasm01.nt.com>
Re: Win32::OLE Excel Chart sizes <davemci@americasm01.nt.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Feb 2001 16:53:19 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: (OFF TOPIC) Re: This is driving me nuts and I need a guru
Message-Id: <t9587vmunpk164@corp.supernews.com>
Frank Miller <no@email.com> wrote:
>>"Abigail" <abigail@foad.org> wrote in message
> news:slrn990fvd.ph4.abigail@tsathoggua.rlyeh.net...
>> If you manage to remain oblivous of the FAQ doing what Frank claimed to
>> do, what good is it to answer his questions? He'll probably miss the
>> answers anyway.
>>
> I think responses like this pretty much prove my point.
I think responses such as this pretty much prove you need to beg, borrow,
or finance a clue.
You make mention (elsewhere in the thread) of how forgiving nontechnical
fora are compared to technical fora. I'm sorry, but I fail to grasp how
precise communication and lack of repitititition would help as much in
alt.flame, alt.mp3.1980s, or alt.binaries.pictures.erotica.redheads as
in a forum where we try to exchange technical information. Of course
nontechnical fora are more forgiving about things such as reading FAQs,
posting in incorrect order, and other things. The value of the
information, time, and desired results are much more valuable when the
people reading the forum are doing so for their work. Why would it be any
other way?
Chris
--
Christopher E. Stith
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: Tue, 20 Feb 2001 10:37:30 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Array length
Message-Id: <3A9248EA.1380DB61@bms.umist.ac.uk>
> Although this seems like a simple task I couldn't find how to do it in the
> FAQ. Does anyone know how/if it is possible to get the length of an array?
my $array_length = @array;
or $#array returns the last index of the array (i.e. length - 1)
Paul
------------------------------
Date: Tue, 20 Feb 2001 17:40:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Array length
Message-Id: <kta59t47t2eh9f6283ac1d9c3a7r2pm7ra@4ax.com>
wavetable wrote:
>Although this seems like a simple task I couldn't find how to do it in the
>FAQ. Does anyone know how/if it is possible to get the length of an array?
Maybe because most Perl people don't call it a "length". But anyway, for
an array @a, $#a will give you the index of the last array item, and
scalar @a (or just plain @a in a scalar context) will giove you the
count of array items. The first item commonly has index 0 (it is that
way by default, and you are begged not to change that without a very
good reason), in which case $#a is 1 less than scalar @a.
--
Bart.
------------------------------
Date: 20 Feb 2001 19:26:39 +0100
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: Array length
Message-Id: <wk3dd9jl3t.fsf@math.uio.no>
Paul Boardman <peb@bms.umist.ac.uk> writes:
> > Although this seems like a simple task I couldn't find how to
> > do it in the FAQ. Does anyone know how/if it is possible to
> > get the length of an array?
>
> my $array_length = @array;
> or $#array returns the last index of the array (i.e. length - 1)
$#array = @array - 1 + $[;
but $[ is virtually always 0.
Peter
--
sub int2roman{@x=split//,sprintf'%04d',shift;@r=('','I','V','X','L','C','D'
,'M');@p=([],[1],[1,1],[1,1,1],[1,2],[2],[2,1],[2,1,1],[2,1,1,1],[1,3],[3])
;join'',@r[map($_+6,@{$p[$x[0]]}),map($_+4,@{$p[$x[1]]}),map($_+2,@{$p[$x[2
]]}),map($_+0,@{$p[$x[3]]})];}print "@{[map{int2roman($_)}@ARGV]}\n";#JAPH!
------------------------------
Date: Tue, 20 Feb 2001 16:39:27 GMT
From: "Denis Hudon" <mortarandpestle@hotmail.com>
Subject: Can't get a value from microsoft access using win32::ODBC
Message-Id: <35xk6.98922$v.7951807@typhoon.nyroc.rr.com>
Below is a Perl script and the HTML code it generates. For some reason,
$Status remains undefined, generating an empty set of HTML paragraph tags at
line 15. I know that I'm connecting to the database correctly, because the
other two pieces of data come through alright. In my access database, I am
sure that I have a field in the table 'Users' identified as 'Status,' using
the same spelling and capitalization as the code below. I know that there
is a value in the cell specifically referred to; it contains the text object
'User.' So why is $Status not getting defined in line 7? I've tried using
different variable names ($MakeItWork instead of $Status) and field names
(Please_Work instead of Status), so there's nothing special about the term
'Status.' I've even tried independently retrieving the single piece of data
using a separate sql(), fetchrow(), param() sequence of calls. Please,
somebody help!! I would appreciate it VERY VERY much.
{{
1 $DataInput = new Win32::ODBC("NorthwayExchange");
2 $DataInput->Sql("SELECT First_Name, Last_Name, Status FROM Users WHERE
UserID = 'Hudon1'");
3 $DataInput->FetchRow();
4 %AccessPageData = $DataInput->DataHash("First_Name", "Last_Name",
"Status");
5 $FirstName = $AccessPageData {First_Name};
6 $LastName = $AccessPageData {Last_Name};
7 $Status = $AccessPageData {Status};
8 $DataInput->Close();
9
10 $AccessPage = new CGI;
11 print $AccessPage->header;
12 print $AccessPage->start_html(-title=>'Northway Exchange Access Page');
13 print $AccessPage->p($FirstName);
14 print $AccessPage->p($LastName);
15 print $AccessPage->p($Status);
16 print $AccessPage->end_html;
17 exit;
}}
{{
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<title>Northway Exchange Access Page</title>
</head>
<body>
<p>Denis</p>
<p>Hudon</p>
<p></p>
</body>
</html>
}}
------------------------------
Date: Tue, 20 Feb 2001 16:52:34 GMT
From: "Fabian Thorbjörnsson" <fabian@markisspecialisten.com>
Subject: Cannot write quatation marks to html...
Message-Id: <mhxk6.18708$AH6.2555277@newsc.telia.net>
I'm running a perl script and I try to make i write "800" to an html-page.
The problem is that the script doesn't allow me to write more than 2
quatation marks in a print command.
Can I get arround this problem?
--
MVH
Markisspeciaisten
Fabian Thorbjörnsson
08-252500
------------------------------
Date: Tue, 20 Feb 2001 12:03:34 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Cannot write quatation marks to html...
Message-Id: <Pine.A41.4.21.0102201200110.9562-100000@ginger.libs.uga.edu>
On Tue, 20 Feb 2001, Fabian Thorbj=F6rnsson wrote:
>=20
> I'm running a perl script and I try to make i write "800" to an html-page=
=2E
> The problem is that the script doesn't allow me to write more than 2
> quatation marks in a print command.
> Can I get arround this problem?
You might read about "Quote and Quote-like Operators" in the perlop page
(i.e., perldoc perlop). You can also escape your quotes with \ (i.e.,
"\"800\"")
Brad
------------------------------
Date: Tue, 20 Feb 2001 17:00:50 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Cannot write quatation marks to html...
Message-Id: <G92F9E.5tt@presby.edu>
In article <mhxk6.18708$AH6.2555277@newsc.telia.net>,
Fabian Thorbjörnsson <fabian@markisspecialisten.com> wrote:
>
>I'm running a perl script and I try to make i write "800" to an html-page.
If you want to print a " literally, you must "escape" it with a '\'. For
example:
print "Call this \"800\" number now!\n";
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
------------------------------
Date: Tue, 20 Feb 2001 17:38:38 GMT
From: Ty <leinfidel@netscape.net>
Subject: covert "=?ISO-8859-1?Q?=F8Y=22?=" (embeded hex) to F89F how?
Message-Id: <3A92AB8C.4040909@netscape.net>
Hello all,
I using regular expressions to deal with some documents that have a
number of true embeded hex codes such as "øY"". I have no problem
finding them using \x, but I need to replace them with their true hex code.
For the life of me I can find a way to figure out the value of øY" in
hex, within a script, anyone know how?
The only reason I know it's F89F is I dropped it in a hex editor...
thank you!
------------------------------
Date: 20 Feb 2001 08:39:24 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Examples of Using HTML Parser
Message-Id: <m1d7cdtikj.fsf@halfdome.holdit.com>
>>>>> "Gabriel" == Gabriel Richards <grichards@endertechnology.com> writes:
Gabriel> I don't understand HTML::Parser, in particular, from the docs I don't know
Gabriel> how to do this:
Gabriel> "In order to make the parser do anything interesting, you must make a
Gabriel> subclass where you override one or more of the following methods as
Gabriel> appropriate:"
That's the *old* HTML::Parser. The modern one requires no such thing,
and was rewritten in C for a 5x speed improvement. Please upgrade to
something released within the past year or so.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 20 Feb 2001 18:47:51 +0200
From: "Gop" <gop@gop.com>
Subject: How to print a...?
Message-Id: <96u6um$mk9$1@news.kolumbus.fi>
What I would like to do is print a "<" in a label with the radio_group
function in a cgi script (so it would output it as a < instead of <). I
have tried everything I can think of so now I'm asking the helpful group...
------------------------------
Date: Tue, 20 Feb 2001 08:57:15 -0800
From: "Mellissa" <mellissa@intrapromote.com>
Subject: Re: IT Security Game
Message-Id: <3a929fed$1@new01.bendcable.com>
So did you get the game? I need help on level 5.
http://www.verado.com/forms/get_verado_game_1.shtml
>Gosh, that does sound like fun.
>P.S. You misspelled 'Melissa'. Hope this helps.
>>The IT Security Game, a two-dimensional, multi-level game that puts
>>the player in the place of an overworked, stressed IT person.
Thanks for your help! But....... I think I know how to spell my own
name (I've had it my whole life.)
-MeLLissa
------------------------------
Date: Tue, 20 Feb 2001 12:16:01 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: IT Security Game
Message-Id: <eg959tohnr0fcnu71hcikn2slvojbq7ca0@4ax.com>
On Tue, 20 Feb 2001 08:57:15 -0800, "Mellissa"
<mellissa@intrapromote.com> wrote wonderful things about sparkplugs:
>So did you get the game? I need help on level 5.
>
>http://www.verado.com/forms/get_verado_game_1.shtml
>
>>Gosh, that does sound like fun.
>
>>P.S. You misspelled 'Melissa'. Hope this helps.
>
>>>The IT Security Game, a two-dimensional, multi-level game that puts
>>>the player in the place of an overworked, stressed IT person.
>
>Thanks for your help! But....... I think I know how to spell my own
>name (I've had it my whole life.)
>
>-MeLLissa
Make the game more like UT and less like Space Invaders. My wife
misspells her name too. Uses a "Y" where everyone else uses an "I"
and wonders why her name gets misspelled all the time.
>
>
>
>
>
>
>
--
"> thanks in advance !!!
If you are going to do anything 'in advance' it should be RTFM."
--swiped from a nobull clp.misc post
Lou Moran <lmoran@wtsg.com>
------------------------------
Date: Tue, 20 Feb 2001 12:58:58 -0500
From: mbb <michael.beardsley@dartmouth.edu>
Subject: MacPerl help for a newbie
Message-Id: <B6B81A92.1C81%michael.beardsley@dartmouth.edu>
I have a number of folders containing *.wk1 files (old Lotus 123 format)
that I need to convert to MS Excel *.xls format.
All of the files are named some string of 5 numbers and then the ".wk1"
Using AppleScript I've managed to change the File Type and Creator Type to
MS Excel and Excel happily opens up the files with no complaints. However,
since I don't really know what I'm doing, I can't figure out how to ask it
to rename all the file's last 3 characters to "xls". this step is important
for compatibility with Windows machines.
I really don't know the first step to using Perl, but it's my understanding
that this sort of problem is exactly the kind of thing it could handle.
There are almost 400 files and I'd love to figure out how to automate this.
TIA for any pointers!
Mike
------------------------------
Date: 20 Feb 2001 10:37:48 -0600
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: perl irc channel
Message-Id: <83150CDA70917CEB.40895F0014DE9838.C9E6DC3FD290F24D@lp.airnews.net>
Jonathan Feinberg <jdf@pobox.com> writes:
> AvA <a.v.a@home.nl> writes:
>
> > lol randal, somehow i doubt that anyone would fire you
>
> You would be *amazed* at what Randal's "employers" might do.
Yeah, just ask Intel....
Kent
--
work hard, save aggressively, invest well and get the hell out
------------------------------
Date: 20 Feb 2001 09:12:16 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perl irc channel
Message-Id: <m166i5th1r.fsf@halfdome.holdit.com>
>>>>> "Kent" == Kent Perrier <kperrier@blkbox.com> writes:
Kent> Jonathan Feinberg <jdf@pobox.com> writes:
>> AvA <a.v.a@home.nl> writes:
>>
>> > lol randal, somehow i doubt that anyone would fire you
>>
>> You would be *amazed* at what Randal's "employers" might do.
Kent> Yeah, just ask Intel....
Well, there's an old saying (I think it's old, anyway) that if
you have to explain a joke, you lose. :)
But because there might be some mis-firing memes out of this thread
now, I have to clear this up.
Yes, I'm my own boss, sorta. I'm the top of the foodchain at
Stonehenge (both in hierarchy, and ownership), so it's not likely that
Stonehenge would "fire" me. But my company has contracts with many
other companies to provide products and services, so in that sense, my
"boss" would indeed fire me. I'm finding it hard enough just
wandering through #perl on one of the nets from time to time.
But the reason for this post is I can't let stand a bit of
misinformation even as a joke... I was never an *employee* of Intel.
Just a contractor. I'm sensitive about that because the ongoing legal
case makes that distinction a very necessary part of my defense.
And for those that don't get this post or the two parent articles,
please go read http://www.lightlink.com/fors/ et seq, for details
about my ongoing legal case.
Sorry to break the comedy pacing here, but you touched a sensitive
area where I can't afford miscommunications.
We now return you to your regularly scheduled bickerings... :-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 20 Feb 2001 17:08:17 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Specifying the length of regular expression
Message-Id: <slrn995941.ii5.abigail@tsathoggua.rlyeh.net>
Greg Bacon (gbacon@HiWAAY.net) wrote on MMDCCXXX September MCMXCIII in
<URL:news:t952ias50rh9ae@corp.supernews.com>:
&& In article <96saje$sne$1@news.netmar.com>,
&& <ianb@ot.com.au> wrote:
&&
&& : In article <t92nbv22nllh2e@corp.supernews.com>, Greg Bacon
&& : <gbacon@HiWAAY.net> writes:
&& :
&& : >When doesn't one have a choice?
&& :
&& : I provided a justification in my original post, but I'll try
&& : again. Sometimes you aren't writing the code, and you can only write
&& : the regex. For example, you are using a third-party module which
&& : requires you to specify a regex (or a file containing hundreds of regexes)
&& : for validation purposes, or for matching "interesting" log messages. You
&& : can't modify the module, so you just write an appropriate regex. These
&& : cases are rare, but they do happen.
&&
&& I know you objected to the distinction before, but matching strings of
&& the form A+B*C+ that are at least ten characters in length is an
&& academic problem. Introduce concatenations, character classes,
&& alternations, lookaheads, and so forth to severely complicate the
&& problem.
&&
&& I would argue the a module like the one you've described is
&& unnecessarily limited. Giving the user the option of providing a
&& coderef to check individual strings or filter lists of strings would
&& yield considerably more flexibility.
Yes, it would. But I doubt calling a code ref to each line of the monthly
weblogs of a busy server makes many happy users.
&& : The other variation on this theme is where you have written the code
&& : yourself, but you need to use many regexes (e.g. in a loop). On the
&& : odd occasion, you want to do something fancier, but you can't
&& : just change the logic since the extra code applies to only one case, and
&& : you don't want the overhead, bug potential or security concerns of
&& : allowing arbitrary expressions to be evaluated each time.
&&
&& Maybe I'm just unimaginative, but what's wrong with
&&
&& for (@strings) {
&& if (/$monster_regular_expression/o) { ... }
&& elsif (/^(A+B*C+)$/ && length($1) > 10) { ... }
&& }
&&
&& As for security concerns, there are patterns that can push the regular
&& expression matcher into exponential time, so, if you're concerned about
&& denial of service, you shouldn't allow untrusted users to specify
&& arbitrary regular expressions.
If you can anchor the regex, it's trivial:
/^(?=.{10})A+B*C+$/
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Tue, 20 Feb 2001 17:22:14 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Specifying the length of regular expression
Message-Id: <t959u6jc7c9od0@corp.supernews.com>
In article <slrn995941.ii5.abigail@tsathoggua.rlyeh.net>,
Abigail <abigail@foad.org> wrote:
: Greg Bacon (gbacon@HiWAAY.net) wrote on MMDCCXXX September MCMXCIII in
: <URL:news:t952ias50rh9ae@corp.supernews.com>:
:
: && I would argue the a module like the one you've described is
: && unnecessarily limited. Giving the user the option of providing a
: && coderef to check individual strings or filter lists of strings would
: && yield considerably more flexibility.
:
: Yes, it would. But I doubt calling a code ref to each line of the monthly
: weblogs of a busy server makes many happy users.
The users are happy when r3\/\/+ is happy, right? :-) I wrote "or
filter lists of strings" to answer the concern about calling a code
ref for each element in the list.
Greg
--
When going to visit the woman, do not forget the whip.
-- Nietzsche
------------------------------
Date: 20 Feb 2001 10:19:49 -0800
From: Gerard Lanois <gerard@NOSPAMlanois.com>
Subject: Re: striping HTML
Message-Id: <ubsrxi5dm.fsf@NOSPAMlanois.com>
me@nospam.com (Me) writes:
> Gerard Lanois <gerard@NOSPAMlanois.com> wrote in
> <u66iaw3dm.fsf@NOSPAMlanois.com>:
>
> >Funny, I was just writing a stripper earlier today.
>
> 2/16/19101
>
> Dear Savanna,
>
> Thank you very much for the wonderful lap dance...
...ba-dump-bump.
Guess I left myself wide open for that one.
Sorry for posting a followup to this thread - I would have
emailed you personally, but for an obviously invalid return
address.
With tears in my eyes from laughing so hard,
-Gerard
PS: Has any written a stripper name generator?
PPS: OK, here it is -
-------------snip----------------
#!/usr/bin/perl -w
# Pr0nstar/stripper stage name generator.
# Courtesy of "Lucy Sandra"'s Perl Page, http://www.lanois.com/perl/
use strict;
print "Enter the name of a pet you owned as a child:\n";
my $pet = <>;
chomp $pet;
$pet =~ s/\b(\w)/\U$1/g;
print "Enter the name of the first street you lived on:\n";
my $street = <>;
chomp $street;
$street =~ s/\b(\w)/\U$1/g;
print "Your name is: ", $pet, " ", $street, "\n";
------------------------------
Date: 20 Feb 2001 11:56:10 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Well, looks like ANOTHER bug in perl-5.6.0
Message-Id: <m3r90tcmz9.fsf@mumonkan.sunstarsys.com>
Alexey Morozov <morozov@novosoft.ru> writes:
> Well, consider the code below
[...]
> sub value3 { return bad_func('key3'); }
> sub value4 { my $r = bad_func('key4'); return $r; }
^^^^^^^^^^^^^^^^^^^^^
bad_func()'s return() is in a scalar context here.
> testfunc('key1',value1(),'key2',value2(),'key3',value3(),'key4',value4());
^^^^^^^^
bad_func()'s return() is in a list context here.
> It produces the following:
> Got 'key1'
> Got 'value1'
> Got 'key2'
> Got 'value2'
> Got 'key3'
> Got 'key4'
> Got undef
> ===================================================================
> Just wonder why I got NO VALUE AT ALL even undef for value3() call.
You needn't wonder, the manual would tell you why:
% perldoc -f return
=item return EXPR
=item return
Returns from a subroutine, C<eval()>, or C<do FILE> with the value
given in EXPR. Evaluation of EXPR may be in list, scalar, or void
context, depending on how the return value will be used, and the context
may vary from one execution to the next (see C<wantarray()>). If no EXPR
is given, returns an empty list in list context, the undefined value in
scalar context, and (of course) nothing at all in a void context.
(Note that in the absence of a explicit C<return>, a subroutine, eval,
or do FILE will automatically return the value of the last expression
evaluated.)
So after evaluating arguments,
> testfunc('key1',value1(),'key2',value2(),'key3',value3(),'key4',value4());
becomes
testfunc('key1','value1','key2','value2','key3',(),'key4',undef);
^^
Now from
% man perldata
...
The null list is represented by (). Interpolating it in a
list has no effect. Thus ((),(),()) is equivalent to ().
Similarly, interpolating an array with no elements is the
same as if no array had been interpolated at that point.
...
That empty list is dropped, so your testfunc's @_ array contains
@_ = ('key1','value1','key2','value2','key3','key4',undef);
> As you probably guessed I passed to the testfunc a hash initially and got
> a totally insane result. You'll be probably interested that bad_func
> was initially CGI->param() (w/ properly constructed CGI object of course).
> So we have a completely unclear behaviour in so simple and clear looking
> code. I'm totally disappointed.
People that don't understand that return values from subs can and will
behave differently in different contexts are bound to be surprised the
first time they observe it. It's only disappointing when they consider
it a bug when Perl doesn't DWIM as they would like, but don't bother to
look at the manpages for an explanation.
Of course, you could have avoided all this by reading perlfunc and using
return undef unless exists $hash{$key};
in your bad_func instead of
return unless $hash{$key};
HTH
--
Joe Schaefer "Heavier than air flying machines are impossible."
-- William Thomson (Lord Kelvin)
------------------------------
Date: 20 Feb 2001 17:15:10 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Well, looks like ANOTHER bug in perl-5.6.0
Message-Id: <slrn9959gu.ii5.abigail@tsathoggua.rlyeh.net>
Alexey Morozov (morozov@novosoft.ru) wrote on MMDCCXXX September MCMXCIII
in <URL:news:96u1v1$uv8$1@news.itfs.nsk.su>:
.. Well, consider the code below
..
.. ======================================================
.. #!/usr/bin/perl -w
..
.. use strict;
.. use diagnostics;
..
.. sub bad_func
.. {
.. my ($key) = @_;
.. my %hash = (
.. 'key1' => 'value1',
.. 'key2' => 'value2',
.. );
.. return unless $hash{$key};
.. return $hash{$key};
.. }
..
.. sub value1 { return bad_func('key1'); }
.. sub value2 { return bad_func('key2'); }
.. sub value3 { return bad_func('key3'); }
.. sub value4 { my $r = bad_func('key4'); return $r; }
..
.. testfunc('key1',value1(),'key2',value2(),'key3',value3(),'key4',value4());
..
.. sub testfunc
.. {
.. foreach my $elem (@_)
.. {
.. print "Got ".((defined $elem) ? "'$elem'" : 'undef')."\n";
.. }
.. }
.. ==================================================================
.. It produces the following:
.. Got 'key1'
.. Got 'value1'
.. Got 'key2'
.. Got 'value2'
.. Got 'key3'
.. Got 'key4'
.. Got undef
.. ===================================================================
.. Just wonder why I got NO VALUE AT ALL even undef for value3() call.
Not a bug.
Context.
value3() calls bad_func in list context, because it's in list context
itself. value4() calls bad_func in scalar context.
An argumentless return in list context returns the empty list, but
in scalar context, it returns undef. This is documented early in
"man perlsub".
Abigail
--
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
for (??;(??)x??;??)
{??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
------------------------------
Date: Tue, 20 Feb 2001 18:26:20 +0200
From: "Dan" <ge@do.com>
Subject: Re: What's wrong with this script?
Message-Id: <96u5ma$lb8$1@news.kolumbus.fi>
Hmm... I would suggest you would start reading the replies (at least the
replies by the same author as the original post) before replying something
like that. I admit it was a simple mistake but I'm used to write the
substring in another way and the output was right with the lines with just 2
characters so I didn't think of that.
------------------------------
Date: Tue, 20 Feb 2001 11:19:22 -0500
From: "Dave McIntyre" <davemci@americasm01.nt.com>
Subject: Win32::OLE Excel Chart sizes
Message-Id: <96u5bt$7f2$1@bcrkh13.ca.nortel.com>
I'm creating some charts in Excel using Win32::OLE, but I'm having
trouble setting the height and width properties. Here's the script:
use Win32::OLE qw(in valof with);
use Win32::OLE::Const 'Microsoft Excel';
use Warnings;
$Win32::OLE::Warn = 3;
my $Excel = Win32::OLE->new("Excel.Application");
$Excel->{Visible} = 1;
$Excel->{SheetsInNewWorkbook} = 1;
my $Book = $Excel->Workbooks->Add;
my $Sheet = $Book->Worksheets(1);
my $Range = $Sheet->Range("A1:G3");
$Sheet->Cells(1,1)->Font->{Bold} = "True"; # just a test
@data =(["day7", "day6", "day5", "day4", "day3", "day2", "day1"],
[80, 100, 120, 121, 89, 78, 68 ],
[88, 65, 75, 59, 85, 73, 61 ]);
$Range->{Value} = \@data;
my $Chart = $Excel->Charts->Add;
$Chart->SetSourceData({Source => $Range, PlotBy => xlRows});
$Chart->ApplyCustomType({ChartType => xlBuiltIn, TypeName => "Line - Column
on 2 Axes" });
with($Chart, HasLegend => 1,
HasTitle => 1);
$Chart->ChartTitle->{Text} = "Yield Graph";
$Chart->{HasDataTable}=1;
# this works
$Chart->ChartArea->Interior->{Pattern} = xlLightDown; #
# this doesn't
$Chart->ChartArea->{Height} = 400;
$Chart->ChartArea->{Width} = 600;
my $filename = "\\jan3.gif";
$Chart->Export({
FileName => $filename,
FilterName => 'GIF',
Interactive => 0
});
Not sure if I should be using the ChartArea object at all. Anyone familiar
with the VBA for Excel2K object model?
Any suggestions appreciated.
Dave
------------------------------
Date: Tue, 20 Feb 2001 11:22:13 -0500
From: "Dave McIntyre" <davemci@americasm01.nt.com>
Subject: Re: Win32::OLE Excel Chart sizes
Message-Id: <96u5h8$7jg$1@bcrkh13.ca.nortel.com>
> Not sure if I should be using the ChartArea object at all. Anyone familiar
> with the VBA for Excel2K object model?
>
> Any suggestions appreciated.
> Dave
apologies, should have been new post
------------------------------
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 V10 Issue 321
**************************************