[19297] in Perl-Users-Digest
Perl-Users Digest, Issue: 1492 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 10 21:05:36 2001
Date: Fri, 10 Aug 2001 18:05:13 -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: <997491913-v10-i1492@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 10 Aug 2001 Volume: 10 Number: 1492
Today's topics:
Re: Advise on using perl to sort and give totals <ren@tivoli.com>
Apache::MP3::Playlist problem <nobody@nowhere.com>
Re: Apache::MP3::Playlist problem <nobody@nowhere.com>
Re: ASCII-Code in perl <miscellaneousemail@yahoo.com>
Re: ASCII-Code in perl (E.Chang)
Re: Can't Negate Regex /^8([0876])\1\d+$/ <ren@tivoli.com>
Re: DBI:CSV SQL 'order by' problem <goldbb2@earthlink.net>
Re: Different ways to open a file <bwalton@rochester.rr.com>
Re: FAQ: full text version? (Tad McClellan)
Re: FAQ: full text version? <gnarinn@hotmail.com>
Re: FAQ: full text version? <bart.lateur@skynet.be>
FAQ: How do I make a temporary file name? <faq@denver.pm.org>
Re: filename expansion <goldbb2@earthlink.net>
Re: Help - Substitution using a variable (Tad McClellan)
Re: How can I get variables interpeted in qw// ? (Tad McClellan)
Re: How could chomp the blanks of one sentence? (Tad McClellan)
Re: Is an element in a table ? (Abigail)
Re: Is an element in a table ? <tinamue@zedat.fu-berlin.de>
Re: Is an element in a table ? <tinamue@zedat.fu-berlin.de>
Re: Learning Perl, 2nd Edition <wsegrave@mindspring.com>
Re: Learning Perl, 2nd Edition (Tad McClellan)
MIME::Lite::HTML <aaronb@spamcop.net>
Re: MIME::Lite::HTML <dan@nospam_dtbakerprojects.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 09 Aug 2001 22:41:30 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Advise on using perl to sort and give totals
Message-Id: <m3snf0inth.fsf@dhcp9-161.support.tivoli.com>
On Fri, 10 Aug 2001, brentdax1@earthlink.net wrote:
> "Ren Maddox" <ren@tivoli.com> wrote in message
> news:m3r8ukc1vx.fsf@dhcp9-161.support.tivoli.com...
>> On 9 Aug 2001, anno4000@lublin.zrz.tu-berlin.de wrote:
>>
>> > According to sammy <sammy@bigpond.net.au>:
>>
>> [snip]
>>
>> >> #!/usr/local/bin/perl -wl
>> >> $_{(split)[0]}++ while (<>);
>> >> print "$_\t$_{$_}" for sort { $_{$b} <=> $_{$a} } keys %_;
>>
>> [snip]
>>
>> > It also contains a subtle blunder: The parens around <> in the
>> > second line make it slurp the whole file.
>>
>> What makes you say that? Those parens don't change the context.
>> Parens seldom (never?) change the context of what the contain.
>
> Seldom. The only time parens change context is when they're around
> the lvalue of an assignment:
>
> $foo=<STDIN>; #scalar context
> ($foo)=<STDIN>; #list context
> $foo=(<STDIN>); #scalar context
> ($foo)=(<STDIN>); #list context
>
> See the pattern?
Yes, I was aware of that. I considered pointing it out but decided to
restrict my statement instead. Notice that I said that parens don't
change the context of what they *contain*.
This really goes back to the common confusion about what creates
lists. The answer is that list context creates lists. Parens don't
create lists. Commas don't create lists. Arrays don't create lists.
The confusion is increased by the fact that "=" binds more tightly
than ",", so parens are often needed for list assignment. My normal
example to clarify this is:
my @a = do { 1, 2, 3 };
print "@a\n";
Back to the original point -- I still can't think of an example where
parens change the context of what they contain.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 10 Aug 2001 15:56:03 -0700
From: Phil Voris <nobody@nowhere.com>
Subject: Apache::MP3::Playlist problem
Message-Id: <3B746683.9060001@nowhere.com>
I've been working with this module for a while today; overall it works
fine. However, the user-defined playlist functionality is not there.
I have cookies enabled on my browser, and my http.conf (linux apache)
reads :
## Phil Aug 10 01
AddType audio/mpeg mp3 MP3
AddType audio/playlist m3u M3U
<Location /streaming_mp3>
SetHandler perl-script
# Playlist
PerlHandler Apache::MP3::Playlist
PerlSetVar CacheDir /usr/tmp/mp3_cache
</Location>
Any idea what would do this? My error log just says:
...
[Fri Aug 10 15:47:32 2001] [warn] No recognized sort fields passed to
sort_mp3s()
[Fri Aug 10 15:48:54 2001] [error] [client 64.81.192.234] File does not
exist: /var/www/html/default.ida
...
Thanks,
Phil
------------------------------
Date: Fri, 10 Aug 2001 17:23:46 -0700
From: Phil Voris <nobody@nowhere.com>
Subject: Re: Apache::MP3::Playlist problem
Message-Id: <3B747B12.2080600@nowhere.com>
My sincerest apologies for resolving my own problem AFTER posting it.
It appears that I did not have the cookies module installed.
Apache::MP3 didn't indicate during the installation process that this
module was required for that functionality, although, in fairness, the
docs did indicate that this functionality required cookies.
Phil
Phil Voris wrote:
> I've been working with this module for a while today; overall it works
> fine. However, the user-defined playlist functionality is not there.
>
> I have cookies enabled on my browser, and my http.conf (linux apache)
> reads :
>
>
> ## Phil Aug 10 01
>
> AddType audio/mpeg mp3 MP3
> AddType audio/playlist m3u M3U
>
> <Location /streaming_mp3>
> SetHandler perl-script
>
> # Playlist
> PerlHandler Apache::MP3::Playlist
>
> PerlSetVar CacheDir /usr/tmp/mp3_cache
> </Location>
>
>
> Any idea what would do this? My error log just says:
> ...
> [Fri Aug 10 15:47:32 2001] [warn] No recognized sort fields passed to
> sort_mp3s()
> [Fri Aug 10 15:48:54 2001] [error] [client 64.81.192.234] File does
> not exist: /var/www/html/default.ida
> ...
>
> Thanks,
> Phil
>
------------------------------
Date: Fri, 10 Aug 2001 23:04:51 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: ASCII-Code in perl
Message-Id: <MPG.15de165b6500e224989729@news.edmonton.telusplanet.net>
In article <4259465b.0108070750.3e45a9e@posting.google.com>, wade at
jjchen@alumni.ice.ntnu.edu.tw says...
> If you want to translate not only a char but string, you can try
> perldoc -f pack/unpack.
perldoc -f pack/unpack does not appear to be available under Win98.
perldoc -f chr and perldoc -f ord are.
--
Carlos
www.internetsuccess.ca
------------------------------
Date: Fri, 10 Aug 2001 23:36:29 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: ASCII-Code in perl
Message-Id: <Xns90F9C8294C8D9echangnetstormnet@207.106.92.86>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote in
<MPG.15de165b6500e224989729@news.edmonton.telusplanet.net>:
[snip]
>perldoc -f pack/unpack does not appear to be available under Win98.
>perldoc -f chr and perldoc -f ord are.
>
Try "perldoc -f pack" and "perldoc -f unpack"
--
EBC
------------------------------
Date: 09 Aug 2001 23:09:07 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Can't Negate Regex /^8([0876])\1\d+$/
Message-Id: <m3n158imjg.fsf@dhcp9-161.support.tivoli.com>
On 9 Aug 2001, victor@t-net.net wrote:
> I am trying to negate the following regex which I am using
> to filter toll free numbers. The regex seems to work fine as
> is but when I try to negated it won't work.
>
> $regex =~ /^8([0876])\1\d+$/;
>
> even though I have tried many different combinations like
>
> /^[^8([0876])\1]\d+$/
> /^[^8([0876])]\1\d+$/
>
> I can't get it to work properly. Any help is welcome.
Usually, you would just negate the operation, either by using "!~"
instead of "=~" or by negating the result (eg. use "unless" instead of
"if").
However, this question is often asked in a slightly different context
-- only the regex can change and not the code. The general answer to
that is to use a negative lookahead.
/^(?!8([0876])\1\d+$)/
Depending on the original regex, it can be more complicated. In
particular, negating unanchored patterns requires:
/^(?!.*pattern)/;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 10 Aug 2001 19:38:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBI:CSV SQL 'order by' problem
Message-Id: <3B747059.B15A5A9A@earthlink.net>
Bill Neisius wrote:
>
> I've got a CSV file with a field containing 'paragraph' numbers which
> look something like this:
>
> para,descr...
> 5.13.1,"C description"...
> 5.13.2,"A description"...
> 5.13.3,"B description"...
>
> The SQL select from this table:
>
> select para, descr from paragraph order by para, descr
>
> return the rows in this order:
> 5.13.2,"A description"
> 5.13.3,"B description"
> 5.13.1,"C description"
>
> If I prefix the paragraph numbers with a letter, the 'order by' works
> and returns the paragraphs in the proper order...
>
> Evidently, since the paragraph number starts with a number, Perl
> assumes that I want a numeric sort? which works fine till it gets to
> the second decimal point...
> and throws away the rest of the field as non-numeric?
>
> Any way to get Perl (actually the SQL statement package) to ONLY do an
> alpha sort here? Looks like a bug in Statement.pm: I guess I could
> change it there, but maybe there's a better way?
Which package are you using to make your CSV file act as an SQL
database? DBD::AnyData, or DBD::CSV ?
I don't think it matters much at the moment, since neither seems to
support a way of specifying column types. Try changing the CSV file so
that the first column is always quoted, even if it doesn't contain
commas, spaces, etc.
--
I need more taglines. This one is getting old.
------------------------------
Date: Sat, 11 Aug 2001 00:25:35 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Different ways to open a file
Message-Id: <3B747BC6.C09C3628@rochester.rr.com>
Tad McClellan wrote:
>
> Etienne Laverdiere <etienno@sympatico.ca> wrote:
> >Hi I have a simple question, what is the difference between :
> >
> >if (open (FO, '<'.$thefileName)){
> > while (<FO>){
> > $ficReturn .= <FO>;
> > }
> > close FO;
> > }
> >
> >and
> >
> >if (open (FO, '<'.$thefileName)){
> > undef $/;
> > $ficReturn = <FO>;
> > close FO;
> > }
>
> Both code snippets have the same effect.
Um, not quite. The first will store the 2nd, 4th, 6th etc lines of the
file; the second will store all lines of the file.
...
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
--
Bob Walton
------------------------------
Date: Fri, 10 Aug 2001 16:54:18 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FAQ: full text version?
Message-Id: <slrn9n8ifq.1sj.tadmc@tadmc26.august.net>
me@sersa.omg <me@sersa.omg> wrote:
> "Complete text of these FAQ are available on request."
>
>Could someone please post the full FAQ for a nearly new perlite.
The FAQs are included as part of the standard distribution of perl.
If you have a properly installed perl, then you already have the
FAQs on your very own hard disk.
Find out where. Maybe this will tell you where they are on
your system:
perldoc -l perl
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Aug 2001 00:06:11 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: FAQ: full text version?
Message-Id: <997488371.107964727561921.gnarinn@hotmail.com>
In article <ud29nt02kuqesr75rt4ra0r7bk37qop40q@4ax.com>, <me@sersa.omg> wrote:
(quoting from FAQ autoposting without attribution:)
> "Complete text of these FAQ are available on request."
>
>Could someone please post the full FAQ for a nearly new perlite.
I guess that the line you quoted from the FAQ autoposting means that
the FAQ is available on request from the poster, that is faq@denver.pm.org
gnari
------------------------------
Date: Sat, 11 Aug 2001 00:58:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: FAQ: full text version?
Message-Id: <cj09ntg5fc85qkeg7nv1vhnoppgg0fjlr1@4ax.com>
Tad McClellan wrote:
>>Could someone please post the full FAQ for a nearly new perlite.
>
>
>The FAQs are included as part of the standard distribution of perl.
>
>If you have a properly installed perl, then you already have the
>FAQs on your very own hard disk.
In addition, they're on the web.
<http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq.html>
<http://perlfaq.cpan.org/>
<http://www.cpan.org/doc/manual/html/pod/perlfaq.html>
<http://language.perl.com/newdocs/pod/perlfaq.html>
<http://www.perldoc.com/perl5.6/pod/perlfaq.html>
<http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/lib/Pod/perlfaq.html>
Need more pointers still?
--
Bart.
------------------------------
Date: Sat, 11 Aug 2001 00:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I make a temporary file name?
Message-Id: <0Q_c7.28$V3.170991616@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How do I make a temporary file name?
Use the "new_tmpfile" class method from the IO::File module to get a
filehandle opened for reading and writing. Use it if you don't need to
know the file's name:
use IO::File;
$fh = IO::File->new_tmpfile()
or die "Unable to make new temporary file: $!";
If you do need to know the file's name, you can use the "tmpnam"
function from the POSIX module to get a filename that you then open
yourself:
use Fcntl;
use POSIX qw(tmpnam);
# try new temporary filenames until we get one that didn't already
# exist; the check should be unnecessary, but you can't be too careful
do { $name = tmpnam() }
until sysopen(FH, $name, O_RDWR|O_CREAT|O_EXCL);
# install atexit-style handler so that when we exit or die,
# we automatically delete this temporary file
END { unlink($name) or die "Couldn't unlink $name : $!" }
# now go on to use the file ...
If you're committed to creating a temporary file by hand, use the
process ID and/or the current time-value. If you need to have many
temporary files in one process, use a counter:
BEGIN {
use Fcntl;
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
my $base_name = sprintf("%s/%d-%d-0000", $temp_dir, $$, time());
sub temp_file {
local *FH;
my $count = 0;
until (defined(fileno(FH)) || $count++ > 100) {
$base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT);
}
if (defined(fileno(FH))
return (*FH, $base_name);
} else {
return ();
}
}
}
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.04
--
This space intentionally left blank
------------------------------
Date: Fri, 10 Aug 2001 18:40:30 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: filename expansion
Message-Id: <3B7462DE.A8219F23@earthlink.net>
noident wrote:
>
> "Sean Hamilton" <sh@planetquake.com> wrote in message news:<W66b7.28381$b_3.2357462@news0.telusplanet.net>...
> > What would be the best way to expand a filename, ie
> >
> > ~user/dir/../file
> >
> > to
> >
> > /home/user/file
> >
> $file = '~test/dir/file';
> $file =~ /~([^\/]+)(.*)/g;
First off, the ~ isn't anchored, to the beginning of the string, like it
should be -- the above will end up mangling something like this:
$file = "~test/dir/emacs_made_this~"
[when emacs backs up a file, the backup is the original file plus a ~]
Second, it won't match things like "~/whatever"
Third, why the /g flag? It doesn't accomplish anything AFAIKS.
> $expanded = (getpwnam $1)[7] . $2;
> print "$expanded\n";
$file = '~test/dir1/dir2/../file';
$file =~ s{ ^ ~ ([^/]*) }
{ $1 ?
(getpwnam($1))[7] :
(getpwuid($>))[7]
}xe;
$file =~ s[//+][/]g;
1 while $file =~ s[(?<=/)(?>[^/]+)(?!<\.\.)/\.\.(?=/|\z)][]gx;
--
I need more taglines. This one is getting old.
------------------------------
Date: Fri, 10 Aug 2001 17:38:16 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help - Substitution using a variable
Message-Id: <slrn9n8l28.1sj.tadmc@tadmc26.august.net>
pcsw2@hotmail.com <pcsw2@hotmail.com> wrote:
>Hi! What I'm trying to do is do a string substitution using a
>variable, and it's not working.
>
>I'm trying to achive the following:
>
> $line = "alias=\$COMPNAME";
> $COMPNAME = "ntsvr05";
> $line =~ s/\$COMPNAME/$var2/g;
Umm. What is the value in $var2 ?
> print "$line\n";
>
> Output:
> alias=ntsvr05
It does not make that output. I assume you meant instead:
$line =~ s/\$COMPNAME/$COMPNAME/g;
>Using variables $var1 and $var2, this section of code does not return
>the desired output:
>
> $line = "alias=\$COMPNAME";
> $COMPNAME = "ntsvr05";
> $var1 = "\$COMPNAME";
> $var2 = $COMPNAME;
> $line =~ s/$var1/$var2/g;
> print "$line\n";
>
> Output:
> alias=$COMPNAME
>
>Which is not what I want. Can anybody shed some light on my problem?
You could shed some light your very own self by printing out
your variables and seeing what they contain. My bet is that they
are not getting the values that you think they are getting.
Why not look at them and see?
print "s/$var1/$var2/g;\n";
>What am I doing wrong?
1) typing code instead of using copy/paste or otherwise sending us
on a wild goose chase, taking time away from answering someone
else's question.
2) not enabling strictures (it would appear):
use strict;
3) using double quotes when you do not need one of the two extra
things (interpolation, backslash escapes) that they give you
over single quotes.
$var1 = "\\\$COMPNAME"; # double quotes eat backslashes...
or
$var1 = '\$COMPNAME';
Which one do you think is easier to read and understand?
Don't use double quotes when single quotes will do.
>Thanks!
You're welcome.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 10 Aug 2001 18:07:34 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How can I get variables interpeted in qw// ?
Message-Id: <slrn9n8mp6.2ad.tadmc@tadmc26.august.net>
Philip Newton <pne-news-20010810@newton.digitalspace.net> wrote:
>On 10 Aug 2001 14:10:14 -0400, stanb@panix.com (Stan Brown) wrote:
>
>> OK, here is what I' trying to do. In the perlTK "widget" example code the
>> crete a Listbox with scrollbars like this:
>>
>>
>> $entry = $Table->Scrolled(qw/Listbox
>> -height 1
>> -relief 'sunken'
>> -width "$$hash_pointer{$col}{'DATA_PRECISION'}
>> -validate 'focusin'
>> -validatecommand sub
>> {
>> Enter_entry_fields($col)
>> },
>> -setgrid 1 -scrollbars e/);
>
>Hm, I doubt that the example has it like that, because not only will the
>$$hash_pointer{$col}{'DATA_PRECISION'} not work, the sub { ... } will be
>interpreted not as an anonymous sub reference, but as four words (with a
>comma after the fourth word! I think that produces a warning). Oh, and
>the double quote before $$hash_pointer is not paired. And Perl doesn't
>have pointers like C.
I saw all of that when I was deciding if I was going to attempt
further help.
I gave up. :-(
>Something like this should work:
>
> $entry = $Table->Scrolled('Listbox',
> -height => 1,
> -relief => 'sunken',
> -width => $var->{$col}{'DATA_PRECISION'},
> -validate => 'focusin',
> -validatecommand => sub {
> Enter_entry_fields($col)
> },
> -setgrid => 1,
> -scrollbars => 'e',
> );
>
>> the variable just gets passed as a string, and not interpeted.
>> How can I make this work?
>
>Don't put it inside the qw(). "Doctor, it hurts when I do this."
But now that I see Real Code I have something to add. Looks like
all but the first arg are destined for a hash (I dunno Tk), so
the order of the pairs doesn't matter, so we can build up the
list as I first suggested:
$entry = $Table->Scrolled(qw( Listbox
-height 1
-relief sunken
-validate focusin
-setgrid 1
-scrollbars e
),
-width => $var->{$col}{'DATA_PRECISION'},
-validatecommand => sub {
Enter_entry_fields($col)
},
);
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 10 Aug 2001 17:05:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How could chomp the blanks of one sentence?
Message-Id: <slrn9n8j4n.1sj.tadmc@tadmc26.august.net>
anon@anon.com <anon@anon.com> wrote:
>Wenjie ZHAO wrote:
>> Esp in front of the words, e.g. " Hello ", how
>> could perl strip it to "Hello"?
>
>
>The bottom of page 73 in "Programming Perl" (O'Reilly) gives
>
>s/^\s*(.*?)\s*$/$1/
No it doesn't.
The 3rd Edition has been out for over a year now. Folks are going
to assume the current edition. If you are going to cite an old
edition, please say which edition. It appears you have the 2nd edition.
>where the string is in $_
And the answer to the FAQ that is this thread says this about
that code:
"Not only is this unnecessarily slow and destructive, it also
fails with embedded newlines."
And the 3e Camel book no longer has the code above, it instead
has code like in the FAQ answer (p154).
Round and round and round we go, all because the original poster
could not be troubled to check the Perl FAQs before posting to
the Perl newsgroup.
Some people are rather too selfish.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Aug 2001 22:19:08 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Is an element in a table ?
Message-Id: <slrn9n8nfm.8dn.abigail@alexandra.xs4all.nl>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMI September
MCMXCIII in <URL:news:9l0pup$qam$1@mamenchi.zrz.TU-Berlin.DE>:
[] According to Tina Mueller <news@tinita.de>:
[] > Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
[] > > Here is my solution... there must be better :
[] >
[] > > $n = 0;
[] > > foreach (@listA) { # if @listA is smaller
[] > > $n += grep(/^$_$/, @listB);
[] > > }
[]
[] [doesn't work. valid critique snipped]
[]
[] > but you're going through the arrays in O(n^2).
[] >
[] > that can be made quicker:
[] >
[] > my %seen;
[] > my $n=0;
[] > @seen{@a}=(1)x@a;
[] > for (@b) {
[] > $n++ unless --$seen{$_}
[] > };
[]
[] It also naturally avoids the awkward way of using a regex (/^$_$/) for
[] an equality test.
[]
[] Using --$seen is an ingenious technique to secure that each element in
[] $b is counted only once, even if many are present. That wasn't specified,
[] I think, but I like it. If you don't mind the obfuscation, the loop
[] can be compacted:
[]
[] $n += ! --$seen{ $_} for @b;
[]
my (%seen, $n);
@seen {@a} = ();
$n += keys %seen;
delete @seen {@b};
$n -= keys %seen;
# $n now contains the size of the intersection of A and B.
Abigail
--
print 74.117.115.116.32.97.110.111.116.104.101.114.
32.80.101.114.108.32.72.97.99.107.101.114.10;
------------------------------
Date: 10 Aug 2001 23:36:19 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Is an element in a table ?
Message-Id: <9l1r5j$74q3o$1@fu-berlin.de>
Abigail <abigail@foad.org> wrote:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMI September
> MCMXCIII in <URL:news:9l0pup$qam$1@mamenchi.zrz.TU-Berlin.DE>:
> [] According to Tina Mueller <news@tinita.de>:
> [] > Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> [] > > Here is my solution... there must be better :
> [] > > $n = 0;
> [] > > foreach (@listA) { # if @listA is smaller
> [] > > $n += grep(/^$_$/, @listB);
> [] > > }
> [] > my %seen;
> [] > my $n=0;
> [] > @seen{@a}=(1)x@a;
> [] > for (@b) {
> [] > $n++ unless --$seen{$_}
> [] > };
> []
> [] I think, but I like it. If you don't mind the obfuscation, the loop
> [] can be compacted:
> [] $n += ! --$seen{ $_} for @b;
> my (%seen, $n);
> @seen {@a} = ();
> $n += keys %seen;
> delete @seen {@b};
> $n -= keys %seen;
> # $n now contains the size of the intersection of A and B.
anyone up for golf?
shorted version of abigail:
> my(%seen,$n);@seen{@a}=();$n+=keys%seen;delete@seen{@b};$n-=keys%seen;
my%seen;@seen{@a}=(1)x@a;my$n=grep{$_}delete@seen{@b};
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: 10 Aug 2001 23:48:13 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Is an element in a table ?
Message-Id: <9l1rrt$74q3o$2@fu-berlin.de>
Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
> anyone up for golf?
> shorted version of abigail:
>> my(%seen,$n);@seen{@a}=();$n+=keys%seen;delete@seen{@b};$n-=keys%seen;
> my%seen;@seen{@a}=(1)x@a;my$n=grep{$_}delete@seen{@b};
ah, it totally forgot anno's version which is shortest:
| my%seen;my$n;@seen{@a}=(1)x@a;$n+=!--$seen{$_}for@b;
bedtime again i guess... =)
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: Fri, 10 Aug 2001 18:28:47 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <9l1r55$vpp$1@slb7.atl.mindspring.net>
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x766bvmylv.fsf@home.sysarch.com...
***snipped***
> randal was not an author of camel 3 (unlike 1 and 2 where he was an
author).
***snipped***
> and his name is spelled randal.
>
> uri
***snipped***
Thanks, Uri. You're the third person to inform me I spelled Randal's given
name incorrectly.
I did not mean to infer that Randal had any part in Camel 3.
Perhaps my appreciation could be stated better as:
"2. When you're ready for the latest editions, support O'Reilly's (and their
author's) work by picking up the 3rd editions ..."
Bill Segraves
Auburn, AL
------------------------------
Date: Fri, 10 Aug 2001 17:54:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <slrn9n8lvs.2ad.tadmc@tadmc26.august.net>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "WAS" == William Alexander Segraves <wsegrave@mindspring.com> writes:
> WAS> P.S. To Randall: Thank you! Thank you! Thank you!
>
>and his name is spelled randal.
No it isn't.
His name is spelled Randal.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Aug 2001 00:13:47 GMT
From: "Aaron" <aaronb@spamcop.net>
Subject: MIME::Lite::HTML
Message-Id: <%M_c7.7375$PV4.1849084055@newssvr15.news.prodigy.com>
I am trying to use MIME::Lite::HTML but am receiving an error when I run my
program. I am trying to feed the module a variable, but it won't accept it.
It is supposed to be set up like example at the botom of this email (this is
straight from the docs), I am trying to feed it an email address in the form
of $emailAddy (where I have already set the variable equal to an email
address). So instead of
To => 'alian@saturne', --------------- as it is below, I would like
to use
To => '$emailAddy',
But when I do that I get the following error
"Reference found where even-sized list expected at
/usr/lib/perl5/site_perl/5.005/MIME/Lite.pm line 917, <GEN0> chunk 33.
No recipient addresses found in header"
Does anybody have any ideas? I am not familiar with object oriented
programing, so this is quite cryptic to me. I would like to be able to feed
the module email addresses using some type of variable scheme. I am parsing
the email addresses from a file.
Thank you!
Aaron Bazar
use MIME::Lite::HTML;
my $mailHTML = new MIME::Lite::HTML
From => 'MIME-Lite@alianwebserver.com',
To => 'alian@saturne',
Subject => 'Mail in HTML with images';
$MIMEmail = $mailHTML->parse('http://www.alianwebserver.com');
$MIMEmail->send; # or for win user : $mail->send_by_smtp('smtp.fai.com');
--
Aaron B.
http://www.cauce.org (help stop spam)
------------------------------
Date: Sat, 11 Aug 2001 00:49:18 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: MIME::Lite::HTML
Message-Id: <3B74815C.E59BE196@nospam_dtbakerprojects.com>
Aaron wrote:
>
> I am trying to use MIME::Lite::HTML but am receiving an error when I run my
> program. I am trying to feed the module a variable, but it won't accept it.
--------------
...probably because you are using 'instead of " .
check my example posted on 8/6
d
------------------------------
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 1492
***************************************