[25572] in Perl-Users-Digest
Perl-Users Digest, Issue: 7816 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 23 06:10:38 2005
Date: Wed, 23 Feb 2005 03:10:30 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 23 Feb 2005 Volume: 10 Number: 7816
Today's topics:
How to disable importing with "use module qw/.../" stat <snail@localhost.com>
Re: How to disable importing with "use module qw/.../" <phaylon@dunkelheit.at>
How to handle " use module qw/abc/ " in the module ? <snail@localhost.com>
Legitimate use of calling a sub as &sub <richard@zync.co.uk>
OOP Tutorial <leslievNO@SPAMicoc.co.za>
Perl Hash problem (with registry) thomasjbs@yahoo.com
Re: Perl Hash problem (with registry) <zen13097@zen.co.uk>
Re: perl null value ? <tadmc@augustmail.com>
Re: perl null value ? <tadmc@augustmail.com>
Re: perl null value ? <do-not-use@invalid.net>
Re: Regex for "search query" string nick.p.doyle@gmail.com
Re: Regex for "search query" string <zen13097@zen.co.uk>
Re: Regular expression problem <gwillem@gmail.com>
Re: Return HTML between tags with HTML::TokeParser ? <sholden@flexal.cs.usyd.edu.au>
Re: Return HTML between tags with HTML::TokeParser ? <1usa@llenroc.ude.invalid>
unicode: =?ISO-8859-1?Q?=E9=3D=3Ee=2C_=E1=3D=3Ea?= <pilsl@goldfisch.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Feb 2005 02:27:44 -0800
From: "Snail" <snail@localhost.com>
Subject: How to disable importing with "use module qw/.../" statement ?
Message-Id: <cvhlpu$g3r$1@news.astound.net>
"Snail" <snail@localhost.com> wrote in message
news:cvhldj$fsh$1@news.astound.net...
>
> So how can I make it if it is written 'use Test qw/Func1/;' *only*
> Func1
> is imported? (Same for Func2.) And if nothing is passed, ie 'use
> Test;'
> then import all?
>
> In other words how do you see/handle what is "passed" in the 'use'
> line?
>
> Thanks for any help. It's driving my crazy!
>
> Thanks for any help.
Ok I'm sorry, it seems to do it automatically.
But here is a good question, how do you make it so it doesn't import
anyting? I tried pasing na empty list: qw//
but that didn't work. Is it posible to pass something like qw/none/ and
make it not import?
------------------------------
Date: Wed, 23 Feb 2005 11:57:58 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: How to disable importing with "use module qw/.../" statement ?
Message-Id: <pan.2005.02.23.10.57.58.741458@dunkelheit.at>
Snail wrote:
> But here is a good question, how do you make it so it doesn't import
> anyting? I tried pasing na empty list: qw// but that didn't work. Is it
> posible to pass something like qw/none/ and make it not import?
<perldoc -f use> says
If you do not want to call the package's "import"
method (for instance, to stop your namespace from
being altered), explicitly supply the empty list:
use Module ();
That is exactly equivalent to
BEGIN { require Module }
--
http://www.dunkelheit.at/
The mind is its own place, and in itself
Can make a heaven of hell, a hell of heaven. -- Milton, »Paradise Lost«
------------------------------
Date: Wed, 23 Feb 2005 02:21:09 -0800
From: "Snail" <snail@localhost.com>
Subject: How to handle " use module qw/abc/ " in the module ?
Message-Id: <cvhldj$fsh$1@news.astound.net>
I've been going up and down the perldoc and google-groups but can't
figure this one out.
Right now I export functions with Exporter like so:
===============================
Package Test;
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(Func1 Func2);
}
===============================
and in the main package:
===============================
#!/usr/local/bin/perl -w
use strict;
use Test;
Func1{};
Func2();
===============================
this works fine.
But how do you go about making which of these funcs to import
selectable? As in wanting to just import Func1 or Func2? I've seen code
that uses something like
use Module qw/somefunc/;
So how can I make it if it is written 'use Test qw/Func1/;' *only* Func1
is imported? (Same for Func2.) And if nothing is passed, ie 'use Test;'
then import all?
In other words how do you see/handle what is "passed" in the 'use' line?
Thanks for any help. It's driving my crazy!
Thanks for any help.
------------------------------
Date: Wed, 23 Feb 2005 09:38:42 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Legitimate use of calling a sub as &sub
Message-Id: <pan.2005.02.23.09.38.41.770028@zync.co.uk>
Hi all,
Below is a program to calculate the cubic root of a number by
Newton-Raphson which I knocked up to post to the "cubic root subroutine"
thread below. I noticed that the nr function passed 2 of its 3 arguments
unchanged when it recursed. It occured to me that this might be a
legitimate use of using &nr to recurse, having altered the one argument in
@_ which did change. I was just wondering if this is bad style, because I
changed @_, or if it is acceptable ... any comments anyone?
Rich
#!/usr/bin/perl
use strict;
use warnings;
# Program to find the cubic root of a number using the Newton-Raphson
# method for approximating the roots of polynomials
#
# Here, f(x) = x**3 - n where n is the number to be rooted
# thus f'(x) = 3x**2
#
# [ f'(x) is the first differential of f(x) wrt x ]
my $findcubicrootof = $ARGV[0] || 27;
my $first_guess = $findcubicrootof / 3;
my $accuracy = 0.00000001;
# Arbitrarily set to what works on my machine. YMMV
die "Accuracy exceeds machine limits\n" if ($accuracy < 1e-15);
print "The cubic root of $findcubicrootof is ",
nr($first_guess,$findcubicrootof,$accuracy),
" +/- $accuracy\n";
sub nr {
my ($guess,$n,$accuracy) = @_;
# Find delta
my $delta = fofx($guess,$n) / fdashofx($guess,$n);
if (abs($delta) < $accuracy) {
return $guess;
} else {
$_[0] = $_[0] - $delta;
return &nr;
}
}
# Returns f(x)
sub fofx {
my ($x,$n) = @_;
return $x ** 3 - $n;
}
# Returns f'(x)
sub fdashofx {
my ($x,$n) = @_;
return 3 * $x ** 2;
}
------------------------------
Date: Wed, 23 Feb 2005 11:08:40 +0200
From: Leslie Viljoen <leslievNO@SPAMicoc.co.za>
Subject: OOP Tutorial
Message-Id: <GdGdnSF2MveG1YHfRVn-vA@is.co.za>
Hi All
Please forgive the cross-post, I hear comp.lang.perl is defunct.
Anyway, I have written yet another Perl OOP tutorial. If you are
interested, I'd appreciate your comments on it:
http://www.icon.co.za/~mobeus/easyoop.doc.zip (Word)
http://www.icon.co.za/~mobeus/easyoop.sxw.zip (Open Office)
Thanks,
Leslie Viljoen
------------------------------
Date: 23 Feb 2005 00:02:27 -0800
From: thomasjbs@yahoo.com
Subject: Perl Hash problem (with registry)
Message-Id: <1109145747.375288.82950@g14g2000cwa.googlegroups.com>
Getting strange error message: "Can't coerce array into hash at test.pl
line 21 with the following code: (line 22 with added comment)
I'm very new at using hashes and Perl on registry. The strange part is
that it gets through processing about 50 items before the error occurs.
The goal is to simply read the registy and print out a list of
installed applications. Although there might be simple methods to do
this, the secondary goal is to learn to use hashes.
Apparently the data is stored as a hash inside a hash.
Anyone know what's going on?
(run on Windows XP system with Activestate perl).
use Win32::Registry;
my $Register =
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
my ($hkey, @key_list, $key, @klist);
$cnt = 0;
$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;
$hkey->GetKeys(\@key_list);
print "$Register keys\n";
foreach $key (@key_list)
{
$tmpkey = $Register . "\\" . $key . $DisplayName;
$HKEY_LOCAL_MACHINE->Open($tmpkey,$q) or next;
$q->GetValues(\%klist);
#print $klist{'Display Name'},"\n";
while (($k,$d)=each(%klist)) {
if (lc $k eq "display name") {
print $tmpkey,"\n";
print $d,"\n";;
### Error is next line ###
$d = %$d;
print $k," ",$d,"\n";
#@e = %$d;
}
}
$q->Close();
# $cnt++;
print "$key\n";
}
print $cnt;
$hkey->Close();
------------------------------
Date: 23 Feb 2005 08:59:43 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Perl Hash problem (with registry)
Message-Id: <421c45ff$0$32616$db0fefd9@news.zen.co.uk>
On 23 Feb 2005 00:02:27 -0800, thomasjbs@yahoo.com <thomasjbs@yahoo.com> wrote:
> Getting strange error message: "Can't coerce array into hash at test.pl
> line 21 with the following code: (line 22 with added comment)
> $q->GetValues(\%klist);
...
> while (($k,$d)=each(%klist)) {
...
> $d = %$d;
What do you expect that last line to do?
I know nothing about Win32::Registry, but according to the docs:
GetValues:
Populates the supplied hash reference with entries of the form
$value_name => [ $value_name, $type, $data ]
i.e. the value of each entry ($d in your code) is an array ref. You
are dereferencing it as though it was a hash ref.
Instead of:
> $d = %$d;
> print $k," ",$d,"\n";
try:
print "key: $k - $name: $d->[0] type: $d->[1] data: $d->[2]";
(untested).
------------------------------
Date: Tue, 22 Feb 2005 17:04:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl null value ?
Message-Id: <slrnd1nejm.37o.tadmc@magna.augustmail.com>
jeremiah johnson <jjohnson@psg.com> wrote:
> take your elitist attitude and shove it.
That is pretty anti-social of you.
Why not post the way everybody else likes instead of the way you like?
Everybody else is supposed to conform to _you_ rather than
the other way around?
That is an unreasonable expectation, you are likely to be disappointed.
I recommended that you read the Posting Guidelines before posting to avoid
becoming widely killfiled.
That didn't work in this case. :-(
*plonk*
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 22 Feb 2005 17:07:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl null value ?
Message-Id: <slrnd1neot.37o.tadmc@magna.augustmail.com>
jeremiah johnson <jjohnson@psg.com> wrote:
> Paul Lalli wrote:
>> "jeremiah johnson" <jjohnson@psg.com> wrote in message
>> news:VAJSd.16835$g44.4652@attbi_s54...
>>
>> Please do not top quote. Thank you.
> take your elitist attitude and shove it.
Asking the many to conform to the few is elitist.
_You_ are the one being elitist here!
> i will not be reposting.
Thank you for doing your part to make this a better newsgroup.
( I am shocked at appalled at your followup. You seemed
well adjusted in person.)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 23 Feb 2005 10:02:45 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: perl null value ?
Message-Id: <yzdis4jzm16.fsf@invalid.net>
Alexandre Jaquet <alexj@floor.ch> writes:
> Hi how can make a test if ($var ne null) { print "not null"; } when
> I'm doing that I got the following error msg :
>
> bareword "NULL" not allowed while "strict subs" in use at
You can't have gotten a message about "NULL" when your code contains
"null". Perl is case sensitive.
As others have said, Perl doesn't define the word "null" to mean
anything in particular, but note that the documentation often uses
"null" as an adjective to mean "empty", as in "null string" or "null
list".
------------------------------
Date: 23 Feb 2005 00:25:06 -0800
From: nick.p.doyle@gmail.com
Subject: Re: Regex for "search query" string
Message-Id: <1109147106.737013.18730@f14g2000cwb.googlegroups.com>
>Matches go left to right in Perl, so put the thing you want
to match first leftmost.
Cheers Tad.
------------------------------
Date: 23 Feb 2005 08:44:58 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Regex for "search query" string
Message-Id: <421c4289$0$32616$db0fefd9@news.zen.co.uk>
On 22 Feb 2005 11:10:31 -0800, nick.p.doyle@gmail.com
<nick.p.doyle@gmail.com> wrote:
> In code it would be something like :
> $query = "betty and \"the jets\";
> while /super regex here/
> print $1;
>
> To be displaying :
> "the jets"
> " and "
^ ^
Where did those quotes come from?
> betty
If you want (almost) that output from that input:
#!/usr/bin/perl
use strict;
use warnings;
print map { qq('$_'\n) } reverse split /( and )/, q(betty and "the jets");
__END__
outputs:
'"the jets"'
' and '
'betty'
I suspect what you really need is some sort of parser though.
If you were using Perl, Parse::RecDescent could do the job.
------------------------------
Date: Wed, 23 Feb 2005 10:16:18 +0100
From: Willem <gwillem@gmail.com>
Subject: Re: Regular expression problem
Message-Id: <421c49e2$0$28994$e4fe514c@news.xs4all.nl>
Gunnar Hjalmarsson wrote:
> Would this possibly do it?
>
> s{(\([^|)]+(?:\|[^|)]+)+\))|(.)}{
> my $hexenc = sub { sprintf '%2x', ord $_[0] };
> if ($2) { $hexenc->($2) }
> else { local $_ = $1; s/([^(|)])/$hexenc->($1)/eg; $_ }
> }eg;
Yes, exactly! Thank you very much!
Willem
------------------------------
Date: 23 Feb 2005 02:25:41 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: Return HTML between tags with HTML::TokeParser ?
Message-Id: <slrnd1nqd5.o7h.sholden@flexal.cs.usyd.edu.au>
On Wed, 23 Feb 2005 01:50:02 GMT, Michael Wagg <maqo@umich.edu> wrote:
> A. Sinan Unur wrote:
>
>>>my $p = HTML::TokeParser->new("file.txt" || die "Can't open file.");
>>
>> Cute but counter-productive. Please post real code.
>
> With the exception of the input filename (which was changed from
> "digest.html"), this is the exact code being used.
That's a really silly || with a constant true value on the left.
Why would you bother with code that can not be executed? Especially
when all it could possibly serve to do is to trick other people,
and perhaps yourself, into thinking there's error checking when
there isn't.
--
Sam Holden
------------------------------
Date: Wed, 23 Feb 2005 10:07:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Return HTML between tags with HTML::TokeParser ?
Message-Id: <Xns9606341C9691Fasu1cornelledu@127.0.0.1>
Michael Wagg <maqo@umich.edu> wrote in news:ejRSd.9825$rB3.2454645
@twister.nyc.rr.com:
> A. Sinan Unur wrote:
>
>>>my $p = HTML::TokeParser->new("file.txt" || die "Can't open file.");
>>
>> Cute but counter-productive. Please post real code.
>
> With the exception of the input filename (which was changed from
> "digest.html"), this is the exact code being used.
my $p = HTML::TokeParser->new("file.txt")
or "Can't open file.";
>>>while (my $t = $p->get_tag("a")) {
>>>my $name = $t->[1]{name};
>>>next unless $name && ($name eq "anchor");
Now I realize why it doesn't return anything: There are no anchors named
'anchor' in the data you provided.
Sorry, I don't have time to look at the rest of the stuff right now.
------------------------------
Date: Wed, 23 Feb 2005 11:23:40 +0100
From: peter pilsl <pilsl@goldfisch.at>
Subject: unicode: =?ISO-8859-1?Q?=E9=3D=3Ee=2C_=E1=3D=3Ea?=
Message-Id: <421c59bc@e-post.inode.at>
I'm working on a project, that is fully implemented in unicode. We need
to support non-unicode-able terminals in a very spartanic way. By now we
simple nuke everything that is not [a-z0-9] for these terminals.
But I think it could be done a bit better by replacing common unicodes
by their latin "nearbyes" like é=>e, á=>a ...
Is there any easy trick or a module that can do this?
thnx,
peter
ps: in fact we have the trouble that some IE-apple cannot display
unicode in dropdowns ...
--
http://www2.goldfisch.at/know_list
------------------------------
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 7816
***************************************