[24355] in Perl-Users-Digest
Perl-Users Digest, Issue: 6544 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 8 21:05:37 2004
Date: Sat, 8 May 2004 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 8 May 2004 Volume: 10 Number: 6544
Today's topics:
A Stupid question. (Mark Healey)
Re: A Stupid question. <matthew.garrish@sympatico.ca>
Re: A Stupid question. (Sam Holden)
Re: Books online???? <tadmc@augustmail.com>
Re: Books online???? <me@privacy.net>
Re: Finding all open filehandles and closing them befor <pb2@aracnet.com>
Re: Finding all open filehandles and closing them befor <troc@pobox.com>
Re: is there something more elegant to convert Dos to u <uri@stemsystems.com>
many packages in one file <zoooz@gmx.de>
Re: many packages in one file <abigail@abigail.nl>
Re: many packages in one file (Malcolm Dew-Jones)
Re: Spreadsheet::WriteExcel <sean_berry@cox.net>
Re: timeout when reading from a server socket. <abigail@abigail.nl>
Re: win32::ole and excel VBA macro conversion: SmallScr moller@notvalid.se
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 08 May 2004 20:07:40 GMT
From: die@spammer.die (Mark Healey)
Subject: A Stupid question.
Message-Id: <VP2SpNyJrzMZ-pn2-lOGkVxwVd5VO@adsl-63-207-135-60.dsl.sndg02.pacbell.net>
For some reason I can't find the answer to this question in the
O'Reily books I have.
How to I pass an array or hash to a function?
--
Mark Heaely
marknews(at)healeyonline(dot)com
------------------------------
Date: Sat, 8 May 2004 16:23:07 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: A Stupid question.
Message-Id: <Fkbnc.104616$ZJ5.2364893@news20.bellglobal.com>
"Mark Healey" <die@spammer.die> wrote in message
news:VP2SpNyJrzMZ-pn2-lOGkVxwVd5VO@adsl-63-207-135-60.dsl.sndg02.pacbell.net...
> For some reason I can't find the answer to this question in the
> O'Reily books I have.
>
> How to I pass an array or hash to a function?
>
O'Reilly's books are much better... ; )
In answer to your question, just pass a reference to your hash or array:
mysub(\@array, \%hash);
sub mysub {
my ($aref, $href) = @_;
}
Matt
------------------------------
Date: 8 May 2004 22:22:46 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: A Stupid question.
Message-Id: <slrnc9qndm.sem.sholden@flexal.cs.usyd.edu.au>
On Sat, 08 May 2004 20:07:40 GMT, Mark Healey <die@spammer.die> wrote:
> For some reason I can't find the answer to this question in the
> O'Reily books I have.
>
> How to I pass an array or hash to a function?
sub foo {
my ($arg1, $arg2, @array) = @_;
}
sub bar {
my ($arg1, %hash) = @_;
}
foo($a_scalar, $another, @an_array);
bar($a_scalar, %a_hash);
If you want to pass more than one array or hash then see
perldoc perlsub
Of particular interest will be the section which begins:
Pass by Reference
If you want to pass more than one array or hash into a
function--or return them from it--and have them maintain
their integrity, then you're going to have to use an
explicit pass-by-reference.
Reading the documentation that comes with perl is usually a good
first step when wanting to know how to do something in perl.
------------------------------
Date: Sat, 8 May 2004 15:02:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Books online????
Message-Id: <slrnc9qf6m.8tq.tadmc@magna.augustmail.com>
Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
> Suppose the experts relax, and don't put heat on people who
> consistently answer things incorrectly, and an anything-goes
> atmosphere (the sort you appear to be advocating) becomes the norm.
For a peek into that future, lurk on alt.perl for several weeks and
see how well it works.
(at least that's what alt.perl was when I attempted to read
it some years ago.
)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 9 May 2004 08:57:18 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: Books online????
Message-Id: <2g4vs9F4h2g8U1@uni-berlin.de>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnc9qf6m.8tq.tadmc@magna.augustmail.com...
> Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:
>
> > Suppose the experts relax, and don't put heat on people who
> > consistently answer things incorrectly, and an anything-goes
> > atmosphere (the sort you appear to be advocating) becomes the norm.
>
>
> For a peek into that future, lurk on alt.perl for several weeks and
> see how well it works.
>
> (at least that's what alt.perl was when I attempted to read
> it some years ago.
> )
Still much the same, although a few of the clpm regulars do their best to
stem the worst abuses.
------------------------------
Date: 8 May 2004 19:03:15 GMT
From: P Buder <pb2@aracnet.com>
Subject: Re: Finding all open filehandles and closing them before exiting
Message-Id: <c7jatj02lnk@enews3.newsguy.com>
Closing everything up to POSIX_OPEN_MAX will not necessarily close all files. It is
defined as a quantity you are guaranteed to have available to you, but the system may
support more. Also, keep in mind the number of FILE pointers you can have via the
perl open /C fopen can be less than the number of file descriptors via perl
sysopen/C open. In one version of Solaris you could have 256 FILE pointers but
1024 file descriptors as I recall.
------------------------------
Date: Sat, 08 May 2004 23:32:36 GMT
From: Rocco Caputo <troc@pobox.com>
Subject: Re: Finding all open filehandles and closing them before exiting
Message-Id: <slrnc9qrkt.lqj.troc@eyrie.homenet>
On 8 May 2004 19:03:15 GMT, P Buder wrote:
> Closing everything up to POSIX_OPEN_MAX will not necessarily close all files. It is
> defined as a quantity you are guaranteed to have available to you, but the system may
> support more.
I'm skeptical about this, but I'll let it stand because I don't have
evidence to the contrary.
> Also, keep in mind the number of FILE pointers you can have via the
> perl open /C fopen can be less than the number of file descriptors via perl
> sysopen/C open. In one version of Solaris you could have 256 FILE pointers but
> 1024 file descriptors as I recall.
I disagree. Multiple streams (FILE* in C) can refer to the same file
descriptor. Check out the documentation for fdopen(3), which will
create a new stream associated with an existing open descriptor.
I can illustrate it in Perl. Here both the WHEE and STDIN file handles
share descriptor 0.
1) poerbook:~% perl -wle 'open(WHEE, "<&=STDIN"); print fileno(STDIN); \
print fileno(WHEE)'
0
0
Closing the descriptor with POSIX::close() will close all the handles
associated with it. It's "sneaky" enough that Perl won't give you the
"print() on closed filehandle" warning.
1) poerbook:~% perl -wle 'use POSIX; open(WHEE, ">&=STDOUT"); \
POSIX::close(fileno(WHEE)); print "narf"'
1) poerbook:~%
-- Rocco Caputo - http://poe.perl.org/
------------------------------
Date: Sat, 08 May 2004 18:21:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: is there something more elegant to convert Dos to unix in subroutine?
Message-Id: <x7fzaasrub.fsf@mail.sysarch.com>
stop top posting. no more help until you learn this.
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: Sun, 09 May 2004 00:22:23 +0200
From: Amir Kadic <zoooz@gmx.de>
Subject: many packages in one file
Message-Id: <2g555kF4ne4bU1@uni-berlin.de>
Hi!
I'd like to put 2 (or more) packages in one file, the code
each of which is using functionality from the other ones.
And I'd like to make the whole thing compile :-)
Something like:
package a;
use b;
package b;
use a;
(The reason is simple: stuff the whole app into one file
for distribution.)
Thanks for any hints.
Amir
------------------------------
Date: 09 May 2004 00:06:11 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: many packages in one file
Message-Id: <slrnc9qtfj.4ga.abigail@alexandra.abigail.nl>
Amir Kadic (zoooz@gmx.de) wrote on MMMCMIII September MCMXCIII in
<URL:news:2g555kF4ne4bU1@uni-berlin.de>:
&&
&& Hi!
&&
&& I'd like to put 2 (or more) packages in one file, the code
&& each of which is using functionality from the other ones.
&&
&& And I'd like to make the whole thing compile :-)
&&
&& Something like:
&&
&& package a;
&& use b;
&& package b;
&& use a;
That's not going to work, a "use a" is going to look for a file "a.pm"
and compile what's in there. Just do something like:
package a;
#
# Stuff from package a
#
package b;
#
# Stuff from package b
#
Note that code for package a can use what's in package b (but not during
compile time, like in a BEGIN) - package b can use package a even during
compile time. If you want any exporting to happen, you have to call
import() yourself.
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: 8 May 2004 17:12:54 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: many packages in one file
Message-Id: <409d7786@news.victoria.tc.ca>
Amir Kadic (zoooz@gmx.de) wrote:
: Hi!
: I'd like to put 2 (or more) packages in one file, the code
: each of which is using functionality from the other ones.
: And I'd like to make the whole thing compile :-)
: Something like:
: package a;
: use b;
: package b;
: use a;
: (The reason is simple: stuff the whole app into one file
: for distribution.)
: Thanks for any hints.
Did you try it? What error did you have?
The only issue should be the "use module" lines, since there is no longer
a file to load. The easiest solution is to comment out the line. It's
possible that you will need to call the import functions later yourself in
that case (assuming the module has an import function).
so
use module1;
use modeul2;
becomes
insert module1 code here
.
.
.
insert module2 code here
.
.
.
#use module1;
import module1; # each use may need an import at that point
#use module2;
import module2; # each use may need an import at that point
If you can't easily comment out the use module statements, then explicitly
set a value into the %INC hash for the module name. I CANT TEST THIS
EXAMPLE, though I have used something like this so I know the idea works
insert module1 code here
.
.
.
$INC{'module1'} = 1; # indicates the module is loaded
------------------------------
Date: Sat, 8 May 2004 12:52:13 -0700
From: "Sean Berry" <sean_berry@cox.net>
Subject: Re: Spreadsheet::WriteExcel
Message-Id: <rTanc.97062$Jy3.4635@fed1read03>
I got by my previous error. But now I have a new problem.
If I ever try to write past the 8th column, the xls file becomes corrupted
and will not open. I can fill cells in columns up to 8, but as soon as I
try to add a cell to column 8, whamo.
Any ideas here?
TIA
"Sean Berry" <sean_berry@cox.net> wrote in message
news:ODWmc.85741$Jy3.46975@fed1read03...
> Is there a way of opening a preformatted excel file, then write to empty
> cells in the table.
>
> I have a table with various formulas, cell and text colors, borders, etc.
> But, the data is in a 28 x 170 sized chunk of the sheet. This will be a
big
> pain to code so I was looking for a shortcut.
>
> Is is possible to parse the .xml file and use the values within instead of
> just the data?
>
> TIA
>
>
------------------------------
Date: 09 May 2004 00:11:54 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: timeout when reading from a server socket.
Message-Id: <slrnc9qtqa.4ga.abigail@alexandra.abigail.nl>
Darryl Perry (dperry.geo@yahoo.com) wrote on MMMCMIII September MCMXCIII
in <URL:news:c39c8d76.0405080843.fcc4d55@posting.google.com>:
-: I'm trying to write a simple finger client in perl on Redhat 9.0. I
-: can get it to read just fine, that's not the problem. The problem is
-: that when it tries to connect to a server that is not responding, it
-: takes several minutes before it fails. I would like to set up a
-: timeout value to like 10 seconds. Can anybody recommend a way for me
-: to do this? I've already tried alarm(), but that has unwanted side
-: effects when the alarm time has been reached.
It depends on how you create your socket. Some suggestions:
- Use select() before doing a blocking action on a handle.
- Only use non-blocking actions on your handle - if the action
failed because there was nothing to do, (microsleep) and retry
until your time is up.
- Use IO::Socket::INET and a TimeOut parameter.
- Use POE.
- Use threads. Open the socket in a subthread - kill the thread if
it didn't connect after 10 seconds.
- fork(). Open the socket in the child. Kill the child if it hasn't
connected after 10 seconds.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Sat, 08 May 2004 21:57:03 GMT
From: moller@notvalid.se
Subject: Re: win32::ole and excel VBA macro conversion: SmallScroll
Message-Id: <uy8o260pp.fsf@notvalid.se>
Bob Walton <invalid-email@rochester.rr.com> writes:
> Domenico Discepola wrote:
>
> >>I wholeheartedly agree, a good book on the subject would have saved me
> >>weeks of experimenting and tinkering.
>
> You should *never* have to "experiment and tinker". It is *way* more
^^^^^^
A nice word but unforunatly I was not in a position to argue.
After one week at a new job I was given a 4 week deadline and
having no experince with eiter perl or excel I do what I must.
After two week the logic was done[1], the following three weeks
I spent trying to get excel to do what I wanted with charts
,fonts, textboxes, colors and whatnot. Because the charts had
to look "Just So".....
The price of tinkering in this way is not so good code but we
got a new customer on it and it's paying a third of my salary.
And I'm the poor bugger trying to clean up the code whenever I
have some time.
> effective to study and learn the terminology (so you know, for
> example, what exactly VBA means when its docs say "property"), and
Well I didn't have the time and they deemed a VB book unnessesary.
I was after all writing the thing in perl. (Also their decision)
> then follow the docs to the letter. When you do that, things work --
> you can write code that works the first time. The approach of copying
> the first example you see, ignoring "minor" differences, must be
> hugely frustrating. It is not the docs or the books that are
^^^^^^^^^^^^^^^^^^
very
> deficient, it is the technique by which you are approaching
> programming that is deficient.
I spent several years at uni learning proper[2] computer science.
And I have tried many times to do software development the *right*
way but sadly the goal has mostly been to get it out of the door NOW.
I'm not telling where I work :-)
I wish someone would give me a problem to solve that I could spend
six moths on, reading the apropriate documentation. Selecting
the right tools for the job and perhaps maby get a properly written
specification (ohh wishful thinking).
I have never been able to use most the skills I was tought
regarding software design, robustness and efficency.
The only thing that I use is what they taught us about computer
languages. No matter what funny words they use or what weird
syntax they use they are fundamentally the same.
So one of my abilitys is to take a problem and solve it[3] with
the tools given to me (language/development environment).
Give me a week I can start working with (almost) any pice of code
you can throw at me written in any obscure computer language.
/Well just my opinion
[1] I mean that the design was done, the data extraction
was done, the data massaging was done and I knew
how to write the data to a worksheet in excel.
[2] I thought about writing about how good it is/was
but cant be botherd. If interested read at
http://www.it.uu.se/edu/masters/CS
Note! I was there more 92-96 so it has
probably changed
[3] For varying values of the solve
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6544
***************************************