[28656] in Perl-Users-Digest
Perl-Users Digest, Issue: 10020 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 29 18:06:23 2006
Date: Wed, 29 Nov 2006 15:05:08 -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, 29 Nov 2006 Volume: 10 Number: 10020
Today's topics:
Re: CGI parsing <someone@example.com>
Re: comparing two times using Date::Manip <benmorrow@tiscali.co.uk>
Re: FAQ 1.8 Is Perl difficult to learn? <brian.d.foy@gmail.com>
Re: File open problem <joe@inwap.com>
Re: Hash of arrays & 'values' function <usenet@fkspam.org>
Re: NRN again <justin.0611@purestblue.com>
Re: Perl API to be used as process. <tzz@lifelogs.com>
Re: Perl API to be used as process. <benmorrow@tiscali.co.uk>
Regex failed to replace utf8 character <mccownf@yahoo.com>
Re: Regex failed to replace utf8 character <nobull67@gmail.com>
Re: Regex failed to replace utf8 character <benmorrow@tiscali.co.uk>
Re: Regex failed to replace utf8 character <mccownf@yahoo.com>
Re: Regex failed to replace utf8 character <mccownf@yahoo.com>
RTF::Writer work <mhughes@orsl.co.uk>
Re: run a perl program using actviveperl <benmorrow@tiscali.co.uk>
Re: size of reference octomancer@gmail.com
Re: size of reference <benmorrow@tiscali.co.uk>
String comparison optimization ironmanda@yahoo.com
Re: String comparison optimization <spamtrap@dot-app.org>
Re: String comparison optimization <uri@stemsystems.com>
Re: String comparison optimization jgraber@ti.com
Re: String comparison optimization <benmorrow@tiscali.co.uk>
using DateTime object <clifton_francis@hotmail.com>
Re: using DateTime object <spamtrap@dot-app.org>
Re: using DateTime object <clifton_francis@hotmail.com>
Re: using DateTime object <spamtrap@dot-app.org>
Re: What is a glob variable? <merrile@telus.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Nov 2006 17:23:58 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: CGI parsing
Message-Id: <Omjbh.9765$rv4.7177@edtnps90>
Tad McClellan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>
>>But hey, things have improved. A couple of years ago, when someone
>>revealed that they were using their own code for parsing CGI, about 10
>>regulars told that person that s/he was stupid. Nowadays only one or two
>>regulars do the same thing. ;-)
>
>
> Because there are now eight less regulars!
Probably up north helping Santa this time of the year. :-)
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Wed, 29 Nov 2006 17:16:32 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: comparing two times using Date::Manip
Message-Id: <gsr044-sj8.ln1@osiris.mauzo.dyndns.org>
Quoth JackL <jbl02NO@SPAMgoogle.com>:
>
> This simple fragment will compare $string1 against a later time,
> $string2
>
> strict does not like the bareword CDT, commented out for now.
>
> In this example, if $string2 is 5 seconds or more later than $string1
> ($string2 will always be later than $string1, normally 1 to 3 seconds)
>
> Yes this is very rough.I am now in a fog.
> Date::Manip needs the time zone and strict doesn't like my format.
> What am I doing wrong??
>
> If/when I overcome that I will go back and correct the declaration of
> the variables with "my" and begin using warnings and strict
>
> thanks
> jackL
>
> #use warnings;
> #use strict;
> use Date::Manip;
> $main::TZ=CDT;
You need to quote strings when using 'strict'. So:
$main::TZ = 'CDT';
Personally I would avoid this (using globals is bad enough; using
globals in main:: is just smelly) and either set $ENV{TZ} or call
Data_Init:
Data_Init 'TZ=CDT';
> if ($secondsDiff => 5) {
The greater-than-or-equal operator is '>='. The '=>' operator does
something quite different, and will always return a true value in this
case.
Ben
--
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
-- F.P. Brooks, 'No Silver Bullet', 1987 [benmorrow@tiscali.co.uk]
------------------------------
Date: Wed, 29 Nov 2006 16:47:12 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 1.8 Is Perl difficult to learn?
Message-Id: <291120061647129782%brian.d.foy@gmail.com>
In article <chju34-hlq.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<benmorrow@tiscali.co.uk> wrote:
> Quoth PerlFAQ Server <brian@stonehenge.com>:
> <snip>
> > Things that make Perl easier to learn: Unix experience, almost any kind
> > of programming experience, an understanding of regular expressions, and
> > the ability to understand other people's code. If there's something you
> > need to do, then it's probably already been done, and a working example
> > is usually available for free. Don't forget the new perl modules,
> ^^^
> They aren't exactly 'new' any more :).
I'm not even sure what "new" is supposed to mean. I'll see how I can
update the answer.
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 29 Nov 2006 12:56:06 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: File open problem
Message-Id: <MoOdnWcwlJh6bvDYnZ2dnUVZ_o2dnZ2d@comcast.com>
IJALAB wrote:
>
> I am trying to take the files as command line arguments and do some
> formatting to the files based on their extensions. I am getting error
> in the file open when i use $ARGV[$i]
Don't use $ARGV[$i]. Use shift() or foreach() instead
> Also, I am assigning a fixed name to my files. can i dynamically do
> them based on my input file names?
>
> print $#ARGV;
> $copypath = "<path>";
> for ($i=0;$i<=$#ARGV;$i= $i + 1)
foreach my $file (@ARGV) {
# use proper indenting
}
> $b0 = system("copy $ARGV[$i] $copypath\\scripts");
my $cmd = "copy $file $copypath\\scripts";
print $cmd,"\n";
(system $cmd) == 0 or warn "Command failed: $?";
> $b1 = chdir ("$copypath\\scripts");
Since you don't undo the chdir() later on, that will fail the second
time if $copypath does not start with "\" or "X:\".
> #Error here!!!
> open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";
Of course there is an error. '$file' is not the same as "$file" and
you're using single quotes there. Better to use 3-argument open().
open my $fh,'<',$file or die "Cannot open $file - $!";
------------------------------
Date: Wed, 29 Nov 2006 17:20:59 +0000
From: Ben Tisdall <usenet@fkspam.org>
Subject: Re: Hash of arrays & 'values' function
Message-Id: <IYednV8hM4HmXPDYnZ2dnUVZ8tadnZ2d@bt.com>
anno4000@radom.zrz.tu-berlin.de wrote:
> Ben Tisdall <usenet@fkspam.org> wrote in comp.lang.perl.misc:
>> anno4000@radom.zrz.tu-berlin.de wrote:
>>
>>> Since the machines are the keys of %userlist
>> Ah, but I never said they were. The keys are the users.
>>
>> I either want a list of the machines a particular user is logged into or
>> a list of all machines that are currently logged into. I'd achieved
>> this, my question was really a general one about the 'best' way to
>> dereference arrays within hashes, as the first respondents correctly
>> deduced.
>
> The standard way:
>
> map @$_, values %userlist;
>
>>> If you actually meant to say "...list of all *users* currently logged in"
>>> that's a different story, but then your OP was really misleading.
>>>
>> So it wasn't :)
>
> It wasn't exactly clear either. In particular, the name %userlist seems
> to indicate that the values represent users in some sense.
Ok, I see where you're coming from. Actually the hash started as users
keyed by machines, hence the name, but then got switched up when I
realised that a user might be logged into more than one machine (whereas
the converse would be very unlikely).
Thanks for your contribution.
--
Ben Tisdall
------------------------------
Date: Wed, 29 Nov 2006 21:30:23 +0000
From: Justin C <justin.0611@purestblue.com>
Subject: Re: NRN again
Message-Id: <justin.0611-F19BA9.21302329112006@stigmata>
In article <reviewyourdemo-089898.02444129112006@reader2.panix.com>,
gcr <reviewyourdemo@hotmail.com> wrote:
> > but not if you insist on refusing education.
>
> Give it a rest, newsgroup cop. You made up an argument and you won. I
> will now email a couple of people and rewrite their scripts with CGI.pm
> ;-> Fix it even if it works. timtowtdi
> Thanks for pointing out the original typo, though. That was *cool*.
Bah! That's it. I've had enough.
<plonk>
--
Justin C, by the sea.
------------------------------
Date: Wed, 29 Nov 2006 17:22:52 +0000
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl API to be used as process.
Message-Id: <g69wt5e9ngz.fsf@lifelogs.com>
On 29 Nov 2006, gnitin21@gmail.com wrote:
> I have a design issue where i need to login to Dst machine from Src
> machine using Expect. Dst machine has the perl functions module. This
> perl module requires to be running continously to able to support the
> session handling. With my current understanding we can only call perl
> API's which does not maintain the session. Need idea's how to proceed.
Use something designed for remote calls. SOAP for example (there are
many other RPC protocols these days).
Ted
------------------------------
Date: Wed, 29 Nov 2006 17:39:55 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Perl API to be used as process.
Message-Id: <b8t044-tci.ln1@osiris.mauzo.dyndns.org>
Quoth Ted Zlatanov <tzz@lifelogs.com>:
> On 29 Nov 2006, gnitin21@gmail.com wrote:
>
> > I have a design issue where i need to login to Dst machine from Src
> > machine using Expect. Dst machine has the perl functions module. This
> > perl module requires to be running continously to able to support the
> > session handling. With my current understanding we can only call perl
> > API's which does not maintain the session. Need idea's how to proceed.
>
> Use something designed for remote calls. SOAP for example (there are
> many other RPC protocols these days).
RPC::PlServer is probably simpler if you don't need to interact with
other programs.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* benmorrow@tiscali.co.uk *
------------------------------
Date: 29 Nov 2006 09:25:12 -0800
From: "Frank" <mccownf@yahoo.com>
Subject: Regex failed to replace utf8 character
Message-Id: <1164821112.150529.117460@h54g2000cwb.googlegroups.com>
I'm trying to replace a character from an HTML file I got from Yahoo's
search engine cache. I'm reading in the file line by line and applying
the following regex:
if (utf8::is_utf8($html)) {
print "Is UTF8\n";
}
# Char that I copied and pasted directly from the HTML file
my $special =3D utf8::encode("=C2");
if ($html =3D~ /$special /) {
print "TRUE:\n";
}
if ($html =3D~ s|$special | |g) {
print "REPACED\n";
}
if ($html =3D~ /$special /) {
print "STILL TRUE\n";
}
What I'm seeing is:
Is UTF8
TRUE
REPLACED
STILL TRUE
I don't understand why the character is not being replaced by a space.
I've been working on this for hours. Any help would be much
appreciated.
Frank
------------------------------
Date: 29 Nov 2006 09:56:01 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Regex failed to replace utf8 character
Message-Id: <1164822961.154749.282740@l39g2000cwd.googlegroups.com>
On Nov 29, 5:25 pm, "Frank" <mcco...@yahoo.com> wrote:
> $html =~ s|$special | |g
> I don't understand why the character is not being replaced by a space.
Perhaps because the thing in the LHS of the replacement operator is not
just the character, it's the character followed by a space.
------------------------------
Date: Wed, 29 Nov 2006 17:43:24 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Regex failed to replace utf8 character
Message-Id: <set044-tci.ln1@osiris.mauzo.dyndns.org>
Quoth "Frank" <mccownf@yahoo.com>:
> I'm trying to replace a character from an HTML file I got from Yahoo's
> search engine cache. I'm reading in the file line by line and applying
> the following regex:
>
> if (utf8::is_utf8($html)) {
> print "Is UTF8\n";
> }
>
> # Char that I copied and pasted directly from the HTML file
> my $special = utf8::encode("Â");
>
> if ($html =~ /$special /) {
> print "TRUE:\n";
> }
Just an idea: try adding
if ($html =~ /$special$special /) {
print "Whoops! There are two of them!\n";
}
here. You may also find the idiom
1 while $html =~ s/$special / /g;
useful, which keeps trying to do the replacement until the result
doesn't match.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
benmorrow@tiscali.co.uk The Levellers, 'Believers'
------------------------------
Date: 29 Nov 2006 13:51:06 -0800
From: "Frank" <mccownf@yahoo.com>
Subject: Re: Regex failed to replace utf8 character
Message-Id: <1164837066.127613.164160@h54g2000cwb.googlegroups.com>
Ben,
> 1 while $html =3D~ s/$special / /g;
This causes an infiinite loop. The substitution is simply not being
made. I also tried replacing the copyright character =A9 like so:
my $copy =3D "\x{00a9}";
if ($html =3D~ s|$copy|©|g) {
print "REPLACED COPYRIGHT\n";
}
but no replacement was made.
I also tried this:
$copy =3D utf8::encode("=A9");
if ($html =3D~ s|$copy|©|g) {
print "REPLACED COPYRIGHT\n";
}
and it changed the text
id=3D"copy1"> =C2=A9 2005 Farmer
to
id=3D"copy1">©=A9©2005©Farmer
Notice the =A9 char is still present, but all the spaces were replaced.
Very odd. I have a *lot* of experience with regex in Perl, and I've
never seen this before. Unfortunately, I have very little experience
with utf8 which I believe is at the core of this problem.
If anyone wants to take a look at the file I'm parsing, I've posted it
here:
http://www.cs.odu.edu/~fmccown/buy-online.html
I'm running Perl v5.8.3 on Redhat Linux.
Thanks,
Frank
------------------------------
Date: 29 Nov 2006 14:00:30 -0800
From: "Frank" <mccownf@yahoo.com>
Subject: Re: Regex failed to replace utf8 character
Message-Id: <1164837629.942474.27270@l12g2000cwl.googlegroups.com>
When I posted my previous response using Google Groups, they apparently
changed all my "ampersand copy semicolon" parts into the copyright
symbol. The conversion of the string should look like this:
# Assume X is "ampersand copy semicolon"
id=3D"copy1">X=A9X2005XFarmer
Thanks,
Frank
------------------------------
Date: Wed, 29 Nov 2006 16:22:18 -0000
From: "Sparky" <mhughes@orsl.co.uk>
Subject: RTF::Writer work
Message-Id: <ekkc3k$bpj$1$8302bc10@news.demon.co.uk>
Hi all
Are there any RTF::Writer black belts out there that are able to do some
coding for cash?
I've been using the module for a while with OK results but would like to
improve the aesthetics of the output. To do so requires learning a fair bit
about the RTF syntax and I don't really have the time so was wondering if
anyone out there is interested.
There's a couple of methods in the module that allow you to knock together a
table fairly easily. The downside is fonts, colours, alignment etc can't
easily be controlled. Therefore I'm looking for the production of some
custom methods that produce a better quality output.
It's not a huge amount of work but if succesful I may have additional
requirements in the new year.
Apologies if I'm posting this in the wrong group. If so maybe someone can
point me in the right direction.
Thanks
Mark Hughes
mhughes@orsl.co.uk
------------------------------
Date: Wed, 29 Nov 2006 17:05:53 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: run a perl program using actviveperl
Message-Id: <h8r044-sj8.ln1@osiris.mauzo.dyndns.org>
Quoth quakewang@mail.whut.edu.cn:
>
> I want to know, where talk about the wperl.exe command? Where
> is the document talk about it?
perldoc perlwin32, in the section 'Miscellaneous Things'.
Ben
--
You poor take courage, you rich take care:
The Earth was made a common treasury for everyone to share
All things in common, all people one. [benmorrow@tiscali.co.uk]
'We come in peace'---the order came to cut them down.
------------------------------
Date: 29 Nov 2006 09:31:16 -0800
From: octomancer@gmail.com
Subject: Re: size of reference
Message-Id: <1164821476.878261.277000@80g2000cwy.googlegroups.com>
jtbutler78@comcast.net wrote:
> I have a reference to an array ($ref). Can I get the size in order to
> loop without dereferencing $ref?
>
> I would like to achive this but it seems like it is an extra step to
> dereference it.
> @array = @$ref;
>
> for $i ( 0 .. $#array) ...
That's a C way of iterating over an array. It is more perlish to use
foreach my $element (@$ref) {
# do some stuff ... note $element is an alias for the array element
# and any change to $element is changing the array itself
}
------------------------------
Date: Wed, 29 Nov 2006 17:10:22 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: size of reference
Message-Id: <ugr044-sj8.ln1@osiris.mauzo.dyndns.org>
[quoting fixed. please quote correctly]
Quoth "jtbutler78@comcast.net" <jtbutler78@comcast.net>:
> Lawrence Statton XE2/N1GAK wrote:
> > "jtbutler78@comcast.net" <jtbutler78@comcast.net> writes:
> > > I have a reference to an array ($ref). Can I get the size in order to
> > > loop without dereferencing $ref?
> > >
> > > I would like to achive this but it seems like it is an extra step to
> > > dereference it.
> > > @array = @$ref;
> > >
> > > for $i ( 0 .. $#array) ...
> > >
> >
> > for my $i ( 0 .. $#$ref )
> >
> Before dereferencing, I was trying something like ${#$ref} which I
> understand now why it wasnt working. Thanks.
If you read perlreftut, you will find 'Use Rule 1' (Rule 1 for using
references): You can always use an <array> reference, in curly braces,
in place of the name of an <array>. So:
$#array # a normal array
$#{$aref} # an arrayref
There are some circumstances where you can omit the braces, but as with
parens, if in doubt put them in.
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC benmorrow@tiscali.co.uk
------------------------------
Date: 29 Nov 2006 10:40:16 -0800
From: ironmanda@yahoo.com
Subject: String comparison optimization
Message-Id: <1164825616.356318.80690@h54g2000cwb.googlegroups.com>
I have some code that attempts to match a set A of strings against a
set B of strings,
where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
strings in B,
so there is no early exit criteria. The code is roughly:
foreach my $a (keys %A) {
$a=lc($a);
# Repeat the string 3 times so as to allow up to 3!=6 permutations
# of $b to match
$a.=qq( $a $a);
foreach my $b (keys %B) {
# $b is lowercase already
# Allow string fragments of $b to match anywhere in $a - use .*
# in place of spaces
$b=~s/\s+/\.\*/g;
if ($a=~/$b/) {
&doSomething($a, $b);
}
}
}
Is there a faster way to do this?
David
------------------------------
Date: Wed, 29 Nov 2006 13:50:03 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: String comparison optimization
Message-Id: <m2hcwigk9w.fsf@Sherm-Pendleys-Computer.local>
ironmanda@yahoo.com writes:
> I have some code that attempts to match a set A of strings against a
> set B of strings,
> where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
> strings in B,
> so there is no early exit criteria. The code is roughly:
>
> foreach my $a (keys %A) {
> $a=lc($a);
> # Repeat the string 3 times so as to allow up to 3!=6 permutations
> # of $b to match
> $a.=qq( $a $a);
> foreach my $b (keys %B) {
> # $b is lowercase already
> # Allow string fragments of $b to match anywhere in $a - use .*
> # in place of spaces
> $b=~s/\s+/\.\*/g;
> if ($a=~/$b/) {
> &doSomething($a, $b);
> }
> }
> }
>
> Is there a faster way to do this?
You might try calling study($a) before the loop. As it says in "perldoc -f
study" though, that may or may not help:
study SCALAR
study Takes extra time to study SCALAR ($_ if unspecified) in antici-
pation of doing many pattern matches on the string before it is
next modified. This may or may not save time, depending on the
nature and number of patterns you are searching on, and on the
distribution of character frequencies in the string to be
searched--you probably want to compare run times with and with-
out it to see which runs faster.
Have a look at the perldoc for more.
For comparing run times as suggested above, have a look at the Benchmark.pm
module included with Perl. You might also want to have a look at Devel::DProf
for profiling your code to find bottlenecks.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 29 Nov 2006 13:59:20 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: String comparison optimization
Message-Id: <x764cyaxkn.fsf@mail.sysarch.com>
>>>>> "i" == ironmanda <ironmanda@yahoo.com> writes:
i> I have some code that attempts to match a set A of strings against a
i> set B of strings,
i> where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
i> strings in B,
i> so there is no early exit criteria. The code is roughly:
i> foreach my $a (keys %A) {
i> $a=lc($a);
don't use $a and $b for regular vars (even in examples). they are
reserved for sort. in general single letter var names are bad (with the
exception of $i, $j, etc.). plenty of past threads in here cover that.
i> # Repeat the string 3 times so as to allow up to 3!=6 permutations
i> # of $b to match
i> $a.=qq( $a $a);
i> foreach my $b (keys %B) {
why get the keys each time? they don't change for each outer loop. get
the keys into an array outside the loops and loop over that.
i> # $b is lowercase already
i> # Allow string fragments of $b to match anywhere in $a - use .*
i> # in place of spaces
i> $b=~s/\s+/\.\*/g;
you do this each time in the %A loop when it should be done one
time. move it to the outside of both loops.
also since this will be recompiled into a regex each time, you should
make the array consist of qr// expressions.
i> if ($a=~/$b/) {
i> &doSomething($a, $b);
don't use & to call functions. plenty of past threads in here cover that.
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: 29 Nov 2006 13:22:42 -0600
From: jgraber@ti.com
Subject: Re: String comparison optimization
Message-Id: <yvnfyc22h31.fsf@famous02.dal.design.ti.com>
ironmanda@yahoo.com writes:
> I have some code that attempts to match a set A of strings against a
> set B of strings,
> where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
> strings in B,
> so there is no early exit criteria. The code is roughly:
>
> foreach my $a (keys %A) {
> $a=lc($a);
> # Repeat the string 3 times so as to allow up to 3!=6 permutations
> # of $b to match
> $a.=qq( $a $a);
> foreach my $b (keys %B) {
> # $b is lowercase already
> # Allow string fragments of $b to match anywhere in $a - use .*
> # in place of spaces
> $b=~s/\s+/\.\*/g;
> if ($a=~/$b/) {
> &doSomething($a, $b);
> }
> }
> }
>
> Is there a faster way to do this?
>
> David
You've provided a code example. Thats good.
But its not complete enough to run, because
there is no data provided, ( you could use __DATA__ )
so we have no examples of what your data looks like.
Without examples of your data, it seems likely that your code
fragment does not well represent your real code,
and/or does not represent your true intent.
An example is worth 1000 words of description.
But otherwise, these general comments may help.
1 use of variable names $a and $b is discouraged except inside sort routines.
so pick some other variable name, even in short example code.
2 refactor your loop, or build a new %Bprime hash to search on.
As is, the same operation $b=~s/\s+/\.\*/g;
is applied to the first key of %B ~30,000 times.
The new %Bprime could be precompiled regexps. using qr()
3 There may already be a module to to do hashkey by regexp lookup.
If this is genetics related, there are quite likely modules
for it already.
4 Since you will be doing ~3000 pattern matches on $a,
you could try studying it first. perldoc -f study
5 The biggest time issue is likely the .* in $b
since it seems like they will cause lots of backtracking.
--
jgraber
------------------------------
Date: Wed, 29 Nov 2006 19:10:56 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: String comparison optimization
Message-Id: <0j2144-0o5.ln1@osiris.mauzo.dyndns.org>
Quoth ironmanda@yahoo.com:
> I have some code that attempts to match a set A of strings against a
> set B of strings,
> where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
> strings in B,
> so there is no early exit criteria. The code is roughly:
>
> foreach my $a (keys %A) {
The variables $a and $b are magic (they are used by sort, so you don't
need to predeclare them under 'strict'). It's better to avoid them.
> $a=lc($a);
> # Repeat the string 3 times so as to allow up to 3!=6 permutations
> # of $b to match
> $a.=qq( $a $a);
> foreach my $b (keys %B) {
> # $b is lowercase already
> # Allow string fragments of $b to match anywhere in $a - use .*
> # in place of spaces
> $b=~s/\s+/\.\*/g;
. and * are not magic in double-quoted strings (the RHS of s/// is a
double-quoted string.
> if ($a=~/$b/) {
This will (or may, at any rate) recompile the regex every time. You can
probably make it faster by precompiling it:
$b = qr/$b/;
if ($a =~ $b) {
Are the strings in $b regular expressions, or are they literal strings?
That is, if you have $a = 'aaa' and $b = 'a*', do you want a match or
not? If the latter, then you need to use \Q:
$b = qr/\Q$b/;
You *may* also be able to make it faster by using index, or by splitting
$a and $b into their consitiuent parts and using a hash to match them.
You would need to specify more exactly the sorts of things you are
matching for us to help you with this.
> &doSomething($a, $b);
Don't call subs with & unless you know what it does.
Ben
--
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent?~Feynmann~benmorrow@tiscali.co.uk
------------------------------
Date: 29 Nov 2006 13:16:29 -0800
From: "aswad" <clifton_francis@hotmail.com>
Subject: using DateTime object
Message-Id: <1164834989.776150.279740@n67g2000cwd.googlegroups.com>
Hello, I've installed Perl 5.8.8 to use the DateTime module. Because I
need to subtract 2 dates to get the number of days difference. But I
cannot use the DateTime object. In all the examples I've seen, they are
using the new keyword. When I try this I get the following error: Can't
locate object method "new" via package "DateTime" (perhaps you forgot
to load "DateTime"?) at tt.pl line 17.
Can someone tell me what I'm doing wrong. Here is my code. Thanks.
use lib "C:\\Perl\\lib\\ActiveState";
my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
or
my $dt1 = DateTime->now();
------------------------------
Date: Wed, 29 Nov 2006 16:47:59 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: using DateTime object
Message-Id: <m27ixdhqls.fsf@Sherm-Pendleys-Computer.local>
"aswad" <clifton_francis@hotmail.com> writes:
> Hello, I've installed Perl 5.8.8 to use the DateTime module. Because I
> need to subtract 2 dates to get the number of days difference. But I
> cannot use the DateTime object. In all the examples I've seen, they are
> using the new keyword.
"new" isn't a keyword, it's just a method provided by the DateTime module
that creates a new DateTime object.
> When I try this I get the following error: Can't
> locate object method "new" via package "DateTime" (perhaps you forgot
> to load "DateTime"?) at tt.pl line 17.
>
> Can someone tell me what I'm doing wrong. Here is my code. Thanks.
>
> use lib "C:\\Perl\\lib\\ActiveState";
> my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
> or
> my $dt1 = DateTime->now();
Looks to me like the error already told you precisely what's wrong - you
forgot to use() the DateTime module.
use DateTime;
Also, unless you installed the module in a non-standard location (you'd
know if you did), you don't need to specify any additional library paths
with "use lib". Perl already knows about the standard core and CPAN module
directories.
You would also benefit from reviewing the basics of modules and their use.
Have a look at:
perldoc perlmod
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 29 Nov 2006 13:55:43 -0800
From: "aswad" <clifton_francis@hotmail.com>
Subject: Re: using DateTime object
Message-Id: <1164837343.916356.229180@l39g2000cwd.googlegroups.com>
Sherm Pendley wrote:
> "aswad" <clifton_francis@hotmail.com> writes:
>
> > Hello, I've installed Perl 5.8.8 to use the DateTime module. Because I
> > need to subtract 2 dates to get the number of days difference. But I
> > cannot use the DateTime object. In all the examples I've seen, they are
> > using the new keyword.
>
> "new" isn't a keyword, it's just a method provided by the DateTime module
> that creates a new DateTime object.
>
> > When I try this I get the following error: Can't
> > locate object method "new" via package "DateTime" (perhaps you forgot
> > to load "DateTime"?) at tt.pl line 17.
> >
> > Can someone tell me what I'm doing wrong. Here is my code. Thanks.
> >
> > use lib "C:\\Perl\\lib\\ActiveState";
> > my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
> > or
> > my $dt1 = DateTime->now();
>
> Looks to me like the error already told you precisely what's wrong - you
> forgot to use() the DateTime module.
>
> use DateTime;
>
> Also, unless you installed the module in a non-standard location (you'd
> know if you did), you don't need to specify any additional library paths
> with "use lib". Perl already knows about the standard core and CPAN module
> directories.
>
> You would also benefit from reviewing the basics of modules and their use.
> Have a look at:
>
> perldoc perlmod
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net
Sorry, i do have that statement. I though i had include that line.
use lib "C:\\Perl\\lib\\ActiveState";
use DateTime;
my $dt1 = DateTime->now();
------------------------------
Date: Wed, 29 Nov 2006 17:22:31 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: using DateTime object
Message-Id: <m23b81hp08.fsf@Sherm-Pendleys-Computer.local>
"aswad" <clifton_francis@hotmail.com> writes:
> Sherm Pendley wrote:
>> "aswad" <clifton_francis@hotmail.com> writes:
>>
>> > When I try this I get the following error: Can't
>> > locate object method "new" via package "DateTime" (perhaps you forgot
>> > to load "DateTime"?) at tt.pl line 17.
>> >
>> > Can someone tell me what I'm doing wrong. Here is my code. Thanks.
>> >
>> > use lib "C:\\Perl\\lib\\ActiveState";
>> > my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
>> > or
>> > my $dt1 = DateTime->now();
>>
>> Looks to me like the error already told you precisely what's wrong - you
>> forgot to use() the DateTime module.
>>
>> use DateTime;
>
> Sorry, i do have that statement. I though i had include that line.
Are you saying that you didn't copy-and-paste your real code, as the group
guidelines suggest you do? Why not? You *have* read the guidelines, haven't
you?
Anyway, the error message you included above is Perl is telling you that
you didn't "use DateTime;" before calling its methods. You can think you
included it all you wish - Perl is telling you that in fact you didn't.
If your real code had actually included "use DateTime;", you would have had
one of two results - neither of which would be the error message you reported.
If you don't have the DateTime module installed, you would get a "couldn't
locate DateTime.pm in @INC" error. If you *do* have DateTime installed, and
your script included "use DateTime;", then you would not be getting the error
message above.
> use lib "C:\\Perl\\lib\\ActiveState";
I told you before - you don't need "use lib".
> use DateTime;
You have installed the DateTime module, haven't you? It's not a core module,
it needs to be installed separately. It also needs to be installed correctly.
Since you're using ActiveState, the best way to install it would be through
their PPM package manager:
ppm install DateTime
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 29 Nov 2006 20:22:03 GMT
From: Merrilee Larson <merrile@telus.net>
Subject: Re: What is a glob variable?
Message-Id: <LZlbh.7488$dX4.5511@clgrps13>
On 2006-11-29, anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de>
wrote:
> perlster <perlster@phenix.rootshell.be> wrote in comp.lang.perl.misc:
>> Hi.....
>>
>> I ran across this example code the other day
>>
>> sub my_sub(*some_var);
>>
>> Where in perldoc would I find documentation
>> on this *some_var? TIA....
>
> perldoc perldata, and look for "typeglob". Or wait for Ferry Bolhar's
> extensive perlglobtut, but that will be a while.
>
> Anno
Thank you!
--
duke
------------------------------
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 10020
****************************************