[23399] in Perl-Users-Digest
Perl-Users Digest, Issue: 5617 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 5 03:05:44 2003
Date: Sun, 5 Oct 2003 00:05:11 -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, 5 Oct 2003 Volume: 10 Number: 5617
Today's topics:
Re: A couple of matching questions. (Jay Tilton)
Re: fastest count of instances in string? (Roy Johnson)
Re: fastest count of instances in string? <uri@stemsystems.com>
Re: LWP:UserAgent not working ??? (Bill)
Null value in print string (David G Anderson)
Re: Null value in print string (Tad McClellan)
Re: REGEX (Not allowing file extenstions) or the dot <sts@news.sts>
Re: using PAR (pp) for executables <kalinaubears@iinet.net.au>
Re: using PAR (pp) for executables (The Mosquito ScriptKiddiot)
Re: using PAR (pp) for executables (The Mosquito ScriptKiddiot)
Re: using PAR (pp) for executables <usenet@dwall.fastmail.fm>
Re: using PAR (pp) for executables (The Mosquito ScriptKiddiot)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 05 Oct 2003 02:04:10 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: A couple of matching questions.
Message-Id: <3f7f674c.73948309@news.erols.com>
agoodguygonebad@aol.com (AGoodGuyGoneBad) wrote:
: Q1. I have a string of characters like
:
: $string="aaagggcebbb";
: "cfbbcaaacee"
: "ebccaaaggge"
:
: I need to pass this string to a sub, and return true if
: the characters (repeating or not) are in order.
: That is, if a character occurs anywhere other than beside itself,
: the string fails.
: In the 3 strings above, T,F for c,F for e.
: If true, I need 2 other strings, the characters in the order they appear
: and the a string of the times they appear.
:
: ie "aaagggcmbbb" true "agcmb" "33113" or maybe "3,3,1,1,3" since I'm not sure
: yet if a character will appear more than 9 times.
Kinda confusing. Like, say,
sub foo {
local($_) = @_;
/\G(?=.+$1)/ && return 'F' while /(.)\1*/g;
my(%count, @keys);
$count{$_}++ || push @keys, $_ for /./g;
local $" = '';
return 'T', "@keys", "@count{@keys}";
}
: Q2. I have a string of characters where some repeat and some don't,
: and an array of characters. The string is only made up of characters
: from the array.
:
: I need to match the string, at the begining, with
: a string of repeating characters from the array greater than 4,
: or a string of non repeating characters within the array,
: or a string of reversed non repeating characters within the array.
Good golly.
The third case trivially reduces to the second case, so consider them as
a single problem.
Is there a minimal length requirement for the string of non-repeating
characters?
: I know I can find any repeat with =m/^(.)\1{4,}/;
: and $+ contains what character it found, and length($&) is how many, (I think).
Better to add another set of capturing parentheses and avoid $&.
m/^((.)\2{4,})/
: How can I find if there is a match in the forward or reverse strings?
My thinking:
1. Construct a string from the array elements, starting with the
element that matches the first letter in the target string.
2. XOR the string built in step 1 with the target string.
3. Count how many null ("\c@") characters occur at the beginning of
the string created in the XOR operation.
4. Pluck that many characters from the beginning of the target
string.
5. Reverse the array; perform the first above steps again.
As in,
sub bar {
my($str) = @_;
my @array = qw( a b c d g );
my @matches;
my $c = substr($str, 0, 1);
for(1, 2) {
my $mask;
for( 0..$#array ) {
next unless $array[$_] eq $c;
$mask = join '', @array[ $_ .. $#array ];
last;
}
my($nulls) = ($mask^$str) =~ /^(\c@*)/;
push @matches, substr($str, 0, length $nulls);
@array = reverse @array;
}
return @matches;
}
: short examples
: ie for @array like @array=('a','b','c','d','g');
Are the elements of @array guaranteed to be sorted in ascending order?
Is @array guaranteed to have no duplicated elements?
: $forward=join('',@array);
: $reverse=join('', sort {$b <=> $a} @array);
Reversing a list of items is more easily done with the reverse()
function.
: I've been trying to use matches, and tring to avoid
: long loops using substrings.
Is there a reason to avoid them?
------------------------------
Date: 4 Oct 2003 20:11:48 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: fastest count of instances in string?
Message-Id: <3ee08638.0310041911.21e658bf@posting.google.com>
My results were: about 9-10 sec for your solution, 12 for s///g, and
15 for m//g with an iterator. Code is below for anybody who wants to
try/tweak it. Not as much difference as I had expected, but
noticeable.
#!perl
use strict;
use warnings;
my $string='cacababaA';
my %tr_subs ;
my $count;
for my $i (1 .. 1000000) {
my $char='a';
$count = str($string, $char);
}
print "There are $count of them.\n";
sub mtr {
my ($str, $tr_chars) = @_;
my $count = 0;
++$count while $str=~/a/g;
$count;
}
sub str {
my ($str, $tr_chars) = @_;
$str=~s/$tr_chars//g;
}
sub tr_chars {
my ( $str, $tr_chars ) = @_;
$tr_subs{ $tr_chars } ||= eval 'sub { $str=~tr/$tr_chars// }' ;
$tr_subs{ $tr_chars }->() ;
}
------------------------------
Date: Sun, 05 Oct 2003 04:13:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: fastest count of instances in string?
Message-Id: <x74qyonwyb.fsf@mail.sysarch.com>
>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
RJ> sub str {
RJ> my ($str, $tr_chars) = @_;
RJ> $str=~s/$tr_chars//g;
RJ> }
that still doesn't do anything useful. how many times do you have to be
told that?
RJ> sub tr_chars {
RJ> my ( $str, $tr_chars ) = @_;
RJ> $tr_subs{ $tr_chars } ||= eval 'sub { $str=~tr/$tr_chars// }' ;
and that doesn't interpolate $tr_chars either as it is in single quotes.
it may still works as it has an 'a' in '$tr_chars' but it is slower than
just having 'a' in there.
RJ> $tr_subs{ $tr_chars }->() ;
RJ> }
this is going nowhere slowly. first, learn how to generate subs on the
fly with exactly what you want. try printing out the generated code
first and then do an eval on it. also learn to factor out fixed stuff
like that out of the loop. even an ||= takes time that is reflected in
the benchmarks.
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: 4 Oct 2003 23:22:57 -0700
From: wherrera@lynxview.com (Bill)
Subject: Re: LWP:UserAgent not working ???
Message-Id: <239ce42f.0310042222.7a099698@posting.google.com>
> use INC 'mydir';
Sorry meant
use lib 'mydir';
------------------------------
Date: 4 Oct 2003 19:57:31 -0700
From: anderson@glen-net.ca (David G Anderson)
Subject: Null value in print string
Message-Id: <ea22dbc.0310041857.31e461a5@posting.google.com>
I wish to protect against a null value in the print string below:
foreach my $result (@{$response->{Details}}) {
print
join "\n",
$result->{ProductName}[0]||"no title",
$result->{Asin}[0] . "\t" .
$result->{ListPrice}[0] . "\n\n";
}
Error message when ListPrice is null:
"Use of uninitialized value in concatenation (.) or string at ... "
David Anderson
------------------------------
Date: Sat, 4 Oct 2003 22:25:05 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Null value in print string
Message-Id: <slrnbnv3oh.5ej.tadmc@magna.augustmail.com>
David G Anderson <anderson@glen-net.ca> wrote:
> I wish to protect against a null value in the print string below:
>
> foreach my $result (@{$response->{Details}}) {
$result->{ListPrice}[0] = '' unless defined $result->{ListPrice}[0];
> print
> join "\n",
> $result->{ProductName}[0]||"no title",
> $result->{Asin}[0] . "\t" .
> $result->{ListPrice}[0] . "\n\n";
> }
>
> Error message when ListPrice is null:
>
> "Use of uninitialized value in concatenation (.) or string at ... "
That is a *warning* message, not an error message.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 05 Oct 2003 06:07:42 GMT
From: "sts" <sts@news.sts>
Subject: Re: REGEX (Not allowing file extenstions) or the dot
Message-Id: <OyOfb.3055$Ll1.1180@newssvr17.news.prodigy.com>
Darren,
I just want to say thankyou for responding. You helped me solve my problem.
One of the REGEX that you gave me worked.
RE:^lrcon.*[.] # This one worked.
RE:^lrcon.*\. # This did not work.
RE:\. # I didn't try this one because the first one worked.
I was just wondering tho out of curiosity, How would I allow the period
inside a string but only Disallow certain letters & numbers in
a particlular sequence. Say I only wanted to disallow cetain extension only
like:
DISALLOW THE FOLLOWING BUT ACCEPT ANYTHING ELSE:
bsp
123
AdF
1A2
Again this is now allowing the '.' to be in the string but doing an Exact
Match for the extension.
Thank you
sts
"Darren Dunham" <ddunham@redwood.taos.com> wrote in message
news:DOnfb.270$%S1.42855670@newssvr21.news.prodigy.com...
> sts@news.sts wrote:
> > ;RE:^say.*
>
> > I DO NOT WANT TO ALLOW THIS: ".bsp" QUAKE SERVER ONLY NEEDS THE MAP NAME
WHICH IS THE NAME OF THE FILE AND
> > NOT THE '.' NOR THE 'BSP'. I WANT TO TOTALLY BAN, ".BSP" part of the
client's command sent to the server.
>
> > lrcon map map q2dm1.bsp
>
> The question I have is whether you have any command where a period
> should appear. If you don't, then just ban all periods. The problem is
> that periods are usually special in regular expressions, and I can only
> guess that this module and perl use similar syntax.
>
> RE:\. # Ban any command with a period.
>
> If that's too limiting, then this (might) ban anything starting with
> lrcon that has a period elsewhere on the line.
>
> RE:^lrcon.*\.
>
> Again, syntax issues for RE are very dependent on what engine is in
> use. Hopefully a backslash escapes the period here, but it might not.
>
> It is possible that
> RE:^lrcon.*[.]
> would work if the above did not..
>
> --
> Darren Dunham ddunham@taos.com
> Unix System Administrator Taos - The SysAdmin Company
> Got some Dr Pepper? San Francisco, CA bay area
> < This line left intentionally blank to confuse you. >
------------------------------
Date: Sun, 05 Oct 2003 11:47:05 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: using PAR (pp) for executables
Message-Id: <3f7f78d0$0$23586$5a62ac22@freenews.iinet.net.au>
The Mosquito ScriptKiddiot wrote:
> thanks, but i think theres a problem with my installation...here is what it
> shows when i type in perl makefile.pl:
>
> *** ExtUtils::AutoInstall version 0.54
> *** Checking for dependencies...
> [Core Features]
> - File::Temp ...loaded. (0.12)
> - Compress::Zlib ...loaded. (1.16 >= 1.14)
> - Archive::Zip ...failed! (needs 1)
> - Module::ScanDeps ...failed! (needs 0.3)
> - PAR::Dist ...failed! (needs 0.05)
> ==> Do you wish to install the 3 mandatory module(s)? [y] y
> *** Dependencies will be installed the next time you type 'nmake'.
> *** ExtUtils::AutoInstall configuration finished.
> Writing Makefile for PAR
> Warning: prerequisite Archive::Zip 1 not found at
> C:/Perl/lib/ExtUtils/MakeMaker
> .pm line 343.
> Warning: prerequisite Module::ScanDeps failed to load: Can't locate
> Module/ScanD
> eps.pm in @INC (@INC contains: inc C:/Perl/lib C:/Perl/site/lib) at (eval 20)
> li
> ne 3.
> Warning: prerequisite PAR::Dist failed to load: Can't locate PAR/Dist.pm in
> @INC
> (@INC contains: inc C:/Perl/lib C:/Perl/site/lib) at (eval 21) line 3.
> Usage: xsubpp [-v] [-C++] [-except] [-prototypes] [-noversioncheck]
> [-nolinenumb
> ers] [-nooptimize] [-noinout] [-noargtypes] [-s pattern] [-typemap typemap]...
> f
> ile.xs
>
> i think it has to do with those warnings...how do i fix it!!
>
Possibly by simply entering nmake straight after. At least, that's the
claim it's making :-)
You possibly already have Archive::Tar - but not a sufficiently recent
version. But it looks like you don't have the other 2 at all.
Running nmake should install those modules for you and might also
install a pre-compiled version of PAR, which you'll need if you don't
have your own MSVC++ compiler. (If you don't have that compiler, and you
get prompted about accepting the pre-built version, then accept the
invitation.)
You can get nmake from:
http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
(if you don't already have it).
So, grab and install nmake, then run nmake (from the same directory
where you ran 'perl Makefile.PL') and see how it goes.
Some of those prerequisite modules might be available via ppm if you
need to resort to that.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 05 Oct 2003 03:12:07 GMT
From: anotherway83@aol.comnospam (The Mosquito ScriptKiddiot)
Subject: Re: using PAR (pp) for executables
Message-Id: <20031004231207.16492.00000188@mb-m19.aol.com>
>Possibly by simply entering nmake straight after. At least, that's the
>claim it's making :-)
>
>You possibly already have Archive::Tar - but not a sufficiently recent
>version. But it looks like you don't have the other 2 at all.
>
>Running nmake should install those modules for you and might also
>install a pre-compiled version of PAR, which you'll need if you don't
>have your own MSVC++ compiler. (If you don't have that compiler, and you
>get prompted about accepting the pre-built version, then accept the
>invitation.)
>
>You can get nmake from:
>http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
>(if you don't already have it).
>
>So, grab and install nmake, then run nmake (from the same directory
>where you ran 'perl Makefile.PL') and see how it goes.
>
>Some of those prerequisite modules might be available via ppm if you
>need to resort to that.
>
>Cheers,
>Rob
thanks...i already have nmake...i will try that and let u know!
later
--The Mosquito Scriptkiddiot.
"I wish I was a glow worm
A glow worm's never glum
'Cos how can you be grumpy
When the sun shines out your bum!"
------------------------------
Date: 05 Oct 2003 03:28:55 GMT
From: anotherway83@aol.comnospam (The Mosquito ScriptKiddiot)
Subject: Re: using PAR (pp) for executables
Message-Id: <20031004232855.11972.00000329@mb-m03.aol.com>
>>Possibly by simply entering nmake straight after. At least, that's the
>>claim it's making :-)
>>
>>You possibly already have Archive::Tar - but not a sufficiently recent
>>version. But it looks like you don't have the other 2 at all.
>>
>>Running nmake should install those modules for you and might also
>>install a pre-compiled version of PAR, which you'll need if you don't
>>have your own MSVC++ compiler. (If you don't have that compiler, and you
>>get prompted about accepting the pre-built version, then accept the
>>invitation.)
>>
>>You can get nmake from:
>>http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
>>(if you don't already have it).
>>
>>So, grab and install nmake, then run nmake (from the same directory
>>where you ran 'perl Makefile.PL') and see how it goes.
>>
>>Some of those prerequisite modules might be available via ppm if you
>>need to resort to that.
>>
>>Cheers,
>>Rob
>
>thanks...i already have nmake...i will try that and let u know!
>
>later
ok tried it and its not working...here is the output when i type in nmake right
after all that stuff that gets outputted (after typing perl makefile.pl):
Microsoft (R) Program Maintenance Utility Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.
Can't locate object method "extractTree" via package "Archive::Zip::Archive"
(pe
rhaps you forgot to load "Archive::Zip::Archive"?) at inc/Module/Install/PAR.pm
- /usr/local/lib/perl5/site_perl/5.8.0/Module/Install/PAR.pm line 97.
NMAKE : fatal error U1077: 'C:\PERL\BIN\PERL.EXE' : return code '0xff'
Stop.
i dont know what it means by 'load "Archive::Zip::Archive"'
i'm using the ActiveState port of Perl and i'm aware of ppm (ppm2 and ppm3)
that come with it...supposedly they make installing modules a breeze but for
the life of me i couldn't figure out how (yes i read and followed the
instructions in the html help files that come with the installation)...i was
able to create a 'repository' called 'par' which was the folder
c:\windows\desktop\par-0.75 on my computer. then i tried to use the 'search *'
thing to find packages in that folder but it wouldnt find it...for one thing
what name am i even supposed to supply as the argument to get this thing to
work...at my wits end here
thanks for any help
--The Mosquito Scriptkiddiot.
"I wish I was a glow worm
A glow worm's never glum
'Cos how can you be grumpy
When the sun shines out your bum!"
------------------------------
Date: Sun, 05 Oct 2003 05:21:56 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: using PAR (pp) for executables
Message-Id: <Xns940BDE2F1935dkwwashere@216.168.3.30>
anotherway83@aol.comnospam (The Mosquito ScriptKiddiot) wrote:
> i'm using the ActiveState port of Perl and i'm aware of ppm (ppm2 and
> ppm3) that come with it...supposedly they make installing modules a
> breeze but for the life of me i couldn't figure out how (yes i read and
> followed the instructions in the html help files that come with the
> installation)...
Like this:
C:\>ppm
PPM - Programmer's Package Manager version 3.1.
Copyright (c) 2001 ActiveState SRL. All Rights Reserved.
Entering interactive shell. Using Term::ReadLine::Stub as readline
library.
Type 'help' to get started.
ppm> install PAR
------------------------------
Date: 05 Oct 2003 06:19:41 GMT
From: anotherway83@aol.comnospam (The Mosquito ScriptKiddiot)
Subject: Re: using PAR (pp) for executables
Message-Id: <20031005021941.06966.00000266@mb-m20.aol.com>
>Like this:
>
>
>C:\>ppm
>PPM - Programmer's Package Manager version 3.1.
>Copyright (c) 2001 ActiveState SRL. All Rights Reserved.
>
>Entering interactive shell. Using Term::ReadLine::Stub as readline
>library.
>
>Type 'help' to get started.
>
>ppm> install PAR
thanks!!! works like a charm now...feel like an idiot but whatever!
thanks also to all those who offered their help!
btw, i needed this because i am building my own assembler and will be using
perl to do the parsing and stuff...
thanks!
--The Mosquito Scriptkiddiot.
"I wish I was a glow worm
A glow worm's never glum
'Cos how can you be grumpy
When the sun shines out your bum!"
------------------------------
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 5617
***************************************