[23057] in Perl-Users-Digest
Perl-Users Digest, Issue: 5278 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 27 18:05:51 2003
Date: Sun, 27 Jul 2003 15:05:09 -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 Sun, 27 Jul 2003 Volume: 10 Number: 5278
Today's topics:
Re: "theory vs practice" ceases power <ed@membled.com>
Re: "theory vs practice" ceases power <mspight@dnai.com>
Re: "theory vs practice" ceases power <ramen@lackingtalent.com>
Re: "theory vs practice" ceases power <ramen@lackingtalent.com>
Call for Authors (Bogomil Shopov)
Re: Called as method or subroutine? <tassilo.parseval@rwth-aachen.de>
Re: can this one-liner be squeezed any shorter? (Andrew Savige)
Re: can this one-liner be squeezed any shorter? (Tad McClellan)
Re: can this one-liner be squeezed any shorter? <abigail@abigail.nl>
Concatenation (Greg)
Re: Concatenation <tassilo.parseval@rwth-aachen.de>
Re: Currying functions (was "theory vs practice" ceases <REMOVEsdnCAPS@comcast.net>
Re: Currying functions (was "theory vs practice" ceases <fb@frank-buss.de>
Re: Currying functions (was "theory vs practice" ceases <ed@membled.com>
Extend global symbol table in embedded perl <aphor_noethe@hotmail.com>
Re: How to pick out words from a non-delimited string? <tassilo.parseval@rwth-aachen.de>
Re: How to pick out words from a non-delimited string? <NOSPAM@bigpond.com>
Re: How to pick out words from a non-delimited string? <boffin@fromru.com>
Re: module and $ARGV help <eric-amick@comcast.net>
Re: module and $ARGV help (Tad McClellan)
Re: Need help chopping data in Perl (Tad McClellan)
Re: Perl lib version (v5.6.0) doesn't match executable <kalinabears@iinet.net.au>
Perl module for doing text/document comparisons? (Phil)
Re: Perl module for doing text/document comparisons? <grazz@pobox.com>
Re: use File::Archive extracting zip's with '.' in fron <kalinabears@iinet.net.au>
Re: Where to hitch the <<EOF to plaster input file? <eric-amick@comcast.net>
Re: Where to hitch the <<EOF to plaster input file? (Tad McClellan)
Win32 Ole <mikeflan@earthlink.net>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Jul 2003 11:06:51 +0100
From: Ed Avis <ed@membled.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <l1oezgxozo.fsf@budvar.future-i.net>
Dave Benjamin <ramen@lackingtalent.com> writes:
>> sub curry( $ ) {
>> my $f = $_[0];
>> sub( $ ) { my $x = $_[0]; sub( $ ) { $f->($x, $_[0]) } };
>> }
>Well, I'd define curry a little differently,
There isn't really any option about how to define it. As far as I
know the operation 'curry' is defined as
curry f x y = f (x, y)
in other words turning a function which takes a pair into a function
which takes one argument and returns a function taking the second
argument.
Lots of people misuse the word 'curry' when they mean to say partial
application.
>sub curry {
> my $func = shift;
> my @args = @_;
>
> return sub { $func->(@args, @_) };
>}
What you have here is partial application - although no evaluation of
the function $func will happen until it is finally called. (OTOH, you
can imagine a Haskell system which is able to reduce (+ 0) to (id)
even before it is applied to anything, if the compiler can determine
that it's worthwhile.)
>It curries in any number of arguments, and produces a function that
>handles the rest.
Again there is no such thing as 'currying in arguments'. Look at the
Prelude in Haskell, or the standard library for many other functional
languages, to see what curry and uncurry mean.
>Then, I'd define my own map that takes a function reference instead
>of a code block:
>
>sub fmap {
> my $func = shift;
> my @args = @_;
>
> my @result = ();
> for my $arg (@args) {push @result, $func->($arg)}
> return @result;
>}
It's a nuisance that the standard Perl map() doesn't transparently
take a code reference, but you can write
map { $func->($_) } @args
>Your point about libraries not being designed in a curried style is
>totally valid, however. Thinking about currying in advance causes you
>to write functions that take arguments in a particular, thought-out
>order,
No, by a curried style I meant
plus(1)(2)
instead of
plus(1, 2)
and so on. Most Haskell standard library functions are in a curried
style, even the binary operators. If you want versions that take a
pair of arguments you can use the standard 'uncurry' function.
However I'm not aware of any Perl code that takes arguments this way.
>I don't think type checking is that important to the functional
>style, however.
It's not fundamental, but if you are like me and make lots of
mistakes, it just takes much too long to program complicated
functional things in Perl. You end up cluttering the code with
run-time type checks like
die if ref $x ne 'ARRAY';
die if @$x != 2;
die if ref $x->[0] ne 'CODE';
and this makes the syntax worse.
>It may be good for other things, like proving correctness, that may
>be of value to you. However, lambda calculus does not require type
>checking, and neither does LISP
Yes, but Lisp and Scheme have a clean syntax that makes it fairly
straightforward to say what you want. I can live without a simple
syntax, and I can live without type checking, but doing without both
is really uncomfortable.
(I don't mean simple 'map' stuff, I mean for more complicated programs
where you start having multiple layers of fold / map / filter / Maybe
/ curry / uncurry / etc etc. This is easy in Haskell, but very tricky
in Perl unless you are a programming demigod who rarely makes
mistakes.)
--
Ed Avis <ed@membled.com>
------------------------------
Date: Sun, 27 Jul 2003 15:55:32 GMT
From: "Marshall Spight" <mspight@dnai.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <UBSUa.158923$N7.20156@sccrnsc03>
"Xah Lee" <xah@xahlee.org> wrote in message news:7fe97cc4.0307261045.6f442296@posting.google.com...
> I have written the following essay, that i hope will demystify the
> computing jockey's inquiring minds.
>
> from:
> http://xahlee.org/UnixResource_dir/writ/theory_practice2.html
While I generally agree with what you're saying, I'd like to encourage
you to use a less vituperous tone. Your message will be lost when
you audience stops reading because you say things in such extreme
language.
It's possible to write the same message, but do it in a way that tries
to convince people. Right now you just come across like you're
pissed and you want to blow off some steam. Which is fine,
except no one will want to read it.
Marshall
------------------------------
Date: Sun, 27 Jul 2003 20:04:47 -0000
From: Dave Benjamin <ramen@lackingtalent.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <slrnbi8c9l.6eu.ramen@lackingtalent.com>
In article <l1oezgxozo.fsf@budvar.future-i.net>, Ed Avis wrote:
>>> sub curry( $ ) {
>>> my $f = $_[0];
>>> sub( $ ) { my $x = $_[0]; sub( $ ) { $f->($x, $_[0]) } };
>>> }
>
>>Well, I'd define curry a little differently,
>
> There isn't really any option about how to define it. As far as I
> know the operation 'curry' is defined as
>
> curry f x y = f (x, y)
I guess it all depends on what your definition of "define" is. =) Not to be
a pedant, but I can define "curry", the function in my Perl vocabulary, like
this as well:
sub curry {
"$_[0], you put too much curry in the $_[1] this time!";
}
print curry('Raji', 'chicken'), "\n";
Output:
Raji, you put too much curry in the chicken this time!
> in other words turning a function which takes a pair into a function
> which takes one argument and returns a function taking the second
> argument.
>
> Lots of people misuse the word 'curry' when they mean to say partial
> application.
You are correct about this, and I guess I've been misusing the word myself
for quite awhile. Interestingly, I proposed (with help from Carl Banks)
a function called "selfcurry" in comp.lang.python a few months ago that
really ought to have been called "curry", as it does what you describe.
At the same time, I think that naming this function "curry" would have been
at odds with the more popular usage of "curry" within that language domain.
I found a lot of variance searching Google for "curry function" and the
like. It seems that many people define "curry" (in code, not theory) as a
function that performs partial application, especially in languages that are
not explicitly functional. I think it may be more practical when dealing
with libraries that are not designed for currying, as many of those
languages offer. I also noticed that Dylan defines "curry" and "rcurry" as
partial applicators.
Wall on Perl 6 and a proposal for a function.curry(argument) type syntax:
http://archive.develooper.com/perl6-language@perl.org/msg09952.html
A paper on "Functional Currying in Scheme" which calls partial application
"explicit currying" (I didn't read this before I wrote previously, although
I reached the same implicit/explicit conclusion):
http://www.engr.uconn.edu/~jeffm/Papers/curry.html
A thread about Scheme called "It's not currying!":
http://srfi.schemers.org/srfi-26/mail-archive/msg00015.html
>>It curries in any number of arguments, and produces a function that
>>handles the rest.
>
> Again there is no such thing as 'currying in arguments'. Look at the
> Prelude in Haskell, or the standard library for many other functional
> languages, to see what curry and uncurry mean.
Well, I suppose there's no point in arguing about this.
> It's a nuisance that the standard Perl map() doesn't transparently
> take a code reference, but you can write
>
> map { $func->($_) } @args
Yes, but in any case, all it took was five or so extra lines of code to
write a map that takes a function reference. Besides, what's one more
function to a functional programmer? =)
> ...snip...
>
> (I don't mean simple 'map' stuff, I mean for more complicated programs
> where you start having multiple layers of fold / map / filter / Maybe
> / curry / uncurry / etc etc. This is easy in Haskell, but very tricky
> in Perl unless you are a programming demigod who rarely makes
> mistakes.)
Can you provide an example of this problem (in Haskell)? I'd like to try a
conversion to Perl so that I might better understand the awkwardness you
describe. If you have a chance.
Peace,
Dave
------------------------------
Date: Sun, 27 Jul 2003 21:05:33 -0000
From: Dave Benjamin <ramen@lackingtalent.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <slrnbi8frk.6eu.ramen@lackingtalent.com>
In article <7fe97cc4.0307261045.6f442296@posting.google.com>, Xah Lee wrote:
> You wrote:
> [morons are just joking with their "theroy vs practice" quote]
That is most certainly *not* what I wrote. Clearly, you like to talk and
don't care to listen, so I have nothing more to say to you. Good luck with
your campaign.
Dave
------------------------------
Date: 27 Jul 2003 02:59:30 -0700
From: contact_bogomil@need.bg (Bogomil Shopov)
Subject: Call for Authors
Message-Id: <c3e19379.0307270159.75e6b9c@posting.google.com>
WebDevMagazine will start in September an international edition of
magazine.If you want to be an author of this magazine please email to
:
authors@webdevmagazine.co.uk the folowing things:
1. Your details - name , age ,...etc
2. Your experience
3. In what topic from Web Development you want to write articles(news,
reviews)
Regards
Bogomil
http://webdevmagazine.co.uk/n/
------------------------------
Date: 27 Jul 2003 08:03:44 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Called as method or subroutine?
Message-Id: <bg0110$s00$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Martien Verbruggen:
> On 26 Jul 2003 06:13:12 GMT,
> Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>> Hmmh, just a sec. Plain functions are subject to inheritance in Perl
>> (they also trigger AUTOLOAD if it exists):
>>
>> ethan@ethan:~$ perl -l
>> package t;
>> require CGI;
>> @ISA = qw/CGI/;
>> package main;
>> print t::h1("test");
>> __END__
>> <h1>test</h1>
>>
>> That makes class-methods and function look even more indistinguishable.
>
> $ cat /tmp/foo.pl
> use strict;
> use warnings;
>
> package Foo;
> sub foo { print "Foo::foo called\n"; }
>
> package Bar;
> @Bar::ISA = qw/Foo/;
>
> package main;
> Bar->foo();
> eval { Bar::foo() };
> print "$@" if $@;
> eval { Bar::foo("Bar") };
> print "$@" if $@;
> eval { Bar::foo("Foo") };
> print "$@" if $@;
> # Indirect syntax:
> Bar::foo Bar;
>
> $ perl /tmp/foo.pl
> Foo::foo called
> Undefined subroutine &Bar::foo called at /tmp/foo.pl line 12.
> Undefined subroutine &Bar::foo called at /tmp/foo.pl line 14.
> Undefined subroutine &Bar::foo called at /tmp/foo.pl line 16.
> Foo::foo called
Hmmh, ok, no inheritance involved here. What I find irritating is that
AUTOLOAD is still involved. The search-sequence of Perl for a method is
usually from left to right @ISA, then UNIVERSAL::method(). Only after
these searches failed AUTOLOAD is triggered (albeit with a warning).
UNIVERSAL::AUTOLOAD() is last in this chain.
When reading the explanation to this warning in perldiag.pod, the
intended behaviour still sounds fishy to me. The only thing that will be
removed in future is the inherited AUTOLOAD, but not the invocation of
AUTOLOAD of the package from which a non-existing function was
requested. Provided that functions do not obey inheritance, they
shouldn't involve AUTOLOAD either IMHO.
> I don't know what extra work CGI.pm does, but to me that looks like @ISA
> does not come into play unless the arrow notation is used (ignoring the
> horror of indirect calling).
In case of CGI, @ISA does come into play in some way:
ethan@ethan:~$ perl
package t;
require CGI;
package main;
t::test();
__END__
Undefined subroutine &t::test called at - line 4.
I haven't been able to figure out why CGI.pm is special. I used require
on purpose to not invoke CGI::import(). I suppose CGI.pm is always a bad
candidate when trying to exhibit Perl's standard behaviour.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 27 Jul 2003 01:53:36 -0700
From: ajsavige@yahoo.com.au (Andrew Savige)
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <f5d2f2e7.0307270053.1b9b4c59@posting.google.com>
Dan Jacobson <jidanni@jidanni.org> wrote in message news:<87oezgreri.fsf@jidanni.org>...
> Say, can this one-liner be squeezed any shorter, aside from removing
> spaces or hardwiring $q's value?
> perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
> Reference: http://jidanni.org/geo/taipower/meter_en.html
I'm assuming you don't want to drop the -w switch.
The -l switch can be dropped.
The BEGIN block can also be dropped (at a cost in performance).
BEGIN{$q=7.2*3600} could be replaced by:
BEGIN{$=*=$=*7.2} and use $= instead of $q (sorry, I just had to do it :-)
This one produces a similar formatting to yours:
#!perl -pw
BEGIN{$q=7.2*3600};s!\d+ +!sprintf"%4d ",$q/$&!e
If you're less strict on formatting, you can shave more, for example:
#!perl -pw
BEGIN{$q=7.2*3600};s!\d+!$q/$&|0!e
/-\
------------------------------
Date: Sun, 27 Jul 2003 13:00:42 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <slrnbi84qa.1u3.tadmc@magna.augustmail.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> On Sun, 27 Jul 2003, Dan Jacobson wrote:
>
>>Say, can this one-liner be squeezed any shorter, aside from removing
>>spaces or hardwiring $q's value?
>
> Well, you ARE hardwiring $q's value. Or do you mean using the expression
> instead of $q?
>
>>perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
^^^^^^^^
^^^^^^^^
I think he means apart from applying constant folding to that expression. ?
(although that would save 3 strokes (chars))
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Jul 2003 20:47:52 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <slrnbi8ejo.bm.abigail@alexandra.abigail.nl>
Dan Jacobson (jidanni@jidanni.org) wrote on MMMDCXVII September MCMXCIII
in <URL:news:87oezgreri.fsf@jidanni.org>:
$$ Say, can this one-liner be squeezed any shorter, aside from removing
$$ spaces or hardwiring $q's value?
$$ perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
You could always drop the BEGIN:
perl -ane'$q=7.2*3600;printf "%4d %s\n",$q/shift @F,"@F"'
Abigail
--
print v74.117.115.116.32;
print v97.110.111.116.104.101.114.32;
print v80.101.114.108.32;
print v72.97.99.107.101.114.10;
------------------------------
Date: 27 Jul 2003 13:44:29 -0700
From: gdsafford@hotmail.com (Greg)
Subject: Concatenation
Message-Id: <a8f367ed.0307271244.44573f87@posting.google.com>
Can someone give me any insight into why
my $s = undef() . '';
executes without complaint in my Perl 5.6 installation. But
my $s = '' . undef();
emits
"Use of uninitialized value in concatenation (.) or string"
Seems to me that I'm using an uninitialized value in either case.
Just curious.
Any information appreciated.
TIA.
Greg
------------------------------
Date: 27 Jul 2003 21:30:27 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Concatenation
Message-Id: <bg1g9j$cvh$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Greg:
> Can someone give me any insight into why
>
> my $s = undef() . '';
>
> executes without complaint in my Perl 5.6 installation. But
>
> my $s = '' . undef();
>
> emits
>
> "Use of uninitialized value in concatenation (.) or string"
>
> Seems to me that I'm using an uninitialized value in either case.
Yes, in both cases it's uninitialized. But the former works because it is
treated specially. There is no warning because it would make things like
this clumsy:
my $var;
for (0 .. 50) {
# in the first iteration this is:
# $var = undef . something()
$var .= something();
}
So it's really just a convenience thing that perl wont warn when you
append something to an unitialized variable.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 27 Jul 2003 06:44:26 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Currying functions (was "theory vs practice" ceases power)
Message-Id: <Xns93C54EC2873DAsdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Ed Avis <ed@membled.com> wrote in news:l1oezgxozo.fsf@budvar.future-
i.net:
> Dave Benjamin <ramen@lackingtalent.com> writes:
>
>>> sub curry( $ ) {
>>> my $f = $_[0];
>>> sub( $ ) { my $x = $_[0]; sub( $ ) { $f->($x, $_[0]) } };
>>> }
>
>>Well, I'd define curry a little differently,
>
> There isn't really any option about how to define it. As far as I
> know the operation 'curry' is defined as
>
> curry f x y = f (x, y)
>
> in other words turning a function which takes a pair into a function
> which takes one argument and returns a function taking the second
> argument.
Pardon me for jumping in here, but....
- From time to time I've heard people discussing currying functions, but
only from either a computer science theoretical point of view, or how to
implement them in Perl (or whatever language).
What the heck would one ever use them for? I mean, in the real world,
not as some funky way to solve the Towers of Hanoi or something.
(As a personal aside, I understand closures and regularly use them in the
real world, so it's not like I can't apply complex functional
structures). :-)
Thanks,
- --
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/AwUBPyO7DmPeouIeTNHoEQLM+gCeMsZHnoGAeH4sGcNds5wLv/IGE8QAoOJF
zkk/mB77VEaJiJkgLHp8+f7V
=0wak
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 27 Jul 2003 12:30:09 +0000 (UTC)
From: Frank Buss <fb@frank-buss.de>
Subject: Re: Currying functions (was "theory vs practice" ceases power)
Message-Id: <bg0gkh$5ef$1@newsreader2.netcologne.de>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
> What the heck would one ever use them for? I mean, in the real
> world, not as some funky way to solve the Towers of Hanoi or
> something.
Assuming you want to convert an internet address from the single byte form
to the 32-bit form (Haskell syntax):
bytesToInt = foldl1 (\x y -> 256*x+y)
Ok, this is syntatic sugar for "bytesToInt z = foldl1 (\x y -> 256*x+y) z",
but if you use combinators, it would be more diffcult to do it without
currying, for example if you want to build XML files:
http://www.cs.york.ac.uk/fp/HaXml/icfp99.html
--
Frank Buß, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
------------------------------
Date: 27 Jul 2003 18:22:35 +0100
From: Ed Avis <ed@membled.com>
Subject: Re: Currying functions (was "theory vs practice" ceases power)
Message-Id: <l1llujyjdw.fsf@budvar.future-i.net>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> writes:
>- From time to time I've heard people discussing currying functions,
>but only from either a computer science theoretical point of view, or
>how to implement them in Perl (or whatever language).
>
>What the heck would one ever use them for?
I think it is mostly a matter of syntax. In Haskell and many other
functional languages function application is simply
f x
not f(x) as in C, Perl etc. If application is left-associative, then
f x y
is the same as
(f x) y
that is, f takes one argument and returns a function taking one
argument, which is then applied to y.
You have a choice of writing a tupled style:
f (a, b) = something
x = f (1, 2)
or a curried style:
f a b = something
x = f 1 2
Purely from syntax the second is a bit cleaner. It also lets you
write things like
g = f 1
newlist = map (f 2) list
to partially apply a function, instead of
g (x, y) = f (1, y)
newlist = map (\y -> f (1, y)) list
or similar workarounds. (The syntax '\x -> r' is a lambda expression
in Haskell.)
In a language that needs more punctuation to call a function, currying
isn't so attractive; you might not enjoy writing f(2)(3) instead of
f(2, 3). But note that C did use a similar idea for array access.
--
Ed Avis <ed@membled.com>
------------------------------
Date: Sun, 27 Jul 2003 20:23:51 GMT
From: Aphor <aphor_noethe@hotmail.com>
Subject: Extend global symbol table in embedded perl
Message-Id: <Xns93C58849837B5postedbyaphor@63.240.76.16>
The 30 second version:
----------------------
Is it possible to add a new function to Perl's global symbol table
somewhere during the perl_(alloc,construct,parse,run) sequence?
The details:
------------
I'm working with a Win32 application that currently has a method for adding
extension DLLs. When the extension is first loaded (which may or may not
be at application startup), it is given pointers to a function AppFunction
(). I'm writing an application extension that contains an embedded perl
interpreter. I would like to make AppFunction() available to the perl
scripts. Looking through the perl source, I /think/ I need to push
something into either Perl->Imodglobal or Perl->Iglobalstash, but I'm not
sure how to get back at that data from the script in order to verify that
I'm correct.
The disclaimer:
---------------
This is my first project embedding perl (unless you count building the
samples in perlembed), so I'm far from an expert.
I've poked through the various PODs, the perl source, the newsgroups, and
various perl books, but haven't noticed anything that addresses the correct
way to do this.
If I'm off-my-rocker and should be looking at a different way to solve the
problem, by all means, please point me in the right direction.
If I haven't provided enough information, let me know and I'll be more
verbose in describing the problem.
Thanks,
Aphor N.
------------------------------
Date: 27 Jul 2003 08:19:50 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: How to pick out words from a non-delimited string?
Message-Id: <bg01v6$sic$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Julian Hsiao:
> Since Perl excels at string parsing, I thought this would be the right
> group to ask my question. If not, I apologize for the confusion.
>
> I want to know if there's an algorithm that picks out the words from a
> string that doesn't delimit each words. For example, given
> "helloworld" outputs "hello world". Ideally, it should also be
> resistant to spelling errors.
>
> So, does such algorithm exist? Better yet, has someone already
> implemented it?
Such an algorithm could only be used as a preprocessors. The result
would still need to be verified by a human. An approach would be to take
a dictionary file and scan the text for any words that are in the
dictionary. If a word has been found, surround it with spaces.
Another, more general approach, would try to do the splitting based on
morphological rules for a given language.
But take the word "deallocate": the above dictionary approach could turn
this into "deal locate". There is a famous example in German where
picking the wrong answer can have pretty devestating effects:
"Urinstinkt" (fragmented like "Ur-Instinkt", a basic/archaic instinct or
somesuch). This word could be fragmented into "Urin stinkt" (urine
stinks): Clearly something you wouldn't want to have lying around in
your scientific essay.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 27 Jul 2003 18:23:52 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: How to pick out words from a non-delimited string?
Message-Id: <bg026n$jctjt$1@ID-202028.news.uni-berlin.de>
Does "therapist" become "the rapist" ???
gtoomey
------------------------------
Date: Sun, 27 Jul 2003 18:43:35 +0200
From: "Evgeny Trifuntov" <boffin@fromru.com>
Subject: Re: How to pick out words from a non-delimited string?
Message-Id: <bg0s0d$ise$1@news2.netvision.net.il>
Hello, Julian!
You wrote on 26 Jul 2003 23:21:52 -0700:
JH> I want to know if there's an algorithm that picks out the words from a
JH> string that doesn't delimit each words. For example, given
JH> "helloworld" outputs "hello world". Ideally, it should also be
JH> resistant to spelling errors.
Well, at least you should make up kind of "dictionary" for your program with
all the words that can be met in your text.
Evgeny Trifuntov
Technion. Israel Institute of Technology
E-mail: boffin@fromru.com
Good Luck, All.
------------------------------
Date: Sun, 27 Jul 2003 10:41:57 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: module and $ARGV help
Message-Id: <qko7iv00fltilv28jhh0tnrphgcdcc7mf4@4ax.com>
On Sat, 26 Jul 2003 17:42:52 GMT, Steve Grazzini <grazz@pobox.com> wrote:
>Eric Amick <eric-amick@comcast.net> wrote:
>> The earlier line
>>
>> my @words = split /\W+/, <> ;
>>
>> read all the data at once, so $ARGV probably won't be useful after
>> that.
>
>That actually puts the readline() into scalar context, so only
>the first file gets slurped. $ARGV will be the name of the first
>file afterward.
I clearly wasn't thinking (again) when I responded. I was having a bad day
when I wrote that. Yeah, that's it. Bad day. :-)
--
Eric Amick
Columbia, MD
------------------------------
Date: Sun, 27 Jul 2003 13:12:20 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: module and $ARGV help
Message-Id: <slrnbi85g4.1u3.tadmc@magna.augustmail.com>
Eric Amick <eric-amick@comcast.net> wrote:
[ snip code that does not work as intended ]
> I clearly wasn't thinking (again) when I responded. I was having a bad day
> when I wrote that. Yeah, that's it. Bad day. :-)
If you merely test your code (again) before offering it to thousands
of people around the world, then such a problem can be avoided
without regard to the goodness of the day in question.
:-) :-)
If you don't want to take the time to test it, then at least mark
it as untested, so folks might be expecting that it does not
do the Right Thing.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 27 Jul 2003 13:15:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help chopping data in Perl
Message-Id: <slrnbi85m0.1u3.tadmc@magna.augustmail.com>
Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> "\"Dandy\" Randy" <ducott@hotmail.com> wrote in
> news:9sEUa.527551$ro6.12239594@news2.calgary.shaw.ca:
>> and remove any data that appears after the first space it encounters -
^^^
^^^
>> including the space itself.
> $name =~ s/ .*//;
$name =~ s/ .*//s;
heh.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 27 Jul 2003 23:45:12 +1000
From: "Sisyphus" <kalinabears@iinet.net.au>
Subject: Re: Perl lib version (v5.6.0) doesn't match executable version (v5.8.0)
Message-Id: <3f23d87a$0$23586$5a62ac22@freenews.iinet.net.au>
"Francesco Moi" <francescomoi@europe.com> wrote in message
news:5b829932.0307260257.730ee1b2@posting.google.com...
> Hello.
>
> On a Linux PC, I'm trying to install libwww-perl, but I get this error
> message when 'make':
>
> -------------
> Perl lib version (v5.6.0) doesn't match executable version (v5.8.0) at
> /usr/lib/perl5/5.6.0/i386-linux/Config.pm line 21.
> Compilation failed in require at
> /usr/lib/perl5/5.6.0/ExtUtils/Install.pm line 10.
> ----------------
Config.pm says you've got version 5.6.0 installed, but the perl executable
is version 5.8.0.
>
> If get my Perl version (perl -v):
> This is perl, v5.6.0 built for i386-linux
>
'perl -v' derives its output from info contained in Config.pm.
To find out what version the perl executable really is, run:
perl -e 'print $];'
If that produces '5.6.0', then I don't know what's going on. If it produces
'5.8.0', then that's what I would expect, but I still don't know what's
going on :-)
Bottom line is that you've somehow achieved a mismatched installation, and
things won't function properly until you get it fixed.
I recommend that you re-install your perl unless you can establish that the
problem can be fixed by some trivial means.
Cheers,
Rob
------------------------------
Date: 27 Jul 2003 12:06:09 -0700
From: phoenix@lanset.com (Phil)
Subject: Perl module for doing text/document comparisons?
Message-Id: <120bf58d.0307271106.518f253c@posting.google.com>
Hi Everyone,
I've been looking for a Perl module that can be used to do document
comparisons. I've done a web search and looked in my perl books, but
can't seem to find the exact animal I'm looking for.
Basically, I'm looking for a Perl module that does the standard
document comparison function found in most word processors. It takes
version 1 of a document and version 2, and does a text scan of the
word/string groups that have been changed, deleted/added. Here's an
example of what I mean:
Version 1 document looks like this:
This is a version 1 document.
Version 2 document looks like this:
Here is a version 2 document. I like it better.
And the output from the Perl module subroutine(s) would like something
like this:
<strike>This</strike><u>Here</u> is a version <strike>1
document.<strike><u>2 document. I like it better.</u>
(Note, if your newsreader doesn't process the HTML codes above, the
<strike></strike> tags indicate the standard line throught the middle
of text marking deleted or changed text, and the <u></u> tags
indicate underline text that has been added from the earlier version
of the document.)
If anyone knows of a Perl module that includes a subroutine that can
compare two documents like the above, I'd greatly appreciate a link or
pointer to it. If an appropriate module could be found, it would be
used for a web-based curriculum project for a community college in
Northern California.
Thanks,
Phil Smith
------------------------------
Date: Sun, 27 Jul 2003 20:35:29 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Perl module for doing text/document comparisons?
Message-Id: <lIWUa.1255$JS2.308@nwrdny03.gnilink.net>
Phil <phoenix@lanset.com> wrote:
> Basically, I'm looking for a Perl module that does the standard
> document comparison function found in most word processors.
I don't know if there's a module to produce that html, but it would
be pretty easy to whip one up with Algorithm::Diff.
--
Steve
------------------------------
Date: Sun, 27 Jul 2003 16:56:30 +1000
From: "Sisyphus" <kalinabears@iinet.net.au>
Subject: Re: use File::Archive extracting zip's with '.' in front of name
Message-Id: <3f2378af$0$23601$5a62ac22@freenews.iinet.net.au>
"david" <dwlepage@yahoo.com> wrote in message
news:b09a22ae.0307261357.1812f9d@posting.google.com...
> I have a script to extract any ZIP files in the current directory. The
> problem is when they are extracted, the program puts a . in front of
> the file names.
>
> #!/usr/bin/perl -w
>
> use strict;
> use Archive::Zip qw(:ERROR_CODES);
>
> opendir(DIR, ".") || die "Can't open local directory : $!";
> my @zips = grep { -f "./$_" } readdir (DIR);
> close(DIR);
> foreach my $zipfiles (@zips) {
> if ($zipfiles =~ /\w+\.zip$/) {
> my $zip = Archive::Zip->new();
> my $zipName = "$zipfiles";
> my $status = $zip->read( $zipName);
> die "Read of $zipName failed\n" if $status != AZ_OK;
> print "$zipfiles\n";
> $zip->extractTree();
> #unlink($zipfiles);
> }
>
> }
>
> If I have a file called a.zip with a file in it called 'a', the script
> will extract it as '.a'
>
I don't think Archive::Zip is supposed to do this - but it does (for me on
Win2k, perl 5.6.1).
> How can I get around this?
>
I think you'll get around it with :
$zip->extractMember($member_name);
See Archive::Zip docs.
Hth,
Cheers,
Rob
------------------------------
Date: Sun, 27 Jul 2003 10:28:22 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Where to hitch the <<EOF to plaster input file?
Message-Id: <k3o7ivsnurl94j93gej47e692hudl6raju@4ax.com>
On Sat, 26 Jul 2003 12:18:00 -0500, tadmc@augustmail.com (Tad McClellan)
wrote:
>Eric Amick <eric-amick@comcast.net> wrote:
>
>> ($p, @F) = split(' ', chomp);
>
>
>split() will always return a 1-element list, regardless of what is in $_.
>
>@F will always get the empty list, regardless of what is in $_.
>
>$p will get either a 1 or a 0 ( if you haven't messed with $/ ).
>
>Man oh man, that bug is going to present itself strangely.
I was trying to be too clever. I wasn't thinking.
Make that
chomp;
($p, @F) = split;
--
Eric Amick
Columbia, MD
------------------------------
Date: Sun, 27 Jul 2003 12:50:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Where to hitch the <<EOF to plaster input file?
Message-Id: <slrnbi847t.1u3.tadmc@magna.augustmail.com>
Eric Amick <eric-amick@comcast.net> wrote:
[ snip: using the return value from chomp() ]
> I wasn't thinking.
If you merely test your code before offering it to thousands of people
around the world, then such a problem can be avoided without the
added effort of thinking.
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 27 Jul 2003 20:17:13 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Win32 Ole
Message-Id: <3F2433D2.75825269@earthlink.net>
I got the following code from the examples on
http://aspn.activestate.com//ASPN/Products/ActivePerl/site/lib/Win32/OLE.html#examples
When I try to run it, it gives me:
Can't find string terminator "Overload" anywhere before EOF at
C:/Perl/lib/Win32/OLE.pm line 29.
Compilation failed in require at excel.pl line 4.
BEGIN failed--compilation aborted at excel.pl line 4.
I see that OLE.pm has "Overload" on line 59 and line 65 and a few
other places, but not anywhere near line 29. Any ideas why this is
not working? I'm very new to modules, but have gotten some to
work in the past.
use strict;
use warnings;
use Win32::OLE;
# use existing instance if Excel is already running
eval {my $ex =
Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined my $ex) {
$ex = Win32::OLE->new('Excel.Application', sub
{$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
my $book = my $ex->Workbooks->Add; #<<<<<<LINE 13
# write to a particular cell
my $sheet = $book->Worksheets(1);
$sheet->Cells(1,1)->{Value} = "foo";
# write a 2 rows by 3 columns range
$sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ],
[ 42, 'Perl', 3.1415 ]];
# print "XyzzyPerl"
my $array = $sheet->Range("A8:C9")->{Value};
for (@$array) {
for (@$_) {
print defined($_) ? "$_|" : "<undef>|";
}
print "\n";
}
# save and exit
$book->SaveAs( 'test.xls' );
undef $book;
undef $ex;
__END__
Mike Flannigan
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5278
***************************************