[22992] in Perl-Users-Digest
Perl-Users Digest, Issue: 5214 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 11 12:55:22 2003
Date: Fri, 11 Jul 2003 08:05:08 -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 Fri, 11 Jul 2003 Volume: 10 Number: 5214
Today's topics:
Re: Accessing elements in array ref of array references <usenet@expires082003.tinita.de>
Re: Accessing elements in array ref of array references <usenet@expires082003.tinita.de>
Re: Accessing elements in array ref of array references (Greg Bacon)
Re: Alternative to use vars <bik.mido@tiscalinet.it>
Re: and EZ way to convert XLS file to CSV? (Sara)
Re: and EZ way to convert XLS file to CSV? (Sara)
Re: and EZ way to convert XLS file to CSV? (Sara)
Re: Fastest way to build a hash (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Re: How to add a sequential number to a form (Sara)
Re: Perl 5.8.0 compilation fails in chrooted environmen <nospam-abuse@ilyaz.org>
Re: Perl and telnet <REMOVEsdnCAPS@comcast.net>
Re: Perl and telnet (Greg Bacon)
Re: Perl code question <REMOVEsdnCAPS@comcast.net>
Re: Perl FAQ error in "variable as a variable name" (Eric Pement)
Re: Question about Devel::Cover <usenet@expires082003.tinita.de>
Running Perl on WinCE ( IBM Z50 mini laptop)? (dnrg)
Re: Seeking advice on selecting a sub (possibly/slightl <bik.mido@tiscalinet.it>
Simple: How to include file? <tvrtko@croadria.com>
Re: Simple: How to include file? (Greg Bacon)
Re: split operator with quoted strings <nanae@perusion.com>
Win32-OLE, excel, and empties. <spikey-wan@bigfoot.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Jul 2003 11:17:30 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Accessing elements in array ref of array references
Message-Id: <bem6ca$6qs0u$1@ID-24002.news.uni-berlin.de>
fatted wrote:
> Currently I'm comparing the first value of each of the array
> references (which are stored in an array reference $ref_ref) as
> follows:
> if(map($_->[0] =~ /$keyword/i,@$ref_ref))
> {
> # Do something cunningly clever...
> }
okay...
> What I was wondering about (for no particular reason) is doing
> something like:
> if(map(/$keyword/i,cool_function(@$ref_ref, 0)))
> {
> # Do something equally cunningly clever...
> }
well, i can't see any reason either, but this would do it:
sub cool_function(\@$) {
map $_->[ $_[1] ] => @{ $_[0] }
}
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -
------------------------------
Date: 11 Jul 2003 11:48:49 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Accessing elements in array ref of array references
Message-Id: <bem871$6lia8$1@ID-24002.news.uni-berlin.de>
Tina Mueller wrote:
> well, i can't see any reason either, but this would do it:
> sub cool_function(\@$) {
> map $_->[ $_[1] ] => @{ $_[0] }
> }
or without prototype:
sub cool_function {
my $n = pop;
map $_->[$n] => @_
}
or:
sub cool_function {
map $_->[ $_[-1] ] => @_[0..$#_-1]
}
now *I* should get back to work =)
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -
------------------------------
Date: Fri, 11 Jul 2003 13:51:47 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Accessing elements in array ref of array references
Message-Id: <vgtg7jqdhbkk67@corp.supernews.com>
In article <4eb7646d.0307110111.4a18dd1d@posting.google.com>,
fatted <fatted@yahoo.com> wrote:
: [...]
:
: What I was wondering about (for no particular reason) is doing
: something like:
:
: if(map(/$keyword/i,cool_function(@$ref_ref, 0)))
: {
: # Do something equally cunningly clever...
: }
:
: Any idea's? (or should I get back to work ;)
If I understand you, cool_function would be equivalent to
sub cool_function {
my $i = pop;
map $_->[$i], @_;
}
We're discussing things at such a low level that we may be obscuring
an XY problem. What are you trying to do?
Greg
--
Indeed I tremble for my country when I reflect that God is just, that His
justice cannot sleep forever . . .
-- Thomas Jefferson
------------------------------
Date: Fri, 11 Jul 2003 15:26:37 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Alternative to use vars
Message-Id: <h96tgv8s69a47hd3s568m6mlqblspie3eo@4ax.com>
On Thu, 10 Jul 2003 10:36:29 +1000, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>> BTW: since you're so kind commenting my article, I'd like to hear your
>> (and other's) opinion about the other post I wrote, namely the one
>
>Is that the one with Message-ID
><aa6egvkv440j3u8baqeugciu6ut6jrcsh4@4ax.com>?
Yes, it is.
>I read that article earlier, but I wasn't sure whether there was anythin
>in there that I could comment on :)
Fine!
>I do think it might show that there is still a bit of a misunderstanding
>about what C<my()>, C<local()>, C<our()> and C<use vars> do, and that's
>understandable, since they seem to do many similar things.
>
>Maybe a few more explanations, as I see things, could help, in addition
>to MJD's "Coping with scoping" article. I'll say much of the same, but
>phrased differently.
[snip]
REPETITA IUVANT...
>translation, which will probably be automatic [4]. Perl 6 is a new language,
>and one of the goals of the project is to finally get rid of all the
>accumulated backward compatibility mess. Localisation and scope is
I see... actually, even if Perl is supposed to be a non-elegant (but
magic!) language, whenever I discover *how* an extension to a previous
release and in particular to Perl4 has been added, I'm astonished by
how elegantly such an extension has been implemented wrt backwards
compatibility.
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: 11 Jul 2003 05:31:07 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: and EZ way to convert XLS file to CSV?
Message-Id: <776e0325.0307110431.544f8ec1@posting.google.com>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns93B49CBD9408Easu1cornelledu@132.236.56.8>...
> genericax@hotmail.com (Sara) wrote in news:776e0325.0307100525.37b06a42
> @posting.google.com:
>
> > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
>
> I do not know what XL is but I'll assume you are talking about Excel.
Yes sorry I'm not fluent in Microsoft-ese...
>
> > another package NIH by Microsoft but still controlled by them...
>
> NIH?
Not Invented Here
_ _ _
>
> > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
> > I looked in cpan and news but didn't see a straightforward way to do
> > the same thing with a Perl module. I saw XL-Parse but the readme
> > implied it didn't have a quick-conversion capability.
>
> I do not know about modules, but some time ago, I wrote a very
> rudimentary method to save each sheet in a bunch of Excel files in text
> format. If you are on a Win32 system with Excel installed, you could use
> that method. See:
>
> http://www.people.cornell.edu/pages/asu1/notes/perl-excel.html
Hmm I see- and I appreciate the tip and offer. Luckily for me I'm not
on a Billy-G platform, I have either Solaris or Linux at my diposal.
Regards, and have a nice weekend!
Gx
>
> Sinan
------------------------------
Date: 11 Jul 2003 05:34:43 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: and EZ way to convert XLS file to CSV?
Message-Id: <776e0325.0307110434.7cc4db04@posting.google.com>
Garry Short <g4rry_short@zw4llet.com> wrote in message news:<bejstc$msb$1$8302bc10@news.demon.co.uk>...
> Sara wrote:
>
> > OK, I'm painted into a corner by Bill G again.. This time with XL, yet
> > another package NIH by Microsoft but still controlled by them...
> >
> > If I bop into OpenOffice I can read in an XLS and export it as a CSV.
> > I looked in cpan and news but didn't see a straightforward way to do
> > the same thing with a Perl module. I saw XL-Parse but the readme
> > implied it didn't have a quick-conversion capability.
> >
> > Something, perhaps, like
> >
> > my @csv = DreamXLModule::Convert($XLFilePath, 'csv');
> >
> > Thanks!
> > Gx
>
> Not seen one, sorry. You could write your own without too much trouble,
> using Spreadsheet::ParseExcel, something like this:
>
> --
>
> #!/usr/bin/perl -w
> use strict;
> use Spreadsheet::ParseExcel;
> my ($file) = (@ARGV);
> my $dest = $file;
> my $xls = Spreadsheet::ParseExcel::Workbook->Parse("$file");
> foreach my $sheet (@{$xls->{Worksheet}}) {
> my $name = $sheet->{Name};
> my $dest =~ s/\.xls$/_sheet$name\.cvs/;
> open OUT, ">$dest" or die "Can't write to $dest: $!\n";
> my ($col, $row);
> for ($row = $sheet->{MinRow};
> defined $sheet->{MaxRow} && $row <= $sheet->{MaxRow};
> $row++) {
> for ($col = $sheet->{MinCol};
> defined $sheet->{MaxCol} && $col <= $sheet->{MaxCol};
> $col++){
> my $cell = $sheet->{Cells}[$row][$col]->Value;
> print OUT "$cell,";
> }
> print OUT "\n";
> }
> close OUT;
> }
>
> --
>
> It should write every sheet to a different file, in the form
> <filename>_<sheetname>.cvs
> Not tested, but it may work. Gives you the idea, anyway.
>
> Two things, though - this module throws up lots of warnings, so you may wish
> to switch them off once you get it working.
> Also, this won't be quick (from recent experience, I'd guess about 15mins
> for an xls with 12 sheets, each around 150x400. That's on a P3/700mhz with
> 128mb RAM & Linux, just to give you an idea)!
>
> Hopefully this'll give you a good start on writing it, anyway. It may just
> need a check to make sure the cell's not empty.
>
> Regards,
>
> Garry
Garry:
MOST APPRECIATED dude- you didn't have to go to all of that trouble! I
figured with this probably being a very common conversion, that there
would be a ton of modules out there. But your solution should work
fine- I'm gonna give it a go here shortly once I get the module
insalled.
That's amazing that it could run 15 minutes. This is a 1GHz with like
512MB RAM running Redhat 8; I hope I can get these converted faster
than that! But if not then we'll just have to live with it- heck a 15
minute coffeebreak 3-4 times a day sounds OK to me no?
Regards, and have a nice summer weekend...
-Gx
------------------------------
Date: 11 Jul 2003 05:37:23 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: and EZ way to convert XLS file to CSV?
Message-Id: <776e0325.0307110437.3306fdcb@posting.google.com>
helgi@decode.is (Helgi Briem) wrote in message news:<3f0d8994.15320453@news.cis.dfn.de>...
> On 10 Jul 2003 06:25:45 -0700, genericax@hotmail.com (Sara) wrote:
>
> >OK, I'm painted into a corner by Bill G again.. This time with XL, yet
> >another package NIH by Microsoft but still controlled by them...
> >
> >If I bop into OpenOffice I can read in an XLS and export it as a CSV.
> >I looked in cpan and news but didn't see a straightforward way to do
> >the same thing with a Perl module. I saw XL-Parse but the readme
> >implied it didn't have a quick-conversion capability.
>
> Are you talking about Excel, by any chance?
>
> use Spreadsheet::ParseExcel;
Yes, that's what an XLS file extension implies, no? The package you
mention is the one I already mentioned- wherein that readme didn't
imply a method was there do to the conversion (directly).
Anyhow, Garry gave me a good kickstart I'm gonna try his suggestion
and code.
Thank-You,
Gx
------------------------------
Date: 11 Jul 2003 06:03:19 -0700
From: fischerlaender@gmx.de (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Subject: Re: Fastest way to build a hash
Message-Id: <ff9bee6c.0307110503.9bb9231@posting.google.com>
Vlad Tepes <minceme@start.no> wrote in message news:<bejmk6$4g7$1@troll.powertech.no>...
> You should store the data in a way that requires minimal processing to
> build the hash. I tried using keys and values separated with newlines,
> and built a similar hash in a little over 1 second with:
> open my $fh, "hash.dat" or die;
> undef $/;
> my %hash = split /\n/, <$fh>;
On my (slow) system it takes about 2.1 seconds and is nearly as fast
as the other solutions. Now I can choose from four different, very
fast programs.
Thank you all for your ideas and code snippets!
Stefan
------------------------------
Date: 11 Jul 2003 05:47:49 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: How to add a sequential number to a form
Message-Id: <776e0325.0307110447.7ff32f34@posting.google.com>
"gwmbox" <gregatwork@NOSPAMPLEASEhotmail.com> wrote in message news:<bel3dj$g6i$1@ftp.curtin.edu.au>...
> Hi
>
> I have a basic form mailer script but I want to add a number that increments
> on each use of the form - like an ID for each request sent - how do I do
> this - anyone got any code I can use to add this to a form script?
>
> Thanks
>
> Greg
uhhh...
my $formSequence = 0;
while (1)
{$done = UseForm($formSequence);
last if $done;
$formSequence++;
}
Now, if you need to have the increment PERSIST, that is continue where
you left off from the last run, you have a few options there. One is
to tie the scalar. Another is to have it in a textfile and do a little
error-checking on it. The nice part about the latter solution is that
you can EDIT the file and change the value if you need to. Also tie
actually creates 2 files, which seems like a lot of overhead to store
one little old integer no?
This might work:
die "cannot open increment-value file, Land O Goshen!!\n $!" unless
open I, "./increment.dat";
my @i = <I>;
close I;
# you may have to futz around a little with the EOL character, Ill
leave that
# as an exercise for the reader
die "This does not seem to BE an increment file, what the HEY?\n"
unless @i == 1 && $i[0] =~ /^\d+$/;
# OK we have our value..
my $formSequence = $i[0];
# use the rest of the code above
Have a super weekend I know I will its NNW!!
-Gx
------------------------------
Date: Fri, 11 Jul 2003 12:57:14 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Perl 5.8.0 compilation fails in chrooted environment
Message-Id: <bemc7a$djg$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<vrihad@myway.com>], who wrote in article <2a024f54.0307110100.7cf2eac5@posting.google.com>:
> I went through the file Cwd.pm. I found that it is checking for unix
> command pwd in directories /bin and /usr/bin. Since I was using busybox
> for pwd and it was installed in /usr/local/bin, it was not getting detected.
> > P.S. And, please, report the whole story as a bug via perlbug.
> It seems to be not a bug in perl installation script. Just the position of
> one binary in my system was not correct.
Still, it looks like a bug. Please report all the sides of it, so the
developers have enough info to decide whether /usr/local/bin is a good
place to add. [BTW, the spelling of my name down below is correct. ;-]
Yours,
Ilya
------------------------------
Date: Fri, 11 Jul 2003 05:24:05 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Perl and telnet
Message-Id: <Xns93B541269ADF2sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Matt Oliverius <moliverius@w-link.net> wrote in
news:vgsnmgi1v1sr77@corp.supernews.com:
> Hello,
>
> I am trying to get Perl to make the hard things possible, but I'm
> having my doubts on this one...
Look into the Expect module. Or maybe just using 'expect' itself..
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPw6QG2PeouIeTNHoEQKm4wCgqBPZPqV32noK5xwF9QAWeJt4jP8AoKoN
WhXdu6cZNJpSJIFUoSU7bMWI
=sOmP
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 11 Jul 2003 13:36:22 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Perl and telnet
Message-Id: <vgtfams9311lb5@corp.supernews.com>
In article <vgsnmgi1v1sr77@corp.supernews.com>,
Matt Oliverius <moliverius@w-link.net> wrote:
: [...]
:
: Where I am stuck is how can you automate the login in each one of
: those Xterms? The initial script that telnets and logs in is done in
: a single terminal window. However, once the open machines are
: determined, we want to run each instance of the C code in a separate
: Xterm telnet session.
Do you use ssh on your network? The Net::Telnet module has an example
that controls an ssh session, and you'd want an ssh command equivalent
to
ssh -l username host xterm -e your-c-program
Using ssh takes care of all the X11 forwarding issues. You might
want to build a wrapper around your C program that waits for user
input after the C program runs. Otherwise, the xterm will dismiss
itself after your program completes.
Another approach would be to have a daemon that runs on all the
machines on your network. This daemon would watch the load average
and number of users, sleeping if it wouldn't be nice to use the
machine. When circumstances permit, however, it would start your
C program and either store results or send them to some reporting
service.
Hope this helps,
Greg
--
compilant, adj.: Not necessarily compliant, but at least it compiles.
-- Jutta Degener
------------------------------
Date: Fri, 11 Jul 2003 05:21:31 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Perl code question
Message-Id: <Xns93B540B75963Asdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Matt Oliverius <moliverius@w-link.net> wrote in
news:vgsl80mu09koae@corp.supernews.com:
> Hi all,
>
> I'm trying to do something which I believe is quite complex, and I'm
> hoping someone here might not find it so complex. The problem
> involves permutations. Here is the structure of my input file
Structure? No, that's an *example* of your input file. What's missing
is descriptions of the columns and what they might hold.
...
> Basically, you can think of the second column as a compartment. There
> are 5 compartments total.
But you have nine distict values listed in column two. ???!
> Sometimes one or more of these compartments
> can be used to store a half size box, so I basically want to permutate
> every possible combination. If all compartments used had a full box
> or alternate half box configuration then there would be 2^5
> permutations because each compartment either stores one full size box
> or 2 half size boxes. In the above example, there are four
> possibilities since 613 has either full, or half and 614 has either
> full or half and 615-617 only have full.
Four....? I may be dense... that sounds like seven possibilities.
> I need to print each
> permutation along with all the data in columns 0-5 in an ascii file.
> Does anyone have any easy way of doing this? I have beat my head on
> this one for hours.
How exactly do you want to summarize or group the data in columns 0-5 for
the permutations?
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPw6PtGPeouIeTNHoEQLzagCffW6N3F4o4WE59CwSoN5kf3xzLFsAoNgj
/8jMhHKsxTZNsDDdCBvbbAOt
=NU4u
-----END PGP SIGNATURE-----
------------------------------
Date: 11 Jul 2003 07:32:04 -0700
From: pemente@northpark.edu (Eric Pement)
Subject: Re: Perl FAQ error in "variable as a variable name"
Message-Id: <227a55e9.0307110632.637574a3@posting.google.com>
"James E Keenan" <jkeen@concentric.net> wrote in message news:<bekq6l$cq8@dispatch.concentric.net>...
> "Eric Pement" <pemente@northpark.edu> wrote in message
> news:227a55e9.0307100744.6170bb93@posting.google.com...
[... snip ...]
> > The FAQ currently reads in part:
> >
> > By using symbolic references, you are just using the package's
> > symbol-table hash (like %main::) instead of a user-defined hash.
> > The solution is to use your own hash or a real reference instead.
> >
> > $fred = 23;
> > $varname = "fred";
> > $USER_VARS{$varname}++; # not $$varname++
> >
> > This solution does not work and does not provide "24" as one would
> > expect. You can prove it by just running the script:
> >
> No, one would *not* expect '24' as the result. You're not doing anything
> with $fred once you've assigned '23' to it.
Which is exactly what my posting demonstrated. I should have worded my
comment more precisely: "This solution does not work and does not provide
'24' as the authors of the Perl FAQ thought it would."
It was an accident on their part, and with such a large document it
is almost inevitable that errors will creep in here and there. Hopefully
this one will be corrected in the next edition.
--
Eric Pement
------------------------------
Date: 11 Jul 2003 12:18:36 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Question about Devel::Cover
Message-Id: <bem9us$6lia8$2@ID-24002.news.uni-berlin.de>
Himal wrote:
> I downloaded it from cpan.
> tar -xvf
> make
> make test
> perl -Mdevel::Cover temp.pl
btw, are you really calling it this way? ist's
Devel::Cover, not devel::Cover (case-sensitive)
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -
------------------------------
Date: 11 Jul 2003 05:35:06 -0700
From: dananrg@yahoo.com (dnrg)
Subject: Running Perl on WinCE ( IBM Z50 mini laptop)?
Message-Id: <c1888d06.0307110435.39d09a36@posting.google.com>
Anyone have Perl binaries for an IBM Z50 mini-laptop running WinCE
2.0?
Probably just "any old" WinCE binary wouldn't work because,
apparently, it would have to be compiled for the specific processor in
the IBM Z50.
I love my Z50. I know of no other laptop that has a 16 hour battery. I
often wonder why they discontinued the Z50 because it's perfect for
mobile computing. I once tried to use a fold-out keyboard and a Palm
Pilot for mobile writing and it was absurd; screen was way too small.
Thanks.
- Dana
------------------------------
Date: Fri, 11 Jul 2003 15:26:38 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Seeking advice on selecting a sub (possibly/slightly related to cmd line switches)
Message-Id: <1qdtgvs9udrr16ru3n7gr3qbo7u34vnd7v@4ax.com>
On Wed, 09 Jul 2003 18:26:30 -0500, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>That looks like it'd work. I think I personally would have done it
>differently; I'd put a code reference into a scalar variable, $doit, and
[snip]
>You could do this via dispatch table:
[snip]
> my $doit = $dispatch{$option};
> $doit->($_) while <>;
> # or even:
> $dispatch{$option}($_) while <>;
Well, to answer to you and to the others who kindly followed-up my
post, from *my* point of view, all these alternative approaches are
substantially equivalent to my own. That is, I just wanted to know if
"assigning" a suitable coderef is a good way to implement "diversified
behaviours". Say I was quite confidedent this is in fact the case: I
just needed some confirmation...
I wrote "substantially" and not "completely" because actually I've not
played much with typeglobs and I couldn't be 100% sure there wouldn't
have been any issue with (wrt my original code)
sub doit;
...
*doit = sub { ... };
and if there are not, then I will continue using such a technique,
since I feel most comfortable with it as far as code readibility is
concerned. At this point it is largely a matter of personal taste: I
can understand that (e.g.) other people would prefer to tell
user-defined subs from builtin commands, but I prefer to always have
some "degree of freedom" with parentheses and be allowed to ignore
some. (with all my respect to LISP fans out there!)
>> sub doit {
>> ...
>> }
>>
>> doit.END = {
>> print STDERR "$.: foo" if $foo;
>> } if $verbose;
>
>You can do this in Perl 5. No need to wait for hell to freeze over,
>which is approximately when Perl 6 will be ready for prime time. See the
>Hook::LexWrap module (although the wrappers are not "lexical" as the name
>implies, but rather dynamic).
Wow, I would have never thought it would be possible *now*. Even if I
have a feeling it is a "workaround", I'll try it ASAP. However, as I
said, I'm curious, and in particular I'm curious about Perl6, because
of the various "snippets" I've heard about, and OTOH, you see, this is
the kind of thing one (well, "I", for one) would like to see as a
basic language feature.
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: Fri, 11 Jul 2003 15:22:19 +0200
From: Tvrtko Ursulin <tvrtko@croadria.com>
Subject: Simple: How to include file?
Message-Id: <20030711132522.1D889943.NOFFLE@orion.local>
Hello everyone!
I am new to perl (from C) and cannot figure how to include a simple custom
file in the main program?
I need something like:
our $default_value = 'xyz';
in my include.ph, and a way to include this in main.pl so that
$default_value can normally be used. Can it be done?
------------------------------
Date: Fri, 11 Jul 2003 13:56:40 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Simple: How to include file?
Message-Id: <vgtggo5nlep0e4@corp.supernews.com>
In article <20030711132522.1D889943.NOFFLE@orion.local>,
Tvrtko Ursulin <tvrtko@croadria.com> wrote:
: I am new to perl (from C) and cannot figure how to include a simple
: custom file in the main program?
:
: I need something like:
:
: our $default_value = 'xyz';
:
: in my include.ph, and a way to include this in main.pl so that
: $default_value can normally be used. Can it be done?
You could do it quickly with
% cat try
#! /usr/local/bin/perl
require "foo.pl";
print $default_value, "\n";
% cat foo.pl
$default_value = 'xyz';
% ./try
xyz
Depending on the nature of your project, you probably don't want to do
it that way, though, but want instead to write a module. See the
perlmod and perlmodlib manpages.
Hope this helps,
Greg
--
You have to choose between trusting the natural stability of gold and the
honesty and intelligence of members of the government. With due respect for
these gentlemen, I advise you, as long as the capitalist system lasts, to
vote for gold. -- George Bernard Shaw
------------------------------
Date: Fri, 11 Jul 2003 12:43:43 +0000 (UTC)
From: Perusion hostmaster <nanae@perusion.com>
Subject: Re: split operator with quoted strings
Message-Id: <slrnbgtc83.ogk.nanae@ns.valuemedia.com>
On 11 Jul 2003 00:42:07 -0700, arasu@nospam.org <sent_arasu@hotmail.com> wrote:
> Hi,
>
> #!/usr/local/bin/perl -w
>
> use strict;
>
> my $x = 'hello goat "world world world" "fox goat"';
>
> my @x = split ( /\s+/, $x );
>
> foreach ( @x )
> {
> print "$_\n";
> }
>
> ======================
>
> This splits on space, but expected output is
> "string within quotes should not be split."
>
> hello
> goat
> "world world world"
> "fox goat"
Easy with a standard module:
use Text::ParseWords qw/quotewords/;
my $x = 'hello goat "world world world" "fox goat"';
my @x = quotewords('\s+', 1, $x);
print join "\n", @x, '';
The second parameter to quotewords() tells it to keep the quotation
marks, set it to zero to not retain them.
--
Perusion Hostmaster
"Being against torture ought to be sort of a bipartisan thing."
-- Karl Lehenbauer
------------------------------
Date: Fri, 11 Jul 2003 12:15:36 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Win32-OLE, excel, and empties.
Message-Id: <bem6b2$1lg$1@newshost.mot.com>
Hello World!
I'm trying to find the first empty row in a spreadsheet.
If I use this:
my $EmptyRow = $sheet->UsedRange->rows->count;
$EmptyRow ++;
It works, UNLESS the spreadsheet is empty, where the first line returns 1,
and I end up writing to row 2 instead of row 1.
If I use this:
my $EmptyRow = $sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
my $err = Win32::OLE::LastError();
unless ($err eq 0) {$EmptyRow = 0;}
$EmptyRow ++;
This also works, unless the spreadsheet is empty, where I get the following
error:
Can't use an undefined value as a HASH reference at D:\Script.pl line 43,
<FILE> line 167.
Line 43 is:
my $LastRow = $sheet->UsedRange->Find({What=>"*",
and I only have 127 lines.
Can someone help me out, please?
Thanks.
R.
------------------------------
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 5214
***************************************