[8923] in Perl-Users-Digest
Perl-Users Digest, Issue: 2541 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 8 14:07:28 1998
Date: Fri, 8 May 98 11:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 8 May 1998 Volume: 8 Number: 2541
Today's topics:
Again accent in Perl... <cristina.durana@iie.min-edu.pt>
Re: Anagram algorithm anyone. (Peter Scott)
Re: ANNOUNCE: Perl Builder IDE Now Available (Ken Fox)
Better Sort? <snowbird@pcisys.net>
Re: COUNTING DAYS UNTIL 2000 <upsetter@shore.net>
Re: Ever Wonder Why Not Everyone Uses Modules? (Matthew Cravit)
Re: Ever Wonder Why Not Everyone Uses Modules? (Leslie Mikesell)
Re: Ever Wonder Why Not Everyone Uses Modules? <p-ciccone@usa.net>
Re: exists and -w messages (Wayne C. McCullough)
Re: Grieving our dying community (Chris Russo)
Re: Help me Please! <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Help me Please! (Craig Berry)
Re: how to create name for temporary file <aqumsieh@matrox.com>
Re: How to delete an element in an array? (Kevin Reid)
Re: How to delete an element in an array? (Mark-Jason Dominus)
Re: How to delete an element in an array? <tchrist@mox.perl.com>
Re: How to export constants in modules without C code <keithmur@mindspring.com>
Multiline substitution from command line in Perl 4. How <reardon@maroon.tc.umn.edu>
Re: Problem with xemacs and perl syntax hilitghtning <aqumsieh@matrox.com>
Re: QRe: == vs. eq <abaugher@rnet.com>
Re: settime <mengyu@mail.utexas.edu>
Re: Tip: Hash Slices <cmargoli@world.northgrum.com>
Using frames in perl: How to select target <mosey@alpha3.csd.uwm.edu>
Re: Using frames in perl: How to select target (brian d foy)
Re: Win95 Perl scripts DONT WORK on UNIX (Leslie Mikesell)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 May 1998 17:52:07 +0200
From: Cristina Durana <cristina.durana@iie.min-edu.pt>
Subject: Again accent in Perl...
Message-Id: <35532A27.AA3DD1C6@iie.min-edu.pt>
Hi all!!!!!!
My problem consistes in the next code:
(although the script runs, it doesn't writes the word like I want...)
I would like that the word='Descrição' appeared to the
user like iqual a Descrigco.
Thanks in advance
The code is:
--------------------------------------------------------------------------------
#!/usr/bin/perl
use CGI;
$query = new CGI;
print $query->header;
print $query->start_html('Popup Window');
if (!$query->param) {
#apresentacao do formulario ao utilizador
#comeca a escrever no browser
"Content-type:text/html\n\n";
print <<EndOfHTML;
<center><h4><b><blink><FONT FACE="Comic Sans MS"><FONT
COLOR="#000000"><FON\
T SIZE=+2>Mediateca do
IIE</FONT></FONT></FONT></BLINK></b></h4></center>
EndOfHTML
;
#associative array
%labels=('autor'=>'Autor',
'desc'=>'Descrição');
print $query->startform;
print "Termo a Pesquisar ",$query->textfield('pesquisa');
print "<p><b>Campos de Pesquisa</b><p>",
$query->checkbox_group(-name=>'registos',
-values=>[$labels{'autor'},$labels{'desc'}],
-linebreak=>'true',
-default=>[$labels{'autor'}],
-labels=>\%labels);
print"<p>";
print $query->submit(-name=>'Procura');
print $query->reset(-name=>'Apaga');
print $query->endform;
#fim do formulario ao utilizador
} else {
print "<H1>Resultados da Pesquisa...</H1>\n";
print "O nome escolhido foi...
<EM>",$query->param(pesquisa),"</EM>\n";
print "<P>Os campos foram: <EM>",join(",
",$query->param(registos)),"</EM>\\
n";
}
print $query->end_html;
---------------------------------------------------------------------------
------------------------------
Date: 8 May 1998 17:40:15 GMT
From: psf@euclid.jpl.nasa.gov (Peter Scott)
Subject: Re: Anagram algorithm anyone.
Message-Id: <6ivg1v$3c7@netline.jpl.nasa.gov>
In article <Wbs+iDACUtU1Ewe+@connected.demon.co.uk>, Jerry Pank <jerryp.usenet@connected.demon.co.uk> writes:
> Below is my hopeless attempt at an anagram algorithm.
> Almost works for 4 letters but (obviously) miserable with n letters.
>
> Does anyone have a ``standard'' algorithm for calculating anagrams?
Just so you have a Perl example, here's something I hacked up a while
ago. I cannot speak to its standardness, it's just what came to me
at the time. But it does work. It also makes you wish there weren't
so many three-letter words in the dictionary :-)
use Getopt::Std;
use vars qw($opt_d $opt_v);
$| = 1;
getopts ('dv');
my $DEBUG = $opt_d;
my $VERBOSE = $opt_v;
my @allow = ("a", "i", # Too many pointless 2-letter words in dict...
"am", "an", "as", "at", "ax", "be", "by", "do", "ex", "go",
"ha", "he", "hi", "ho", "if", "in", "is", "it", "ma", "me",
"mr", "ms", "my", "no", "of", "on", "or", "ow", "ox", "pa",
"pi", "so", "to", "up", "us", "we", "ye", "im", "id");
my $x = shift || die "No argument\n"; # First arg is input string
my %exclude = ();
foreach (@ARGV) { # Other args are words to exclude from result
tr/A-Z/a-z/;
tr/a-z//cd;
$exclude{$_} = 1;
}
$x =~ tr/A-Z/a-z/;
$x =~ tr/a-z//cd;
my $input = str2vec ($x);
my $inputw = join '', (sort split //, $x);
my $pos = 0;
my $depth = 0;
my %words = ();
my ($count, $longest) = (0, ""), print "Input = $inputw\nWords found:\n" if $VERBOSE;
my $last_letter = substr ($inputw, -1, 1);
foreach (@allow) {
add_word ($_);
}
open (DICT, "/usr/dict/words") or die "Can't open dictionary: $!\n";
while (<DICT>) {
tr/A-Z/a-z/;
tr/a-z//cd;
next if length() < 3 || exists $exclude{$_};
last if substr ($_, 0, 1) gt $last_letter;
add_word ($_) unless exists $words{$_};
}
close DICT;
$pos = 0;
print "\nCOUNT = $count, LONGEST = $longest (", length $longest, " letters)\n"
if $VERBOSE;
my @words = sort keys %words;
anagram ($input, 0, %words);
print "\n" if $pos;
sub add_word ($) {
my $w = shift;
my $pat = join '.*?', (sort split //, $w);
return unless $inputw =~ /$pat/;
$words{$w}{COUNT} = 0;
$words{$w}{VEC} = str2vec ($w);;
return unless $VERBOSE;
my $len = length $w;
$count++;
$longest = $w if (length $w) > (length $longest);
if ($pos) {
$pos += 2;
$pos += (my $spaces = (8 - ($pos % 8)));
if ($pos + $len > 80) {
print "\n$w";
$pos = $len;
} else {
print ' ' x (2 + $spaces);
print $w;
$pos += $len;
}
} else {
print $w;
$pos += $len;
}
}
sub str2vec ($) {
my $string = shift;
my @vec = ("\0\0\0\0");
foreach my $ch (split //, $string) {
my $cv = "\0\0\0\0";
my $i;
vec ($cv, (ord $ch) - (ord 'a'), 1) = 1;
for ($i = 0; ($vec[$i] & $cv) ne "\0\0\0\0"; $i++) {
$vec[$i+1] = "\0\0\0\0" if $i == $#vec;
}
$vec[$i] |= $cv;
}
\@vec;
}
sub subtract ($$) {
my ($big, $little) = @_;
my @a = @$big;
my $copy = \@a;
for (my $i = 0; $i <= $#$little; $i++) {
$copy->[$i] &= (~ $little->[$i]);
}
normalize ($copy);
$copy;
}
sub contains ($$) {
my ($big, $little) = @_;
return 0 if $#$big < $#$little;
for (my $i = 0; $i <= $#$little; $i++)
{
return 0 unless ($big->[$i] & $little->[$i]) eq $little->[$i];
}
return 1;
}
sub print_results (%) {
my $string = "";
my %words = @_;
my $i = 0;
foreach my $word (@words) {
$i++;
print "COUNT($word) = ", $words{$word}{COUNT}, "\n" if $DEBUG;
$string .= "$word " x $words{$word}{COUNT};
}
chop $string;
my $len = length $string;
if ($pos) {
$pos += 2;
$pos += (my $spaces = (8 - ($pos % 8)));
if ($pos + $len > 80) {
print "\n$string";
$pos = $len;
} else {
print ' ' x (2 + $spaces);
print $string;
$pos += $len;
}
} else {
print $string;
$pos += $len;
}
}
sub normalize ($) {
my $w = shift;
for (my $i = 0; $i < $#$w; $i++)
{
my $remainder = $w->[$i] & $w->[$i+1];
$w->[$i] |= $w->[$i+1];
if ($remainder ne "\0\0\0\0") {
$w->[$i+1] = $remainder;
} else {
splice (@$w, $i+1, 1);
}
}
}
sub empty ($) {
my $w = shift;
for (my $i = 0; $i <= $#$w; $i++)
{
return 0 if $w->[$i] ne "\0\0\0\0";
}
return 1;
}
sub anagram ($$%) {
my ($input, $index, %words) = @_;
if (empty ($input)) {
print_results (%words);
return 1;
}
for (my $i = $index; $i <= $#words; $i++) {
my $word = $words[$i];
if (contains ($input, $words{$word}{VEC})) {
$words{$word}{COUNT}++;
if (anagram (subtract ($input, $words{$word}{VEC}), $i, %words)) {
print " " x $depth, "Anagram returned success\n" if $DEBUG;
}
$words{$word}{COUNT}--;
}
}
return 0;
}
__END__
sub printvec ($) {
my @x = ();
foreach (@{$_[0]}) {
push @x, unpack ("b*", $_);
}
print "(", join (", ", @x), ")";
}
sub vec2str ($) {
my $w = shift;
my $string = "";
foreach (@$w) {
my $s = unpack "b*", $_;
$s =~ tr/01/\000\377/;
$s &= join ('', 'a'..'z');
$s =~ tr/a-z//cd;
$string .= $s;
}
$string;
}
--
This is news. This is your | Peter Scott, NASA/JPL/Caltech
brain on news. Any questions? | (psf@euclid.jpl.nasa.gov)
Disclaimer: These comments are the personal opinions of the author, and
have not been adopted, authorized, ratified, or approved by JPL.
------------------------------
Date: 8 May 1998 15:57:32 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: ANNOUNCE: Perl Builder IDE Now Available
Message-Id: <6iva1c$ke23@eccws1.dearborn.ford.com>
gb@hugo.westfalen.de (Georg Bauer) writes:
> Tom Phoenix <rootbeer@teleport.com> wrote:
> > Of course, there's no way to always get the colors correct unless
> > you have an error-proof way of parsing Perl - which no one has yet
> > invented. :-)
>
> Makes me wonder how Perl does it, then.
If you mean perl, the popular implementation of the language Perl,
then stop wondering. It doesn't. (But it comes *really* close!) ;)
- Ken
--
Ken Fox (kfox@ford.com) | My opinions or statements do
| not represent those of, nor are
Ford Motor Company, Powertrain | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section | "Is this some sort of trick
| question or what?" -- Calvin
------------------------------
Date: Fri, 08 May 1998 11:23:18 -0600
From: snowbird <snowbird@pcisys.net>
Subject: Better Sort?
Message-Id: <35533F85.8DE7B645@pcisys.net>
Is there a way to perform the sort below without having to use the tmp
hash?
I have an array of patch names that I would like to sort, first by the
alpha identifier and then the numeric identifier.
A list of:
PHSS_9928 PHSS_10234 PHSS_1133 PHCO_3234 PHCO_11011 PHKL_8872
would sort as:
PHCO_3234 PHCO_11011 PHKL_8872 PHSS_1133 PHSS_9928 PHSS_10234
Breaking the patch names into a tmp hash and then performing the sort is
the only way that I can get this to work, can it be done with one sort {
BLOCK } withou the hash? for ( sort { BLOCK } @arr ) { .....
#!/usr/bin/perl -w
@arr = qw(PHSS_9928 PHSS_10234 PHSS_1133 PHCO_3234 PHCO_11011
PHKL_8872);
for ( @arr ) {
m/(PH...)(\d+)/; # split the patch name PHSS_9928 =>
$1=PHSS_ $2=9928
$tmp{$2} = $1; # $tmp{9928} = PHSS_
}
# now sort the hash
for ( sort { $tmp{$a} cmp $tmp{$b} || $a <=> $b } keys %tmp ) {
print " $tmp{$_}$_\n";
}
__END__
Thanks for any help,
Andrew
------------------------------
Date: 8 May 1998 15:51:59 GMT
From: Art Cohen <upsetter@shore.net>
Subject: Re: COUNTING DAYS UNTIL 2000
Message-Id: <6iv9mv$ol2@fridge.shore.net>
I R A Aggie <fl_aggie@thepentagon.com> wrote:
: I still await evidence that this load time is greater than the lag time
: of the network.
Well, I can take a simple script like this:
#!/usr/bin/perl
use Date::Manip;
print "Hello World\n";
and time the load time with my WRISTWATCH (approx 2.5 seconds). That's not
anything I would ever want to put in a cgi script.
--Art
National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html
------------------------------
Date: 8 May 1998 09:43:19 -0700
From: mcravit+usenet@mcravit.vip.best.com (Matthew Cravit)
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <6ivcn7$fp9$1@shell3.ba.best.com>
In article <894531613.87925@thrush.omix.com>,
Zenin <zenin@archive.rhps.org> wrote:
>
> That's the point. At the *exact* time you're trying to send this
> mail the SMTP server must be up and available. You also have to
> *hard code* it's address into your application. And guess what? You
No, you don't. There are any number of ways you could safely solve this
problem. For example, you could use the Net::DNS module to find the defined
MX hosts for the domain you're connecting to, and try them one at a time
until you get a connection.
> much less portable and reliable SMTP or whatever methods to deliver
> it.
SMTP is less reliable then sendmail? Huh? Sendmail _talks_ SMTP. And if you
accept your assertion that all systems should have a sendmail daemon, what's
to stop me from pointing the Net::SMTP module at a sendmail daemon running
on my local machine, if it's available?
>: - Non-existant
>
> Name a single flavor of Unix that does not include sendmail.
I have worked at sites where Sendmail has been disabled on all but the mail
relays for policy reasons. If your script is not running on the mail relay,
and the machine it is running on isn't running and can't be running Sendmail,
>: - In a non-standard location
>
> Name a single flavor of Unix that doesn't have sendmail in either
> /usr/sbin or /usr/lib.
Again, I've worked at sites where sendmail was located in an automounted
directory (such as /tools/sendmail) so that it could be updated without
having to reinstall it on all of the machines each time.
>: - Improperly configured
>
> Just as easy to have a mis-configured SMTP server.
Yes; in fact, in many cases they're the same thing, since many SMTP servers
run Sendmail.
> Yep. And if you're on any working and properly configured Unix system
> this is a vary reliable given.
Right...but a working and properly configured UNIX system which is running
a properly configured, non-buggy version of Sendmail, is NOT always a given.
That's my point.
/MC
--
Matthew Cravit, N9VWG | Experience is what allows you to
E-mail: mcravit@best.com (home) | recognize a mistake the second
mcravit@net.com (work) | time you make it.
------------------------------
Date: 8 May 1998 12:28:29 -0500
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <6ivfbt$a1f$1@Jupiter.Mcs.Net>
In article <894597310.838511@thrush.omix.com>,
Zenin <zenin@archive.rhps.org> wrote:
> >snip<
>
> Think about this; If where were printing files instead of sending
> mail, would you me manually connecting to a remote lpd instead of
> calling lpr? Think hard about this, because this is the *exact*
> same case as with sending mail. The *exact* same case... Your
> application is working at the *wrong* level of the protocal stack,
> it's that simple.
As it happens it is equivalent and it's not that simple when you
want the script to work on machines that don't have the tools
you take for granted in a unix environment. You may want to print
to a machine running lpd somewhere and you may very well not
have a correctly configured lpd at your disposal. If you can
talk to a socket you can get the job done, but it is hard to say
whether it is the right thing to do or not. Maybe what we need
are exact perl equivalents of sendmail, lpr, etc. to drop into
such machines so the other scripts don't need to care.
Les Mikesell
les@mcs.com
------------------------------
Date: 08 May 1998 10:44:41 -0700
From: Paolo Ciccone <p-ciccone@usa.net>
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <wkogx8ejxy.fsf@usa.net>
>>>>> "Zenin" == Zenin <zenin@archive.rhps.org> writes:
Zenin> Paolo Ciccone <p-ciccone@usa.net> wrote:
>> snip<
Zenin> : My point was : that since they are free and quite well
Zenin> documented and maintained in : CPAN, criticizing them is
Zenin> really inappropriate.
Zenin> Hmm, since I have made modules freely available at
Zenin> CPAN, would I gain the right to criticize them? :-)
I espressed myself poorly. A good critique is obviously a good way of
improving quality. There are people, though, that complain because
some freeware is not at the same level, their opinion, of commercial
software. For example some modules are shipped with man pages instead
of other formats. While I felt the frustration of not being able to
read that kind of documentation (I work on WinTel) I don't think it's
correct to denigrate the software or the author for that. After all
the software is free so the author has no obligation to deliver
HTML/WinHelp/Postscritp/Your-format-here. If I download an HTML parser
that does the job but it's not performing I believe it's appropriate
to thank the author and not complain because the module is not
optimized. In Italy we use to say that, with some people, if you give
them a hand they will take thew whole arm :).
--Paolo
------------------------------
Date: 8 May 1998 17:29:00 GMT
From: wayne@Glue.umd.edu (Wayne C. McCullough)
Subject: Re: exists and -w messages
Message-Id: <6ivfcs$d21$1@hecate.umd.edu>
Martien Verbruggen (mgjv@comdyn.com.au) wrote:
: In article <6iqlcc$2id$1@hecate.umd.edu>,
: wayne@Glue.umd.edu (Wayne C. McCullough) writes:
: > Whenever I use an exists command on a hash entry, and the
: > command turns false, I get a warning if I have -w on. I
: What's the warning? What does perldiag have to say about it? Are you
: sure perl is complaining about the exists?
: # perldoc perldiag
: > understand the logic, but is there a way to supress that without
: > turning off -w?
: I don't have a warning
Well, what happend was I was doing a:
if (exists($foo{$bar}))
on an undefined $bar. soo...
Yes, I am embarassed.
But thank you.
W
------------------------------
Date: Fri, 08 May 1998 09:21:50 -0700
From: news@russo.org (Chris Russo)
Subject: Re: Grieving our dying community
Message-Id: <news-0805980921500001@buzz.alink.net>
In article <6ismnc$n4a$1@ns1.arlut.utexas.edu>, smcdow@arlut.utexas.edu
(Stuart McDow) wrote:
>nvp@shore.net (Nathan V. Patwardhan) writes:
>>
>> The "where do you want to go today?" generation has taken the
>> developer out of the "programmer" by removing the vital, development
>> tools from the environment and precanning software.
>
>No kidding. Point. Click. Point. Click. Point. Click. Brain Atrophy.
I think that you guys are taking a bit too much of a "nurture" spin on
this. "Nature" is equally to blame, as usual.
News flash: Most people are stupid. More at eleven.
Not having a built-in compiler, but having an easy-to-use interface on my
Macintosh never kept me from learning what my control panels did or how to
read documentation when something went wrong.
The low prices and easy-to-use interfaces didn't *only* spoil some
perfectly good netizen. They also removed the gates protecting our
kingdom.
Attention: The Barbarians are now in the compound. Please proceed to the
new protected area, comp.lang.perl.moderated.
Don't you just love social experiments? :^)
Regards,
Chris Russo
--
Chris Russo
news@russo.org
http://www.russo.org
------------------------------
Date: Fri, 8 May 1998 18:23:54 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Help me Please!
Message-Id: <6ivf4a$dbp$1@plug.news.pipex.net>
>What kind of WEB server do I need to run perl scripts?
>Is it ok to use free web space on www.geocities.com or
>www.xoom.com?
No, no personal-web-space ISP (to my knowledge) will allow you to run CGI
scripts of any kind, perl or otherwise. A commercial ISP probably will, but
they usually prefer to look over scripts/source beforehand.
If it's simply for testing purposes, you can DL a copy of Apache for just
about any platform, and run it locally.
Of course, if it's just PERL (and not CGI scripts), you can just run them
from the command line.
- Jeremy Goldebrg
------------------------------
Date: 8 May 1998 17:34:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help me Please!
Message-Id: <6ivfmu$1ai$1@marina.cinenet.net>
Yurik (nobadnews_yurik5@usa.net) wrote:
: What kind of WEB server do I need to run perl scripts?
You don't need a web server, or (for that matter) to be connected to the
net at all, in order to run perl scripts. I routinely run perl scripts
on boxes with no active net connection. Perl is a general-purpose
programming language. The fact that it's often used as a Web CGI
implementation language is just a social phenomenon, not anything
intrinsic to the language (other than that Perl's text-processing
abilities make it a good *choice* of CGI language, of course).
: Is it ok to use free web space on www.geocities.com or
: www.xoom.com?
If you're asking if these services will allow you to install CGI
applications (in Perl or some other language), you'll have to check with
them, but I don't believe so.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Fri, 08 May 1998 12:08:21 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: how to create name for temporary file
Message-Id: <35532DF5.BEF2F206@matrox.com>
> >Jeff Trawick <trawick@ibm.net> writes:
> >
> >> Are there any functions in the standard Perl 5.004
> >> distribution to create names for temporary files
> >> (like tmpnam() in C Standard Library)?
> >
> >A quick search through the docs reveals: POSIX::tmpnam()
> >
Why bother? A file is as temporary as you want it to be!
Just create a file (I would call it MYFILE.TEMP or whatever),
do whatever you wanna do with it, then unlink() it!
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Fri, 8 May 1998 12:02:44 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: How to delete an element in an array?
Message-Id: <1d8pfhg.16xeabw1m53eo0N@slip166-72-108-18.ny.us.ibm.net>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> In comp.lang.perl.misc, kpreid@ibm.net (Kevin Reid) writes:
> :Tom Christiansen <tchrist@mox.perl.com> wrote:
>
> >mjd:But for this person, the real, unasked
> >mjd:question is `what's the best way to do sets in Perl?', and the right
> >mjd:answer to this question is usually (not always, but usually) ``do sets
> >mjd:with hashes, not lists.''
>
> :> And that small remainder of the time, it's probably bit vectors.
> :Only applicable if your sets are made of small numbers.
>
> Not true! It's applicable so long as you not have infinite
> elements. Off the top of my head:
>
> sub Set::contains {
> my($vector, $element) = @_;
> my $bitno = elt2bit($element);
> return vec($Set::vector, $bitno, 1);
> }
>
> sub Set::add {
> my($vector, @elements) = @_;
> for my $element( @elements ) {
> my $bitno = elt2bit($element);
> vec($Set::vector, $bitno, 1) = 1;
> }
> }
>
> sub Set::delete {
> my($vector, @elements) = @_;
> for my $element( @elements ) {
> my $bitno = elt2bit($element);
> vec($Set::vector, $bitno, 1) = 0;
> }
> }
>
> sub Set::clear { $_[0] = '' if @_ }
>
> sub Set::isempty { $_[0] =~ /^\0*$/i }
>
> $Set::BITS_SEEN = 0;
> sub Set::elt2bit {
> my $name = shift;
> unless (defined $Mapping{$name}) {
> $Mapping{$name} = $BITS_SEEN++;
> }
> $Mapping{$name};
> }
To me, that code looks like it's using a hash to store the positions of
the bits; if you're going to use a hash, why not just store the
true/false values in the hash?
The advantage to this code (that it stores the data compactly) is offset
by the need to store the name->position table; so you only get space
savings if you are going to store a large number of sets with the same
element names.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 8 May 1998 17:38:12 GMT
From: mjd@linc.cis.upenn.edu (Mark-Jason Dominus)
Subject: Re: How to delete an element in an array?
Message-Id: <6ivfu4$4b2$1@netnews.upenn.edu>
In article <3551F522.684C5B31@matrox.com>,
Ala Qumsieh <aqumsieh@matrox.com> wrote:
> That's cheating ... not solving the problem.
Yes, that's the whole point: Some problems aren't worth solving.
As a Great Sage once said: ``You must master the art of fighting by not
fighing.''
--
Mark-Jason Dominus
mjd@plover.com
------------------------------
Date: 8 May 1998 17:51:53 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to delete an element in an array?
Message-Id: <6ivgnp$536$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
kpreid@ibm.net (Kevin Reid) writes:
:To me, that code looks like it's using a hash to store the positions of
:the bits; if you're going to use a hash, why not just store the
:true/false values in the hash?
You don't want a full hash per set. And you want
this kind of thing to be blazingly fast. Which it is.
$intersect = $set1 & $set2;
$union = $set1 | $set2;
:The advantage to this code (that it stores the data compactly) is offset
:by the need to store the name->position table; so you only get space
:savings if you are going to store a large number of sets with the same
:element names.
That's true. But the space savings is incredible. You really won't
believe it.
--tom
--
There is always a better way.
-- Thomas Edison
------------------------------
Date: Fri, 08 May 1998 11:12:14 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: How to export constants in modules without C code
Message-Id: <35532EDD.2DF12915@mindspring.com>
Ken Fox wrote:
>
> Ephrayim "EJ" Naiman <enaiman@ndsisrael.com> writes:
> > I'm trying to figure out how to make export constants in modules
> > without having to generate any C code ...
> >
> > use my_module;
> >
> > $ret_code = my_module::func($foo1, $foo2);
> > if($ret_code == ERR_NOT_FOUND)
>
> Use @EXPORT and prototyped subroutines:
>
> package my_module;
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw(ERR_NOT_FOUND);
> sub ERR_NOT_FOUND () { 47 }
>
Or, if you don't mind the "$", and would like to avoid the subroutine
call, try:
> package my_module;
> require Exporter;
> @ISA = qw(Exporter);
> @EXPORT = qw($ERR_NOT_FOUND);
> $ERR_NOT_FOUND = 47;
Or, come to think of it, why not export a whole hash with the names of
the errors as keys, and the values as, um, values?
------------------------------
Date: 8 May 1998 15:59:55 GMT
From: Rich Reardon <reardon@maroon.tc.umn.edu>
Subject: Multiline substitution from command line in Perl 4. How?
Message-Id: <6iva5r$dvm@epx.cis.umn.edu>
Say I have the following lines in a text file:
Here is one line
and yet another.
Using Perl 4 from the command line, if I write...
perl -pi.bak -e "s/line\nand/replacestring/;" target.txt
it will not find the pattern, yet...
perl -pi.bak -e "s/line\n/replacestring/;" target.txt
WILL find the pattern and replace it.
In my Perl 4 files, I use $*=1, but I don't think I can add that to the
command line code, and because it's Perl 4, I don't have the "m"
(multiline) argument.
Am I up the perly creek?
------------------------------
Date: Fri, 08 May 1998 12:05:20 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Problem with xemacs and perl syntax hilitghtning
Message-Id: <35532D40.CE0D8303@matrox.com>
Gerd Schering wrote:
> Hi,
>
> I think many of you use (x)emacs as develloping environment, as do I.
> Now I upgraded my old xemacs to the new 20.4.
>
> When editing a "*.pl" file (cperl-mode get's autoloaded), perl words
> like "print", "qw", etc. are displayed in PaleGreen, which is hard to
> read on my gray background (which I want to keep).
> It only happens with perl, not with c nor c++.
>
> I dont know how to change this behaviour. I even dont know where to look
> for. I doesn't come from my '.emacs' file and the 'site-star.el' that comes
> with the new xemacs distribution is empty.
>
> Could someone give me a hint?
>
> Thank's
> Gerd
Ask somewhere else ..
how about a newsgroup that discusses emacs?
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: 08 May 1998 10:33:12 -0500
From: Aaron Baugher <abaugher@rnet.com>
Subject: Re: QRe: == vs. eq
Message-Id: <m2zpgseq13.fsf@haruchai.rnet.com>
"Allan M. Due" <due@discovernet.net> writes:
> Any suggestions for "real newsreaders" for those of us doomed to
> operate in a Windoze environment.? Or, are we only real if we
> have access to UNIX?
Yes. :-) Seriously, though, take a look at the Good Net-Keeping Seal
of Approval <http://http.bsd.uchicago.edu/~twpierce/news/index.html>.
It doesn't list Outlook, but it lists a lot of newsreaders and how
close they come to meeting the news-related RFC's. If you have a
choice, support good Internet programming by using a program that
performs it correctly.
> Feeling a bit surreal myself at the moment. Never thought I would
> be judged by my header.
People in many newsgroups have noticed over the years that an
unusually high percentage of posts from aol.com are of the "HI I NEED
HELP WITH ${STUPID_FAQ} PLEASE MAIL ME CAUSE I DONT READ THIS GROUP
THANX D00D$" variety (though webtv and msn.com have spread the
wealth). Those intelligent people who are for some reason stuck with
an aol.com account dislike that characterization, but the fact is that
in any community, individuals will be judged partially by the company
they keep. On the net, using software that makes like more difficult
for other programmers and users is like hanging around with a gang
that likes to break windows in real life. Netiquette applies not only
to your messages, but to the software that sends them.
Enough from the soapbox.
--
Aaron Baugher
Extreme Systems Consulting
CGI, Perl, Java, and Unix Administration
http://haruchai.rnet.com/esc/
------------------------------
Date: Fri, 08 May 1998 13:12:29 -0600
From: Frank Meng <mengyu@mail.utexas.edu>
Subject: Re: settime
Message-Id: <35535918.232D@mail.utexas.edu>
Frank Meng wrote:
>
> I think I can get the time value out of system like this:
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> (localtime(time))[0..8];
> Now I want to have a value for one month ago.
> I can write
> $mon = $mon - 1;
> I want to compare two times. But how can I set it back as a TIME?
> --
> --------------------------------------
> Communicate with others !
> http://thunder.prohosting.com/~yunyu/
I found a book which said "timegm" or "timelocal" can convert
the array to TIME type. I tried but it doesn't work.
Who know how to use these functions?
Thank you.
------------------------------
Date: Fri, 8 May 1998 15:59:32 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: Tip: Hash Slices
Message-Id: <35532BE4.6800@world.northgrum.com>
Nathan Torkington wrote:
>
> You know what an array slice is, right? It's when you say:
> @array[1, 3, 4]
>
> This works as if you had said:
> ( $array[1], $array[3], $array[4] )
>
> Note that we say @array[1,3,4] not $array[1,3,4] -- the former
> is a list, so generates list context if you assign to it. The
> latter is a normal subscript operation, extracting the 4th
> element in @array, but it generates list context and it ignores
> the "1,3" part of the subscript. Don't confuse 'em!
>
You WILL confuse your readers if you say "list context" when discussing
$array[1,3,4].
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: 8 May 1998 16:49:34 GMT
From: John Mosey <mosey@alpha3.csd.uwm.edu>
Subject: Using frames in perl: How to select target
Message-Id: <6ivd2u$vcq$2@uwm.edu>
How do I tell my prel script to put it's output into a certain frame?
Also, how do I have the script refresh a page when the output has changed?
John Mosey
--
John Mosey Unoffical President
Webmaster of the Unoffical
www.mosey.com Scott Elarton Fan Club
"We do in-season too." "Scott got the shaft again!"
"He's got the best hanging-curve I've ever seen, his fastball mores more
than his curve. He wouldn't even make the rotation on this little league
team."
- EX assisstant little league Coach Mike Spearman on John Mosey's pitching
------------------------------
Date: Fri, 08 May 1998 13:08:12 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Using frames in perl: How to select target
Message-Id: <comdog-ya02408000R0805981308120001@news.panix.com>
Keywords: from just another new york perl hacker
[follow-ups set]
In article <6ivd2u$vcq$2@uwm.edu>, John Mosey <mosey@alpha3.csd.uwm.edu> posted:
>How do I tell my prel script to put it's output into a certain frame?
>Also, how do I have the script refresh a page when the output has changed?
after reading the documents in the CGI Meta FAQ, wander over to
comp.infosystems.www.authoring.cgi.
good luck :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: 8 May 1998 12:44:37 -0500
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Win95 Perl scripts DONT WORK on UNIX
Message-Id: <6ivga5$a8p$1@Jupiter.Mcs.Net>
In article <Esn8AM.9vu@world.std.com>,
Andrew M. Langmead <aml@world.std.com> wrote:
>[In a discussion of Control-M's in scripts]
>
>>Is there some reason it isn't treated as white space? I thought
>>postscript got this right - why not perl?
>
>There are a couple of places where perl is sensitive to
>whitespace. Here documents and formats come to mind. Actually, any
>kind of quoting, but to a lesser extent.
>
>Earlier versions of perl did not complain about control-M characters
>and did just treat them as whitespace, but it broke peoples scripts in
>subtle and confusing ways. I guess it was decided that a mandatory
>warning would be less subtle and less confusing. I noticed that in the
>perl5porters mailing list there was a discussion on how to be more
>forgiving (One solution that I remember was examining the "#!" line
>for its line ending, and using that for all subsequent lines) but I
>don't think that anyone came to a consensus for how to solve, or even
>whether to solve the problem.
The place where it is a problem is where you have arranged transparent
filesystem access between your windows and unix machines and would
like to use your favorite editor for everything. I happen to like
vi on unix so I haven't run into this often myself. I guess the
here document problem makes sense. However, wouldn't it work to
treat all unquoted control-M's as white space and have an explict
variable setting to control quoted line endings? This would have
to appear before the quoted ones and would just tell the parser
to rip them off. I suppose all of the printable single-character
punctuation variables are taken already $#,$|, etc....
Les Mikesell
les@mcs.com
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2541
**************************************