[19658] in Perl-Users-Digest
Perl-Users Digest, Issue: 1853 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 1 21:05:34 2001
Date: Mon, 1 Oct 2001 18: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)
Message-Id: <1001984708-v10-i1853@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 1 Oct 2001 Volume: 10 Number: 1853
Today's topics:
Re: ACM programming contest (Randal L. Schwartz)
Re: ACM programming contest <usenet@engelke.com>
Algorithm/Module for improving poor RegExps? <markus.cl@gmx.de>
Re: Algorithm/Module for improving poor RegExps? <jeffp@crusoe.net>
Re: Algorithm/Module for improving poor RegExps? (Mark Jason Dominus)
Re: Algorithm/Module for improving poor RegExps? <jeffp@crusoe.net>
Re: DBI/SQL trouble... <goldbb2@earthlink.net>
Re: Embed Sound into cgi? <goldbb2@earthlink.net>
Re: GIF encoding <nobody@nowhere.com>
how can i do site to site FTP transfer (FXP) <centaurez@ifrance.com>
Re: how can i do site to site FTP transfer (FXP) <gerard@NOSPAMlanois.com>
how to get rid of spaces around a string? <yah00204052@yahoo.com>
Re: how to get rid of spaces around a string? <ronh@iainc.com>
Re: how to send mail without sendmail (Abigail)
Re: IE vs. Netscape problems in perl <tintin@snowy.calculus>
Re: IE vs. Netscape problems in perl (Chas Friedman)
Re: Offtopic: DMCA and perldoc perlsec <goldbb2@earthlink.net>
Re: Pattern Matching (shaz)
Re: Pattern Matching <goldbb2@earthlink.net>
Re: Perl semaphore IPC package real world stability (Abigail)
Re: Perl Tk and Pack Problems (Clinton A. Pierce)
POSIX' sprintf doesn't regard locale? <arifsaha@yahoo.com>
POST REDIRECT, was Re: URL forwarding <flavell@mail.cern.ch>
Re: question of copyright <iltzu@sci.invalid>
Re: Sorting multidimensional arrays and MIN/MAX <bigusAT@btinternetDOT.com>
Re: Sorting multidimensional arrays and MIN/MAX (Randal L. Schwartz)
Re: splitting a very wide report (Abigail)
Re: unpack(), etc - programming question (noident)
Re: URL forwarding <iltzu@sci.invalid>
Using TAB - Newbie Question (Daniel Riveong)
Re: Using TAB - Newbie Question <wyzelli@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 01 Oct 2001 15:19:43 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: ACM programming contest
Message-Id: <m1zo7bc8ao.fsf@halfdome.holdit.com>
>>>>> "Bernard" == Bernard Cosell <bernie@fantasyfarm.com> writes:
Bernard> I was chatting with a friend and he brought up the story about Perl
Bernard> being 'banned' from some ACM programming contest because folks were
Bernard> winning too handily using it.... he tried to find out info about the
Bernard> contest [and that language exclusion] on the ACM site, but couldn't [I
Bernard> just tried and the ACM site is basically down]. A quick trip to
Bernard> perl.com didn't uncover the article with a couple of searches either..
Bernard> Anyone have a URL or something to this? [and a backref to the actual
Bernard> ACM contest would be good, too]. THANKS!!!
<http://archive.develooper.com/advocacy@perl.org/msg00953.html>
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 01 Oct 2001 23:27:09 GMT
From: "Charles Engelke" <usenet@engelke.com>
Subject: Re: ACM programming contest
Message-Id: <hZ6u7.13228$Ef.1035252@news1.rdc1.ga.home.com>
"Bernard Cosell" <bernie@fantasyfarm.com> wrote in message
news:oinhrt8hlk4flfg6vqhfg9mad0kvthge1n@4ax.com...
> I was chatting with a friend and he brought up the story about Perl
> being 'banned' from some ACM programming contest because folks were
> winning too handily using it.
It's not quite right to say they've "banned" Perl, rather, they don't
include Perl in the languages that can be used. The reason that's different
from banning Perl is that they set up the standard programming, testing, and
scoring environments, and can't support everything. Another point is that
the international contest has never included Perl, so it's not because
anyone "won too handily".
The languages included this year are Java, C, C++, and Pascal. No Perl, but
also no FORTRAN, no Ada, no LISP, no... you get the idea.
As it happens, I think this choice of languages reflects an academic mindset
that is unaware of much going on in the "real world". (My wife the computer
science professor, who has been a judge of the ACM International Collegiate
Programming Contest for the last 10 years, probably wouldn't agree.) For
the last few years, I've submitted sample problems to the contest judges,
and I always solved them with Perl first, to get the right output, then
wrote them in Pascal and C for the contest. They never got selected, though
(maybe because I submitted my Perl solutions along with the others?).
The programming contest home page is http://www.acm.org/contest/ , which
just redirects you to http://icpc.baylor.edu/icpc/ , so you can go there if
there's a problem with acm.org. (Why Baylor? The contest coordinator is on
the faculty there.)
In addition to the international contest, there are various regional
contests throughout the world. They can allow Perl if they want, but since
the point is pretty much to select winners to represent the region at the
international contest, most stick to the same set of languages.
Charles Engelke
------------------------------
Date: Tue, 2 Oct 2001 01:12:24 +0200
From: "Markus Dehmann" <markus.cl@gmx.de>
Subject: Algorithm/Module for improving poor RegExps?
Message-Id: <9patdb$hk7qu$1@ID-101658.news.dfncis.de>
Is there a tool that simplifies and improves regular expressions?
Imagine I have the expressions:
s/tree/x/g;
s/fee/x/g;
s/gee/x/g;
Some tool should be able to convert it to:
s/(?:tr|f|g)ee/x/;
Markus.
------------------------------
Date: Mon, 1 Oct 2001 19:17:53 -0400
From: Jeff 'japhy' Pinyan <jeffp@crusoe.net>
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <Pine.GSO.4.21.0110011916490.19830-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 2, Markus Dehmann said:
>s/tree/x/g;
>s/fee/x/g;
>s/gee/x/g;
>
>Some tool should be able to convert it to:
>s/(?:tr|f|g)ee/x/;
Jarkko Hietniemi wrote Regex::PreSuf which takes a list of strings and
converts them to an optimal regex to match any of them. This sounds close
enough to what you want.
I'm going to write a variant which does the same for a list of patterns.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
------------------------------
Date: Mon, 01 Oct 2001 23:24:12 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <3bb8fb1c.3be6$cb@news.op.net>
In article <Pine.GSO.4.21.0110011916490.19830-100000@crusoe.crusoe.net>,
Jeff 'japhy' Pinyan <japhy@pobox.com> wrote:
>I'm going to write a variant which does the same for a list of patterns.
How are you going to do that?
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Mon, 1 Oct 2001 19:42:03 -0400
From: Jeff 'japhy' Pinyan <jeffp@crusoe.net>
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <Pine.GSO.4.21.0110011936550.19830-100000@crusoe.crusoe.net>
On Oct 1, Mark Jason Dominus said:
>In article <Pine.GSO.4.21.0110011916490.19830-100000@crusoe.crusoe.net>,
>Jeff 'japhy' Pinyan <japhy@pobox.com> wrote:
>>I'm going to write a variant which does the same for a list of patterns.
>
>How are you going to do that?
I was half-waiting for that. I'm not sure of the scope of its abilities,
but there are examples of regexes that have common elements that can be
grouped together. Example:
# the fields have commas and/or whitespace separating them
@fields = split /(?:\s*,|\s+,?)\s*/, $record;
can become:
@fields = split /\s*(?:,|\s,?)\s*/, $record;
because the /\s+,?/ is really /\s*\s,?/ in theory. The process I'll take
will be parsing the regex into opcodes of some sort (whether Perl's
internal structure or my own) and then fiddling with them looking for
commonalities.
This is not going to be done any time soon. I'm running out of burners on
my stove.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
------------------------------
Date: Mon, 01 Oct 2001 21:01:50 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBI/SQL trouble...
Message-Id: <3BB911FE.AFD19713@earthlink.net>
martinblack wrote:
>
> Hi, Folks. I'm having trouble with this database addition/appendage
> script. I can't even seem to generate an error from this, other than
> the old "internal server error". Any help on this matter would be
> appreciated. Thanks in advance.
>
> #!/usr/bin/perl
>
> BEGIN {
> open (STDERR, ">html/error.txt");
> }
>
> ### add.cgi
>
> use DBI;
> use CGI::Carp qw(fatalsToBrowser carpout);
> require "dbsubs.cgi";
> use CGI;
> $q=new CGI;
>
You've got some of this stuff in the wrong order.
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser carpout);
BEGIN {
open(LOGFILE, ">html/error.txt")
or die "Couldn't open html/error.txt: $!";
carpout(LOGFILE);
}
use DBI;
use CGI;
> # input..................................
>
> $io{'company_id'} = $company_id = $q->param(company_id);
> $io{'product_id'} = $product_id = $q->param(product_id);
> $io{'title'} = $title = $q->param(title);
> $io{'description'} = $description = $q->param(description);
> $io{'spex'} = $spex = $q->param(spex);
> $io{'price'} = $price = $q->param(price);
> $io{'sex'} = $sex = $q->param(sex);
my %io;
foreach my $key ( qw/
company_id product_id title
description spex price sex/ ) {
$io{$key} = param($key);
}
> # mainline...............................
>
> print header;
This line is ok.
>
> $DBname= "dbi:mysql:username";
> $DBhost = "localhost";
> $DBusername = "myusername";
> $DBpassword = "myPassword";
>
> $dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword) ||
> die "connection problem: ", $dbh->errstr;
> $dbh->{'RaiseError'} = 1;
You don't need to use all these extra variables, and of course you need
to declare $dbh if 'use strict' is enabled. Which it *always* should
be, unless and until you know *all* the things it guards against, and
even then, it should only be disabled for small blocks of code.
my $dbh = DBI->connect(
"dbi:mysql:username:localhost",
"myusername", "mypassword",
{RaiseError=>1}
) or die "DBI Connection problem: " . $DBI::errstr;
> &kaboom;
>
> &print_output;
>
> # subroutines...
>
> sub print_output{
> print<<HTML;
> <HTML><BODY>
> <CENTER><FONT SIZE=5>
> Record added to database
> <P>
> he he he ha ha
> </P>
> </FONT></CENTER>
> </BODY></HTML>
> HTML
>
> }
>
> sub kaboom() {
>
> $sth = $dbh->prepare( q[
> SELECT company_id, product_id
> FROM product
> WHERE company_id = ? and
> product_id= ?
> ] ) || die "prep problem: ", $DBI::errstr;
> $sth->execute( $company_id, $product_id ) || die "execution problem:
> ", $DBI::errstr;
What precidely do you expect this query to return?
It have in your where clause a restriction to just get those records
which match the company and product ids from the form, and then all you
have it SELECT is the company and product ids.
> &fetch_results;
Your fetch_results sub is trying to extract a whole bunch of things from
the database, but since you don't select most of those fields, they all
end up as undef.
> if (defined $pro) {
This will always be false, given the current code.
> $sth = $dbh->prepare( q[
> update product set
> title = ?,
> spex = ?,
> description = ?,
> price = ?,
> sex = ?
> WHERE company_id = ? and
> product_id = ?
> ] ) || die "prep problem: ", $DBI::errstr;
>
> $sth->execute( $title, $spex, $description, $price, $sex,
> $company_id, $product_id ) || die "problem baby: ", $DBI::errstr;
Pretending for a moment that this code ever gets executed...
If you are doing nothing more than a prepare followed by an execute,
then you should probably be using the 'do' method.
$dbh->do(do { local $" = ", "; qq[
UPDATE product
SET @{[map "$_ = ?", keys %io]}
WHERE company_id = ? AND product_id = ?
] }, undef,
values %io,
@io{qw(company_id product_id)} );
>
> #&fetch_results;
>
> } else {
> #111
>
> $sth = $dbh->prepare( q[
> insert into product set
> company_id = ?,
> product_id = ?,
> title = ?,
> spex = ?,
> description = ?,
> price = ?,
> sex = ?
> ] ) || die "prep problem: ", $DBI::errstr;
>
> $sth->execute( $company_id, $product_id, $title, $spex, $description,
> $price, $sex ) || die "problem child: ", $DBI::errstr;
Your sql statement is wrong. Insert has the following syntax.
$dbh->do(do { local $" = ", "; qq[
INSERT INTO product (@{[ keys %io ]})
VALUES (@{[ ('?') x values %io ]})
] }, undef, values %io );
> #&fetch_results;
>
> }
>
> }
>
> sub fetch_results {
>
> while ($x = $sth->fetchrow_hashref) {
> $com = $x->{'company_id'};
> $pro = $x->{'product_id'};
> $tit = $x->{'title'};
> $des = $x->{'description'};
> $spe = $x->{'spex'};
> $pri = $x->{'price'};
> $morf = $x->{'sex'};
>
> $newid = $com ."-".$pro;
>
> }
> }
As I said once before, this sub isn't right.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Mon, 01 Oct 2001 19:07:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Embed Sound into cgi?
Message-Id: <3BB8F721.7EAF4891@earthlink.net>
christo wrote:
>
> I have a free chat cgi script im running and would like to know if a
> beep sound can be embeded somehow to advise me when someone logs in to
> the chat room. any help would be appreciated.
syswrite STDOUT, "\a";
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 2 Oct 2001 09:01:56 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: GIF encoding
Message-Id: <zz6u7.25024$812.37859@newsfeeds.bigpond.com>
"Philip Newton" <pne-news-20011001@newton.digitalspace.net> wrote in message
news:q91grtsbub7d33nqti1npqjftku6pbkkt5@4ax.com...
>
> Then you have an old version of the module. Newer versions of the module
> will not write GIF but, instead, PNG (and also JPEG), since that's what
> newer versions of libgd (on which the module is based) write.
Correct, but some of us have thousands of users around the world with olders
browsers that support gif but not png.
gtoomey
------------------------------
Date: Tue, 2 Oct 2001 00:42:14 +0200
From: "CentaureZ" <centaurez@ifrance.com>
Subject: how can i do site to site FTP transfer (FXP)
Message-Id: <9parg5$ab4$1@front1m.grolier.fr>
Hi,
I'd like to do site to site ftp transfer (fxp) in perl using Net::FTP module
but i found nowhere how to do that, must i do it manually or is there some
module or function to help me?
Thanks in advance for your response.
------------------------------
Date: 01 Oct 2001 16:23:13 -0700
From: Gerard Lanois <gerard@NOSPAMlanois.com>
Subject: Re: how can i do site to site FTP transfer (FXP)
Message-Id: <u3d539c7y.fsf@NOSPAMlanois.com>
"CentaureZ" <centaurez@ifrance.com> writes:
> Hi,
>
> I'd like to do site to site ftp transfer (fxp) in perl using Net::FTP module
> but i found nowhere how to do that, must i do it manually or is there some
> module or function to help me?
>
> Thanks in advance for your response.
http://www.perlmonks.org/index.pl?node_id=85133
-Gerard
http://www.lanois.com/perl/
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
Check out our new Unlimited Server. No Download or Time Limits!
-----== Over 80,000 Newsgroups - 19 Different Servers! ==-----
------------------------------
Date: Mon, 01 Oct 2001 20:47:14 -0400
From: Zimmen Gnauh <yah00204052@yahoo.com>
Subject: how to get rid of spaces around a string?
Message-Id: <3BB90E92.434B79E@yahoo.com>
$string=" abcd ";
what function can give me "abcd"?
------------------------------
Date: Tue, 02 Oct 2001 01:01:59 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: how to get rid of spaces around a string?
Message-Id: <bm8u7.5788$Gd6.117262@typhoon.mw.mediaone.net>
$string=" ab cd "; # I added a space in the middle
$string =~ s/^\s+//; # substitute nothing for leading space(s)
$string =~ s/\s+$//; # substitute nothing for trailing spaces
print ">$string<"; #prints >ab cd<
print "\n"; # a new line
$string=" ab cd "; # I added a space in the middle
$string =~ s/\s+//g; # substitute nothing any space(s)
print ">$string<"; #prints >abcd<
"Zimmen Gnauh" <yah00204052@yahoo.com> wrote in message
news:3BB90E92.434B79E@yahoo.com...
> $string=" abcd ";
> what function can give me "abcd"?
>
------------------------------
Date: 1 Oct 2001 22:25:53 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how to send mail without sendmail
Message-Id: <slrn9rhr8q.5qh.abigail@alexandra.xs4all.nl>
Zimmen Gnauh (yah00204052@yahoo.com) wrote on MMCMLII September MCMXCIII
in <URL:news:3BB79D91.1247D5A9@yahoo.com>:
.. My unix system does not have sendmail (somehow removed by admin). Is
.. there any way to send mail without it?
Maybe, maybe not. We cannot tell. It all depends on your system.
You don't have a Perl issue here. You have a site policy issue here.
The proper (and only) people to discuss this with are your system
administrators. They can tell you about any alternatives - if any.
Perhaps sending mail directly from non-authorized machines is a firing
offence. Perhaps there is a replacement. Perhaps you do have sendmail,
but it wasn't in the directory you look for.
Again, talk to your sysadmins. Don't forget to bring beer. And grovel.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Tue, 2 Oct 2001 08:16:14 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: IE vs. Netscape problems in perl
Message-Id: <SX5u7.2$_L1.9226@news.interact.net.au>
"David Linker" <dtlinker@u.washington.edu> wrote in message
news:9panoe$1470$1@nntp6.u.washington.edu...
> I need some help. I wrote a download logging perl script. It keeps track
> of how many times a file has been downloaded, and who did it, in two
> separate files. It works perfectly now when accessed from within
> Netscape, but when I use Internet explorer, it downloads a link with the
> name of the script, and logs two downloads!
Woah!! Stop right there. Perl has no concept of IE or Netscape or any
other browser for that matter. Perl will generate some output. Exactly how
the webserver and/or the browser handles it, is up to them, not Perl.
[snipped code]
I'd suggest you do
perldoc -q locking
------------------------------
Date: Tue, 02 Oct 2001 00:21:47 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: IE vs. Netscape problems in perl
Message-Id: <3bb9070d.67539651@news.itouch.net>
On 1 Oct 2001 21:38:22 GMT, David Linker <dtlinker@u.washington.edu>
wrote:
>I need some help. I wrote a download logging perl script. It keeps track
>of how many times a file has been downloaded, and who did it, in two
>separate files. It works perfectly now when accessed from within
>Netscape, but when I use Internet explorer, it downloads a link with the
>name of the script, and logs two downloads!
>
>Any ideas appreciated!
>
>Thanks,
>
>David Linker
>
>From Netscape, it downloads the file "Test.RTF", as intended.
>
>From IE, it downloads a file called count.cgi (the name of the perl
>script), containing:
>
>[InternetShortcut]
>URL=http://faculty.washington.edu/dtlinker/Test.RTF
Are the above lines part of your script!?! Why?
I think the shebang line should be the first line.
>
>The script is as follows:
>
>#!/usr/local/bin/perl
>
.....................
------------------------------
Date: Mon, 01 Oct 2001 20:31:19 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Offtopic: DMCA and perldoc perlsec
Message-Id: <3BB90AD7.101CE0F0@earthlink.net>
Alexander Farber (EED) wrote:
>
> Hi,
>
> isn't it strange: hackers complain about legal acts used to
> protect insecure encryptions (PDF) / web sites (IIS) / whatever
> (and I agree with them), but then the "perldoc perlsec" states
> the following:
>
> If you're concerned about people profiting from your code,
> then the bottom line is that nothing but a restrictive
> licence will give you legal security. License your software
> and pepper it with threatening statements like "This is
> unpublished proprietary software of XYZ Corp. Your access
> to it does not give you permission to use it blah blah
> blah." You should see a lawyer to be sure your licence's
> wording will stand up in court.
What perlsec is saying is that there is no programatic way to have your
source code hidden from the end users... you can keep it from being
stolen via laws, not by encryption.
PDF encryption and the like are attempts to use encryption keep the
source code of the document hidden from the viewers.
If you agree with perlsec, then one would conclude that all such
encryption-based attempts to secure PDFs are doomed to failure, and the
only way to prevent people from stealing your content is to write on
that content "Do no copy!" in legalese.
The recent legal acts are essentially saying, "If someone has attempted
to secure data via encryption, you may not attempt to break that
encryption..." as an *attempt* to make it so one could use encryption
without it being doomed-to-failure... simply because breaking the code
becomes illegal.
Personally, I think that instead of making laws to protect doomed-to-
failure encryption, they should try strengthening laws against copying
copywritten material. After all, if a person is willing to break one
law so they can steal, they will be perfectly willing to break the other
so they can steal.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 1 Oct 2001 16:46:26 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: Re: Pattern Matching
Message-Id: <23e71812.0110011546.551771bf@posting.google.com>
The problem now is that I am using three hashes (each contain
different length strings). I will call them %one(longer sentences),
%two() and %three(shorter sentences).
If I am currently scanning %three and I want to see if the strings are
present in %one and %two, I will need to use LOTS of foreach
statements.( This slows the program A LOT).
I am using the following
foreach $small(keys %three){
if (grep { index($_, $small) != -1 } keys %two){
$seen{$_}=1;
}
if (grep { index($_, $small) != -1 } keys %one){
$seen{$_}=1;
}
}
Adding the following in the if loop, will become TOO time consuming.
foreach my $key (keys %strings){
$longer = $key, last if index($key, $small) != -1;
}
print "$longer contains $small.\n" if defined $longer;
Is there an easier way to do this?
I basically need to find the number of different longer strings that
the smaller strings occur in.
------------------------------
Date: Mon, 01 Oct 2001 20:18:15 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Pattern Matching
Message-Id: <3BB907C7.EC596DB2@earthlink.net>
shaz wrote:
>
> The problem now is that I am using three hashes (each contain
> different length strings). I will call them %one(longer sentences),
> %two() and %three(shorter sentences).
>
> If I am currently scanning %three and I want to see if the strings are
> present in %one and %two, I will need to use LOTS of foreach
> statements.( This slows the program A LOT).
>
> I am using the following
>
> foreach $small(keys %three){
> if (grep { index($_, $small) != -1 } keys %two){
> $seen{$_}=1;
> }
> if (grep { index($_, $small) != -1 } keys %one){
> $seen{$_}=1;
> }
> }
>
> Adding the following in the if loop, will become TOO time consuming.
>
> foreach my $key (keys %strings){
> $longer = $key, last if index($key, $small) != -1;
> }
> print "$longer contains $small.\n" if defined $longer;
>
> Is there an easier way to do this?
>
> I basically need to find the number of different longer strings that
> the smaller strings occur in.
I don't think I understand exactly what the problem is you are trying to
write code to solve, [your explanations aren't clean enough for me], but
one way in which you can speed things up is to replace code code like
for $key (keys %hash) with code like: while(defined($key = each %hash)).
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 1 Oct 2001 22:31:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl semaphore IPC package real world stability
Message-Id: <slrn9rhrj9.5qh.abigail@alexandra.xs4all.nl>
Dr. Laurence Leff (mflll@wiu.edu) wrote on MMCMLII September MCMXCIII in
<URL:news:9p7nvt$jmg$1@ecom1.wiu.edu>:
][ Now, our department teaches UNIX including such features as semaphores,
][ sockets, and shared memory using the C language.
][
][ There is a suggestion to teach semaphores, sockets, binary file manipulation,
][ etc. using the Perl packages. We already teach Perl in our Unix class.
][ This would allow us to make the UNIX programming material accessible to
][ those who have not taken our courses on C programming.
][
][ My question for this group is whether this Perl functionality is real-world
][ stable. Is anyone using Perl instead of C programming in the "real world"
][ that involves these kinds of tasks.
Perl only provides a thin layer over the system calls/standard libraries
when it comes to semaphores, sockets and file manipulations.
The functionality provided by Perl is as stable as you get when coding C.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Mon, 01 Oct 2001 23:36:04 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Perl Tk and Pack Problems
Message-Id: <E57u7.140909$K6.65762901@news2>
[Posted and mailed]
In article <3BB86AA1.A2BF0BA@ntlworld.com>,
slightlysprintingdog@ntlworld.com writes:
> I'm having problems with a Perl Tk script that uses multiple windows.
> Basically, I click a button to open a window then click close. (using
> $mw->destroy();)
> Then click to open the same window and I get this error.
> Any ideas ? - or do I need to be more specific ?
Two suggestions:
1. Try comp.lang.perl.tk. The experts in Tk congregate there.
2. They'll probably want to see at least the code around "regress.pl"
near line 248. That's just my guess. :)
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Mon, 1 Oct 2001 19:41:46 -0500
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: POSIX' sprintf doesn't regard locale?
Message-Id: <Pine.LNX.4.33.0110011940450.17705-100000@macbeth.tirone.com>
Apparently the perllocale documentation is wrong. Although it said that
printf and sprintf will obey the LC_NUMERIC locale information, and that
print and internal conversions between numeric and string formats don't
get affected, the reality is reverse.
print & internal conversion obey locale information
printf and sprintf DON'T obey locale information
Here is the code from perllocale documentation:
-------------------------------------------------------------------------
use strict;
use POSIX qw(locale_h strtod);
use locale;
setlocale(LC_NUMERIC, 'de_DE@euro');
my($n) = 5/2; # Assign numeric 2.5 to $n
my($a) = " $n"; # Locale-independent conversion to string
print "half five is $a (locale independent)\n";
print "half five is $n (locale independent)\n"; # Locale-independent
output
printf "half five is %g (locale dependent)\n", $n; # Locale-dependent
output
print "DECIMAL POINT IS COMMA\n"
if $n == (strtod("2,5"))[0]; # Locale-dependent conversion
-------------------------------------------------------------------------
This is the output I got:
-------------------------------------------------------------------------
half five is 2,5 (locale independent)
half five is 2,5 (locale independent)
half five is 2.5 (locale dependent)
DECIMAL POINT IS COMMA
-------------------------------------------------------------------------
As you can see, it actually give result different from what the perllocale
said it would, except for the last output from strtod.
My systems are several Athlon machines running i386 Red Hat Linux 7.0 and
7.1, all running perl 5.6.0. The POSIX unit is part of the perl 5.6.0
distribution.
How to get printf and sprintf to regard locale?
Thanks.
--
S P Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____ arifsaha@yahoo.com
_____/ / / / _____/ http://www.arifsaha.com/
------------------------------
Date: Tue, 2 Oct 2001 00:57:22 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: POST REDIRECT, was Re: URL forwarding
Message-Id: <Pine.LNX.4.30.0110020049020.8163-100000@lxplus023.cern.ch>
On Oct 1, Ilmari Karonen inscribed on the eternal scroll:
> Note that there are issues
> involved in redirecting POST requests beyond Perl-related ones.
Excuse me briefly disregarding your hint about off-topicness, but that
did rather seem to leave the thread dangling, if you don't mind too
much.
There are two classes of "issue", I'd say
One is a matter of policy: POST is supposed to be a non-idempotent
request, it should generally be carried out completely - or rejected
completely, and, either way, a clear response sent to the user.
Involving a redirection in that mechanism is to introduce an extra
level of uncertainty, which would need to be evaluated in terms of
the particular risk involved. IMHO.
The second is technical: browsers don't properly support some of the
interesting options. I've got some observations collected at:
http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
Now I guess I should at least provisionally set f'ups to a more
appropriate group.
cheers
------------------------------
Date: 1 Oct 2001 22:05:00 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: question of copyright
Message-Id: <1001972674.8942@itz.pp.sci.fi>
In article <4f5355b6.0110010651.676c539a@posting.google.com>, Leo wrote:
[snip]
>interface cgi-lib into my code in the standard way so I took a small
>chunk of code in the library (dealing with file uploads) and
>encorporated it directly into my parsing routine. I have acknowledged
>it's use (as specified in the copyright notice of cgi-lib.pl) and why
>it is used directly in my code. Am I breaking any copyright in doing
>this?
>
>p.s. the copywright stated in cgi-lib.pl is:
>
># Copyright (c) 1993-1999 Steven E. Brenner
># Unpublished work.
># Permission granted to use and modify this library so long as the
># copyright above is maintained, modifications are documented, and
># credit is given for any use of the library.
Hard to say. IANAL, but even I can tell that the copyright notice is
rather vague. If there is a problem, it's probably the "copyright above
is maintained" part -- I think it could be interpreted to mean that the
copyright to any derived works must be assigned to Steven E. Brenner.
Or perhaps not, or it might depend on all sorts of little details.
Anyway, why don't you try to find his e-mail address and ask him? I'd
consider it quite likely that he might be willing to give you permission
to use his code.
Or you could try to find some other CGI library that would either fit
your needs better or have a more permissive licence. (Most Perl modules
are licensed "under the same terms as Perl itself". This means a dual
license of GPL and the Artistic License. The latter would seem to allow
you to do what you describe above.)
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Tue, 2 Oct 2001 01:31:42 +0100
From: "S Warhurst" <bigusAT@btinternetDOT.com>
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <9pb1s6$974$1@plutonium.btinternet.com>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9rfcv7.t75.mgjv@martien.heliotrope.home...
> [Please in the future, put your reply _after_ the suitably trimmed text
> you reply to. It is the commonly accepted quoting style on this
> newsgroup, and Usenet in general]
When it is necessary to reply to particular passages of the original
message, like now, then yes I agree, but since my reply didn't require such
quotes and could be read "standalone" then I put it at the top where it's
quickest & easiest to read. I maybe a relative novice to Perl but I have
used Usenet for years and both methods are commonly accepted depending the
context of the reply.
> Good documentation to read for the @ vs. $ stuff is the perldata
> document. Because you're working with references to build an array of
> array references, I'd suggest you also read perlref, perlreftut, perllol
> and perldsc (all available via the perldoc command (and man on unix, and
> as HTML on ActiveState installations).
I will get round to reading all that stuff and thanks for the references. I
have been doing quite alot of Perl for the past 6 months (all scripts to do
various administrative & statistical tasks with regard to Listserv), believe
it or not, and I've learnt it from a combination of Rex Swain's HTML
reference guide & modifying code found by surfing. Not ideal because as you
can probably gather there are still some fundamentals I am missing on. but
like VB before it, you can get by quite well with a core sets of commands at
your disposal & probably doing many things the "long-winded" way ;)
> Sort always uses curlies there:
> @array = sort { $a <=> $b } @other_array;
> Can you give an example with round brackets that compiles?
Yeah, the following syntax I have used before:
@names = ('Peter', 'Alan', 'John');
@sorted = sort(@names);
I guess the round brackets aren't needed at all in that and you could just
say:
@sorted = sort @names; # having been a previous been a dabbler with VB, I
guess I feel comfortable sticking round brackets round everything ;-)
So perhaps it's just Perl being flexible again, and it's only when you are
specifying things to sort by that you need to use the curlies?
<snip>
> I hope the above has made it a little easier. It is, however, not a
> substitute for reading the documentation. You could also consider buying
> a book[1].
Yes, amazingly, I think I understood all that :)
Thanks for taking the time to explain things to me.. I will study the
perldoc site in more detail :)
Spencer
------------------------------
Date: 01 Oct 2001 17:58:41 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <m1adzadfi6.fsf@halfdome.holdit.com>
>>>>> "S" == S Warhurst <bigusAT@btinternetDOT.com> writes:
S> When it is necessary to reply to particular passages of the original
S> message, like now, then yes I agree, but since my reply didn't require such
S> quotes and could be read "standalone" then I put it at the top where it's
S> quickest & easiest to read. I maybe a relative novice to Perl but I have
S> used Usenet for years and both methods are commonly accepted depending the
S> context of the reply.
What groups have you read for over a decade that support upside-down
quoting?
I've been on Usenet for 20 years now. Upside-down quoting is a recent
Microsoft-abomintation, perhaps egged on a bit by some early versions
of Netscape that added the "post" button and forever changed the face
of Usenet.
I just can't see the point of having the answer before the question.
It's just wrong. Either don't quote the question, or quote it in
context. It's either relevant, or it isn't.
Just another Usenet old-timer, :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 1 Oct 2001 22:33:22 GMT
From: abigail@foad.org (Abigail)
Subject: Re: splitting a very wide report
Message-Id: <slrn9rhrmr.5qh.abigail@alexandra.xs4all.nl>
Marc Ulrich (mdulrich@unity.ncsu.edu) wrote on MMCMLIII September
MCMXCIII in <URL:news:3BB87F33.C558BAC2@unity.ncsu.edu>:
`' I've a report output that is very very wide and is better done as three
`' individual reports (which will fit on a single page). Line wraps are
`' annoying and so is ultrasmall text.
`'
`' The only solution I've come up with is to have three output formats and
`' do three separate reports. This is kind of awkward. I'd rather do a
`' single report but ask it to split it after column x and after column y.
`' Is this possible?
You could post process your output. See the open '-|' and '|-'
entries in perlopentut.
Alternatively, you write a second program that splits the output.
Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
# Two foxes crouch. Ten trout
# swim. A pike in a dam. A
# flying woodpecker.
------------------------------
Date: 1 Oct 2001 16:01:20 -0700
From: noident@my-deja.com (noident)
Subject: Re: unpack(), etc - programming question
Message-Id: <66fba11b.0110011501.6dcc1600@posting.google.com>
> use strict;
> use warnings;
>
> my $USER_perm = "100";
> my $ELEM_perm = "100";
>
> my $USER_converted = pack "B8", $USER_perm;
> my $ELEM_converted = pack "B8", $ELEM_perm;
>
> my $result_one = $USER_converted & $ELEM_converted;
>
> if( $result_one == 0 ){
> print("REJECTED-1\n");
> } else {
> my $result_two = $ELEM_converted ^ $result_one;
> if( $result_two == 0 ){
> print("ACCEPTED\n");
> } else {
> print("REJECTED-2\n");
> } #if
> } #if
I'm not sure what you're trying to do, but:
1. if you want to get a binary representation of a number as a string,
do this -
unpack "B16",(pack "n", $short_integer)
instead of 'pack "B8", something'
2. if you want to do bitwise operations on two numbers, 100 & 110 will
work just fine, no need to print them out as binary strings.
Hope that helps.
------------------------------
Date: 1 Oct 2001 22:23:45 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: URL forwarding
Message-Id: <1001974399.9806@itz.pp.sci.fi>
In article <t6bhrtcto9kuou4r93n5p826h3ukkaslho@4ax.com>, Thomas Bδtzler wrote:
>
>is not the proper answer here - read the OP's question again.
>He asks specifically about passing along the CGI parameters - and that
>makes this question at least a bit interesting.
There is a simpler solution using CGI.pm, which also doesn't have any of
the problems you describe:
#!/usr/bin/perl -w
use strict;
use CGI ':cgi';
my $url = 'http://www.example.com/whatever.php';
print redirect("$url?" . query_string);
exit;
If this is a POST request, CGI.pm takes the parameters from the POST
content and ignores any parameters in the URL (unless you change an
internal variable that controls this). Note that there are issues
involved in redirecting POST requests beyond Perl-related ones.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 1 Oct 2001 17:43:31 -0700
From: Daniel@e-storm.com (Daniel Riveong)
Subject: Using TAB - Newbie Question
Message-Id: <4b55ea93.0110011643.1645d189@posting.google.com>
Hi,
I am a newbie at PERL. I know this must be a real easy question, but I
cant find the answer anywhere!
I am creating a flat database with data from a submitted form. My
Question is how does one use TAB is a delimiter?
Here is a sample of the code:
foreach $to_print (@sortlist) {
if ($fields{'outputfile'} ne "")
{ print OUT_FILE "$fields{$to_print}\|"; }
if ($fields{'submit_to'} ne "")
{ $msgtext .= "$to_print = $fields{$to_print}\n"; }
}
As you can see in line 3, I am now use | as the delimiter. How do I
use tab instead?
Thanks A Million in Advance,
Daniel
------------------------------
Date: Tue, 2 Oct 2001 10:28:48 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Using TAB - Newbie Question
Message-Id: <kb8u7.21$xu5.566@wa.nnrp.telstra.net>
"Daniel Riveong" <Daniel@e-storm.com> wrote in message
news:4b55ea93.0110011643.1645d189@posting.google.com...
> Hi,
>
> I am a newbie at PERL. I know this must be a real easy question, but I
> cant find the answer anywhere!
>
> I am creating a flat database with data from a submitted form. My
> Question is how does one use TAB is a delimiter?
>
> Here is a sample of the code:
>
> foreach $to_print (@sortlist) {
> if ($fields{'outputfile'} ne "")
> { print OUT_FILE "$fields{$to_print}\|"; }
Pipe is not special in a double quoted string (it is in a regex). Tab
character is \t (backwack a t to make it special).
> if ($fields{'submit_to'} ne "")
> { $msgtext .= "$to_print = $fields{$to_print}\n"; }
> }
>
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
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 1853
***************************************