[23402] in Perl-Users-Digest
Perl-Users Digest, Issue: 5620 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 5 18:05:39 2003
Date: Sun, 5 Oct 2003 15:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 5 Oct 2003 Volume: 10 Number: 5620
Today's topics:
Re: code with style <jaspax@u.washington.edu>
Re: code with style (James E Keenan)
Re: DBI <tore@aursand.no>
Re: examples of sprintf <mikeflan@earthlink.net>
Re: fastest count of instances in string? <REMOVEsdnCAPS@comcast.net>
Re: fastest count of instances in string? <jaspax@u.washington.edu>
Re: fastest count of instances in string? <uri@stemsystems.com>
Re: how to search a specific file on a web server <nospam@peng.nl>
KHAZAR KING KOOK_KKK <true.geologist@atlantic.com>
Re: pattern matching <perl@my-header.org>
Re: pattern matching <nospam@peng.nl>
Re: pattern matching <nospam@peng.nl>
Re: PerlQt question <scriptyrich@yahoo.co.uk>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 5 Oct 2003 11:02:01 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: code with style
Message-Id: <Pine.A41.4.58.0310051048020.96786@dante12.u.washington.edu>
Pedro sikyal:
> Hi all,
>
> I was trying to calculate the max number of variations of the columns on
> an array.
Having read the other posts, I understand what you're trying to do, so I
can give some suggestions.
> use strict;
>
> my @a = (
> [qw/1 2 3 4 5/],
> [qw/2 2 3 2 4/],
> [qw/3 1 2 4 5/]
> );
>
> my $var = maximum_multiplicity(\@a);
>
> print "$var\n";
>
> sub maximum_multiplicity{
>
> my ($a_ref)= @_;
I recommend $a_ref = shift; Both work, though.
> my $mm=0; # maximum multiplicity
> my $length = @{ @$a_ref[0]}; #length of the row
>
> for (my $i = 0; $i<$length;$i++){
This is C-style looping, which is ANATHEMA in perl. Do this instead:
for my $row (@$a_ref) {}
This sets $row equal to each for in $a_ref in turn.
> my %var=();
>
> for my $r (0..$#$a_ref){
Once again, it is rarely necessary to use the $#foo or C-style looping
constructs given here, especially if all you need is an index of an array.
The missing element for you seems to be the for (@array) {} construct. If
you just want to loop over the elements of an array, all you need to do is
put the array inside the parens for 'for'. If you specify a variable
between the 'for' and the parens, the current element is set to that
variable, otherwise '$_' is set to the current element.
With that in mind, rewrite it this way:
sub max_mult {
my $a_ref = shift;
my $mm = 0;
# Loop over each row in @$a_ref
for my $row (@$a_ref) {
# Within this loop, $row contains the current row
my %seen = (); # Will hold values we've seen
for (@$row) {
# Within this loop $_ has the current value
$seen{$_} = undef;
}
if ($mm < keys %seen) {
$mm = keys %seen;
}
}
return $mm;
}
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
------------------------------
Date: 5 Oct 2003 13:44:06 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: code with style
Message-Id: <b955da04.0310051244.6ff3f597@posting.google.com>
pedro.fabre.NO-SPAM@gen.gu.se (Pedro) wrote in message news:<pedro.fabre.NO-SPAM-0510031532170001@192.168.0.5>...
> Hi all,
>
> I was trying to calculate the max number of variations of the columns on
> an array.
>
In Perl, arrays have *elements*, not columns. Arrays of arrays and
hashes of arrays (2-dimensional data structures) may, however, be used
to represent data structures where the data neatly lines up in
row-column (matrix) format.
That being said, I confess I'm not clear as to what you mean by "the
max number of variations of the [elements] of an array." Do you mean
permutations? Combinations?
> I have worked the code on this way. It works fine and I get what I need
> but I think that still my style is not too perl.
>
You're twice using the C-style 'for' loop rather than the more Perlish
'foreach' loop.
> The idea is that I have to take the length of the array in order to
> operate by columns and then go for every element of the row.
>
>
> I am not fully convinced with my style, and I guess this can be done in a
> simpler way.
>
> Any suggestion?
>
>
> Thanks for your help
> P
>
>
> use strict;
use warnings;
>
> my @a = (
> [qw/1 2 3 4 5/],
> [qw/2 2 3 2 4/],
> [qw/3 1 2 4 5/]
> );
>
> my $var = maximum_multiplicity(\@a);
>
> print "$var\n";
>
> sub maximum_multiplicity{
>
> my ($a_ref)= @_;
>
> my $mm=0; # maximum multiplicity
> my $length = @{ @$a_ref[0]}; #length of the row
>
> for (my $i = 0; $i<$length;$i++){
>
> my %var=();
>
> for my $r (0..$#$a_ref){
>
> $var{ $a_ref->[$r][$i] } =1; # new key for every new variation
> my @al = keys %var; # store var in array
>
> # if the number of var for this column is
> # greater than before set $m value as var number
> $mm= scalar @al if (scalar @al >$mm);
See remark about confusion above. Are there any circumstances in
which $m != @a ?
------------------------------
Date: Sun, 05 Oct 2003 22:04:11 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: DBI
Message-Id: <pan.2003.10.04.14.33.50.222955@aursand.no>
On Fri, 03 Oct 2003 15:45:16 +0100, Bigus wrote:
>> just _always_ use placeholders.
> Thanks, I shall heed that - although, for one-off DB commands, I think
> using the $db->quote() method (when used with say a $db->do()) may
> require less lines of code and save the need to open & "finish" other
> handles like $sth->.
The do() method also supports bind;
$dbh->do( 'SELECT * FROM user WHERE user_id = ?', undef, $user_id );
Have a look at 'perldoc DBI' for more information.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Sun, 05 Oct 2003 20:23:30 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: examples of sprintf
Message-Id: <3F807E69.5F717DE@earthlink.net>
Tad McClellan wrote:
> Mike Flannigan <mikeflan@earthlink.net> wrote:
>
> > Perl documentation is short on
> > examples.
>
> huh?
>
> > The sprintf function is the one I'd most
> > like to see examples included in the documentation.
>
> perldoc -f sprintf
>
> I count only 38 examples there. We need more?
I stand corrected. Thanks for pointing that out.
I don't know how I missed that.
I'm reading up on sprintf now, because I definitely
need help in that area. It's a great tool that I use
fairly often, but I still have trouble every time.
Mike
------------------------------
Date: Sun, 05 Oct 2003 13:56:12 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: fastest count of instances in string?
Message-Id: <Xns940B97E889527sdn.comcast@206.127.4.25>
Uri Guttman <uri@stemsystems.com> wrote in
news:x78ynzmwo9.fsf@mail.sysarch.com:
>>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
>
> RJ> Uri Guttman <uri@stemsystems.com> wrote in message
> news:<x74qyonwyb.fsf@mail.sysarch.com>...
> >> >>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
> >>
> RJ> sub str {
> RJ> my ($str, $tr_chars) = @_;
> RJ> $str=~s/$tr_chars//g;
> RJ> }
> >>
> >> that still doesn't do anything useful. how many times do you have
> >> to be told that?
>
> RJ> How many times do you imagine you have told me that? Can you
> explain RJ> why the output of the program is "There are 4 of them."
> when the str RJ> function is called?
>
> have you rtfm'ed about this? the relevant section was posted in this
> thread. tr/// DOES NOT INTERPOLATE.
Uri..... Roy Johnson's code above does not contain a tr///.
--
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
------------------------------
Date: Sun, 5 Oct 2003 11:50:40 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: fastest count of instances in string?
Message-Id: <Pine.A41.4.58.0310051148190.96786@dante12.u.washington.edu>
Roy Johnson sikyal:
> Uri Guttman <uri@stemsystems.com> wrote in message news:<x74qyonwyb.fsf@mail.sysarch.com>...
> > >>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
> >
> > RJ> sub str {
> > RJ> my ($str, $tr_chars) = @_;
> > RJ> $str=~s/$tr_chars//g;
> > RJ> }
> >
> > that still doesn't do anything useful. how many times do you have to be
> > told that?
>
> How many times do you imagine you have told me that? Can you explain
> why the output of the program is "There are 4 of them." when the str
> function is called?
Because the string you are matching against matches against one of the
characters in qw/$ t r _ c h a r s/. '$tr_chars' is interpreted as a
literal string and the tr/// is matched against that. If the character you
attempt to match against give happens to be in '$tr_chars', you will get a
misleadingly correct value.
This has tripped me up as well.
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
------------------------------
Date: Sun, 05 Oct 2003 19:11:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: fastest count of instances in string?
Message-Id: <x7brsvlctf.fsf@mail.sysarch.com>
>>>>> "EJR" == Eric J Roode <REMOVEsdnCAPS@comcast.net> writes:
>>>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
>>
RJ> Uri Guttman <uri@stemsystems.com> wrote in message
>> news:<x74qyonwyb.fsf@mail.sysarch.com>...
>> >> >>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
>> >>
RJ> sub str {
RJ> my ($str, $tr_chars) = @_;
RJ> $str=~s/$tr_chars//g;
RJ> }
RJ> How many times do you imagine you have told me that? Can you
>> explain RJ> why the output of the program is "There are 4 of them."
>> when the str RJ> function is called?
>>
>> have you rtfm'ed about this? the relevant section was posted in this
>> thread. tr/// DOES NOT INTERPOLATE.
EJR> Uri..... Roy Johnson's code above does not contain a tr///.
this was pointed out to me by someone else. then there is another
bug. if $tr_chars has more than 1 char then s/// not delete the
individual chars. he needs a char class for that.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 5 Oct 2003 20:53:34 +0100
From: "Lex" <nospam@peng.nl>
Subject: Re: how to search a specific file on a web server
Message-Id: <cK_fb.6828$Hd.817191@news-reader.eresmas.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbo0lls.dra.tadmc@magna.augustmail.com...
>
> There is no method for achieving that. HTTP does not give you
> access to directories or files, it gives you access to resources
> (the "R" in "URL").
>
>
> But you _can_ extract the links, and return the latest one assuming
> that the date/time is always encoded in the resource's name:
>
Thanks for that, but in fact, the index.html (or .htm i don't remember) is a
bit misleading.
For exmaple, I know that
http://sohowww.nascom.nasa.gov/data/realtime/javagif/gifs_thumb/20031005_1418_mdi_igr.gif
is there as well, and that's today's. In the index file there's only 2001
pictures.
http://sohowww.nascom.nasa.gov/data/realtime/
On this page is always the latest visible, but for that to work you'd have
to know the name. I guess the only method left is to look on this page and
get the image url from it via www::mechanize ?
Thanks a lot for thinking along and the scripts.
Lex (very much newbie)
------------------------------
Date: Mon, 6 Oct 2003 00:04:48 +0200
From: "['] jpturcaud" <true.geologist@atlantic.com>
Subject: KHAZAR KING KOOK_KKK
Message-Id: <3f809588$0$20948$7a628cd7@news.club-internet.fr>
Hoooop !
Here again is my Khazar / Hun / Ashkenazy dog Der Coach ( D.C.) right on
my heels !
Hey ! . Da ya want to see that Khazar King Kook ( KKK) dance ?
Watch Cobbers how that Boise based Newmont / Newcrest and BHP / Billiton
Mining Criminals ' Gogological beast will swing now !!!!!:
DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN
!!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR
WEEN !!!
Dance KKK Dance !
Let's us all whistle a good bluegrasscountry tune to get the Khazar King
Kook swinging more !!!
Why not pick on that boogy boogy tune that everybody knows ! .... good one !
... and it's perfectly harmonise with DAR WEEN !
Again all again with that Evolution Cunt 's name, it makes KKK go berserk
!!! ... and mark a hefty beat with ya boots Mates !!!
GOOOOOOOOOOOOOOOO !!!!!!!!!!!!!!!!!!!!
DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN
!!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR
WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!!
DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN !!! DAR WEEN
!!! DAR WEEN !!!
See how it works ?
Just stop now since I don't want the Newmont / Newcrest and BHP / Billiton
Mining Criminals ' Gogological beast to cark it right now !
The gutless bags of shit might accuse me of murder !!!
I had the dog cut on his 8th day !
Look how he's smart now !
Amazing ?
Yepp !
Anyone want to buy the beast for Lab duties ?
I am giving it away for 10 Quids ... costing me too much feeding him ...
ravenous appetite !
Give us a buzz and it's yours !
( I may even refund the 10 Quids !)
--
Jean-Paul Turcaud
Hydro & Mining Prospector
Pioneer of australian Mining
Discoverer of Telfer; Kintyre & Nifty Mines in The Great Sandy Desert.
Discoverer of the South Atlantic Submarine Gold Placers
_ 40 Millions Tons estimate _
Founder of The TRUE GEOLOGY
"THE GOLDEN RULE"
"Gold and Intrigue in the Desert"
"The true story of the discovery of the Telfer gold mine"
Author : Bob Sheppard, President of the Australian Prospectors' Union
Author's contact & web page : www.tnet.com.au/~warrigal/
Order from : Hesperian Press, PO Box 317 Victoria Park, 6979 W.Australia.
AUS 40.00 + post
Published in Perth 15th December 2002
* The Greatest Australian Mining Covered Up Swindle Of The 20th Century
http://membres.lycos.fr/jpturcaud/
( Is maintained due to Public demand at least up to next Solstice )
* The True Geology ( previously Refutation of the Horrid Geological Myths )
http://membres.lycos.fr/xxx/ ( Not available due to plagiarism hazards )
~~Ignorance Is The Cosmic Sin, The One Never Forgiven ! ~~
" "
snipped the 1st puberty-cut dog's rants
------------------------------
Date: Sun, 05 Oct 2003 21:18:57 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: pattern matching
Message-Id: <vkr0ovc1s6rnnj776o4lc9flgkcs4rrvmv@4ax.com>
X-Ftn-To: Lex
"Lex" <nospam@peng.nl> wrote:
>> my %winfo;
>> for my $word (split /\s+/, $meaning) {
>> @winfo{qw/id plural synonym meaning/} = sub_id($word);
>> }
>>
>> sub_id returns to you values for given $word, and $meaning is already
>> retrieved meaning for initial word.
>
>Hi Matija,
>
>thanks for the reply. I'm a newbie and trying to see what exaclty happens
>with what you wrote.
>
>for my $word (split /\s+/, $meaning) { # every single word in $meaning
> @winfo{qw/id plural synonym meaning/} = sub_id($word);
>
>Shouldn't that be @winfo{qw/word plural synonym/} = sub_id($word);
>Might well be that I don't understand what's going on here...
I don't know your actual code which you used so far so I made up some
function name which retrieves attributes for requested word; eg. if you want
to know all about "stove", sub_id("stove") returns a list of values,
('1', 'stoves', 'heater', 'a thing to warm up a room')
which are then stored in %winfo hash, so $winfo{plural} contains 'stoves',
and so on..
sub_id should open your text file, split lines and return attributes when it
finds wanted word (it could return only meaning if that is all you need).
sub sub_id {
my($word) = @_;
my @values;
my @fields = qw/id word plural synonym meaning/;
...
LINE: while (my $line = <DAT>) {
chomp $line;
my %attr = ();
@attr{@fields} = split /\|/, $line;
for my $field (qw/word plural synonym/) {
if ($attr{$field} eq $word) {
@values = @attr{@fields};
#word and plural have advantage over synonym
last LINE if $field ne 'synonym';
}
}
}
return @values;
}
--
Matija
------------------------------
Date: Sun, 5 Oct 2003 20:47:48 +0100
From: "Lex" <nospam@peng.nl>
Subject: Re: pattern matching
Message-Id: <OE_fb.6826$Hd.816850@news-reader.eresmas.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbo0iqi.dra.tadmc@magna.augustmail.com...
> Any example data?
>
Thanks I'll go and try it!
Sample data:
1|aardscheerder|aardscheerders|||Populaire, uit het Engels (Earth grazer)
afkomstige benaming voor een planetoïde (of komeet) die de aarde zeer dicht
kan naderen.||||||||||
2|aberratie||||Kleine, schijnbare verplaatsing van een hemellichaam in de
richting waarin de waarnemer beweegt.||||||||||
3|absolute helderheid||||Helderheid die een hemellichaam zou hebben wanneer
het zich op een afstand van 10 parsec zou bevinden.||||||||||
4|absorptielijn|absorptielijnen|||Smalle donkere lijn in een
absorptiespectrum, veroorzaakt doordat een specifieke golflengte van het
licht wordt geabsorbeerd door materie die zich tussen de lichtbron en de
waarnemer bevindt.||||||||||
5|abundantie|abondantie|||De relatieve hoeveelheden van de verschillende
scheikundige elementen die in sterren of gasnevels voorkomen.||||||||||
fields:
1 ID
2 word
3 plural
4 synonym
5 category
6 meaning
7 til 17 extra links info (urls & descriptions)
Lex
------------------------------
Date: Sun, 5 Oct 2003 23:00:06 +0100
From: "Lex" <nospam@peng.nl>
Subject: Re: pattern matching
Message-Id: <QA0gb.6906$Hd.821673@news-reader.eresmas.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbo0iqi.dra.tadmc@magna.augustmail.com...
>
> my %xref;
> while ( <DB> ) {
> my($id, $word, $plural, $synonym) = split /\|/;
> @xref{ $word, $plural, $synonym } = ($id, $id, $id);
> }
This bit seems to work.
> foreach my $word ( $meaning =~ /(\S+)/g ) {
> print "make a link to ID $xref{$word}\n" if exists $xref{$word}
> }
>
Here nothing seems to happen. I included $test .= $word; and tried to print
it but 0 results...
What am I doing wrong?
Thanks,
Lex
------------------------------
Date: Sun, 05 Oct 2003 21:48:43 +0100
From: Rich <scriptyrich@yahoo.co.uk>
Subject: Re: PerlQt question
Message-Id: <blpvrl$iku$1@news6.svr.pol.co.uk>
Amir Kadic wrote:
>
> First off, I apologize if this isn't the best group for my
> question...
>
Hi Amir,
The kde-perl mailing list is the best place to post questions on PerlQt:
kde-perl@mail.kde.org
To subscribe:
http://mail.kde.org/mailman/listinfo/kde-perl
Cheers,
--
Rich
scriptyrich@yahoo.co.uk
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5620
***************************************