[24474] in Perl-Users-Digest
Perl-Users Digest, Issue: 6657 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 6 18:06:05 2004
Date: Sun, 6 Jun 2004 15:05:05 -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, 6 Jun 2004 Volume: 10 Number: 6657
Today's topics:
Re: $NF for perl <usenet@molen.thuis.net>
[Q] how to debug perl compiled with -g flag? <socyl@987jk.com>
Re: Configuring serial port (David Efflandt)
Re: Cute bit of Perl to Assign $1,$2 to named variables (zzapper)
Re: Effective perl function to remove one element from <postmaster@castleamber.com>
Re: Memory problem with XML::DOM::Parser??? <usenet@morrow.me.uk>
Re: Novice how to design this script? (Jim Keenan)
Re: Operator precedence <Joe.Smith@inwap.com>
Perl code design award? <jkrugman345@yahbitoo.com>
Re: Perl code design award? (Greg Bacon)
Re: Perl code design award? <jkrugman345@yahbitoo.com>
Re: Perl code design award? <matthew.garrish@sympatico.ca>
Re: Perl code design award? <jkrugman345@yahbitoo.com>
Re: Perl code design award? <matthew.garrish@sympatico.ca>
Re: Perl code design award? <jkrugman345@yahbitoo.com>
Re: Perl code design award? <please_post@nomail.edu>
Re: Perl code design award? <matthew.garrish@sympatico.ca>
Re: Please help newbie with sendmail problem ! <steven.smolinski@sympatico.ca>
Re: Putting 3 scalars at a time into an array <tadmc@augustmail.com>
Re: Putting 3 scalars at a time into an array <invalid-email@rochester.rr.com>
Re: Putting 3 scalars at a time into an array <usenet@morrow.me.uk>
Set functions (Was: Novice how to design...) <jkrugman345@yahbitoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 06 Jun 2004 11:19:25 GMT
From: Tabe Kooistra <usenet@molen.thuis.net>
Subject: Re: $NF for perl
Message-Id: <pan.2004.06.06.11.19.15.892972@molen.thuis.net>
On Sat, 05 Jun 2004 18:56:35 -0400, Brad Baxter wrote:
> On Sat, 5 Jun 2004, Walter Roberson wrote:
>>
>> my $number_of_fields = scalar( () = split ... )
>>
>> The assignment to () provided the list context.
>
> And the assignment to $n... provides the scalar context, so scalar() isn't
> needed. There are good reasons not to use scalar() when it isn't needed.
>
> my $number_of_fields = () = split ...
>
thank you!
Tabe
------------------------------
Date: Sun, 6 Jun 2004 18:26:19 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: [Q] how to debug perl compiled with -g flag?
Message-Id: <c9vnkb$9nv$1@reader2.panix.com>
I know how to debug C programs, but I could use some advice on how
to debug perl (as a C program, that is, not by using perl -d, so
that I can go into subs coded in C). Does anyone know of a tutorial
showing how one does this?
Thanks!
kj
--
NOTE: In my address everything before the period is backwards.
------------------------------
Date: Sun, 6 Jun 2004 21:51:25 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Configuring serial port
Message-Id: <slrncc74et.f2j.efflandt@typhoon.xnet.com>
On Fri, 04 Jun 2004 00:29:09 -0500, Mike Kelly <nospam@nospam.com> wrote:
> I hadn't thought of using perl for this, but I saw a mention on a web
> site that someone used a trivial little perl program to set the
> parameters on a serial port for barcode scanner input...
>
> What I need to do is set the baud rate, parity, and start and stop
> bits so I can talk to a change machine, which is a pretty primitive
> device, and wants 9600,7,e,1
>
> Frankly, I don't care whether I use perl or not, but in an hour of
> googling and searching various linux sites I haven't come across the
> right combination of terms to find an appropriate command line... so ,
> whether it's perl or something else... if you can point me in the
> right direction, I'd appreciate it.
The Perl Device::SerialPort module is a Linux/Unix port of
Win32::SerialPort. I have used the former to chat AT codes with a modem.
--
David Efflandt - All spam ignored http://www.de-srv.com/
------------------------------
Date: 6 Jun 2004 11:08:30 -0700
From: david@tvis.co.uk (zzapper)
Subject: Re: Cute bit of Perl to Assign $1,$2 to named variables
Message-Id: <f677762.0406061008.e450d3@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c9t7ig$b04$1@mamenchi.zrz.TU-Berlin.DE>...
> J Krugman <jkrugman345@yahbitoo.com> wrote in comp.lang.perl.misc:
> > In <jm01c0195sg795e2e3dedtiv9eu2nuqcup@4ax.com> zzapper
> > <david@tvis.co.uk> writes:
>
> On Usenet, a certain level of aggressiveness seems to go with a healthy,
> interesting group. I can't say that I like it myself, but I have
> never found it otherwise.
>
> Anno
I don't find taking a bit of flak, in any case a few more people know
about this particular feature of Perl than did before. Someone with no
posting rights emailed me to say that though he thought himself
experienced, he hadn't known about this feature.
Thanx to Gnari for explaining that is was only a special case for $_
How about some of the people in this thread posting a few of their
Perl tit-bits
zzapper
------------------------------
Date: Sun, 06 Jun 2004 01:10:41 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Effective perl function to remove one element from array?
Message-Id: <40c2b562$0$211$58c7af7e@news.kabelfoon.nl>
Tassilo v. Parseval wrote:
> Also sprach John Bokma:
>
>>Jürgen Exner wrote:
>
>
>>>True, but only as long as the hash is sparsely populated.
>>>As the hash begins to fill up you will get hash conflicts and then you are
>>>loosing O(1).
>>
>>Ok, you get O(k), which is still O(1) as long as k << n, which is
>>hopefully the case :-D.
>
> Why would that be the case?
In the above context it is. k is some constant, not related to n, so k
is not f(n), otherwise I would have written that.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sun, 6 Jun 2004 03:52:10 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Memory problem with XML::DOM::Parser???
Message-Id: <c9u4da$fct$1@wisteria.csv.warwick.ac.uk>
Quoth markus.mohr@mazimoi.de:
>
> Now, here is the code, and that's prety all I have to master.
>
> Do you think there is anything to do about rwriting this piece of code
> for XML::LibXML2?
>
> ------- Code sample -------
> #!/usr/bin/perl -w
<standard moan>
use strict;
use warnings;
> #------------------------------------------------------------------------------#
> # CFilter.pm
> #
> #
> #
> # Modul für die Filter-Funktionen des Client im Zusammenspiel mit
> CGUI.pm und #
> # CXML.pm
> #
> #------------------------------------------------------------------------------#
Big box comments like this really don't help readability; and info about
what the module is and does should be put in POD so it can be read later
more easily.
> use CXML;
What is this module? It's not on CPAN, so I presume it's yours? By the
looks of things this will need rewriting as well.
> # Pragmata
> use diagnostics;
> use strict;
Oh right, you've got it down here... use strict and warnings should come
first.
> use open ':utf8';
If you say
use open ':encoding(utf8)';
you will get better error handling and fallback facilities when the data
isn't valid.
> return 1;
Don't do this... put it at the end.
> sub import_anfrage ($$) {
> my ( $self, $anfrage, $konfiguration ) = @_;
> print "\nDie ANFRAGE wird imporiert:\n";
> print "---------------------------\n";
>
> open( TEMP, ">./anf_temp.anf" );
> print TEMP $anfrage;
> close TEMP;
You don't need to do this. XML::DOM and XML::LibXML can both parse XML
from a string (though I admit that in the case of XML::DOM the
documentation is less than clear...).
> # Wir legen ein neues XML-Objekt an, das alte wird verworfen
> my $xml = CXML->new();
> $xml->construct_xml($konfiguration);
> $xml = $konfiguration->get_value('xml');
> my $xml_root = $xml->{'root'};
Here is your first problem. CXML objects appear to contain XML::DOM
objects; AFAIK there is no way to transfer a node from an XML::LibXML
tree to an XML::DOM tree short of serialising it and re-parsing. This
means you will have to modify CXML to use XML::LibXML (or whatever) as
well.
> # Die Anfrage wird in ein XML-Dokument geparst
> print "Debug: -> Die ANFRAGE wird gePARSt.\n";
Debug messages like this are better sent to stderr with warn.
> unlink("./anf_temp.anf");
... or die translate_to_German("couldn't delete auf_temp.anf: $!");
> # Die Anfrage ist Teil der neuen EPA
> my $anfrage_root = $anfrage_doc->getElementsByTagName('ANFRAGE');
> $anfrage_root = $anfrage_root->item(0);
> $anfrage_root->setOwnerDocument( $xml->{'doc'} );
> my $nodes = $xml_root->getElementsByTagName('anfragen');
> my $node = $nodes->item(0);
> $node->appendChild($anfrage_root);
All of this stuff will be the same with XML::LibXML, once you have your
CXML object using the same DOM library.
In theory, as the DOM provides a specification of the methods etc., you
should simply be able to switch 'XML::LibXML' for 'XML::DOM' throughout
and it'll all be fine... it won't, of course (life's never that simple),
but the changes required shouldn't be major.
Ben
--
We do not stop playing because we grow old;
we grow old because we stop playing.
ben@morrow.me.uk
------------------------------
Date: 6 Jun 2004 10:40:57 -0700
From: jkeen_via_google@yahoo.com (Jim Keenan)
Subject: Re: Novice how to design this script?
Message-Id: <196cb7af.0406060940.1afc252@posting.google.com>
fastidious007@fastmail.fm (arc) wrote in message news:<fd80715e.0406040345.574ba01e@posting.google.com>...
> Hi There,
>
> I an currently tying myself in knots trying to write a perl script
> which will basically get from one file a list of stations and from
> another file another list of stations and then to write to third file
> the common station names. If the names are different to get the
> alternative from a mappings file. The common factor in all of this is
> an identifying code which each of the stations has.
>
Have a look at CPAN module List::Compare:
http://search.cpan.org/~jkeenan/List-Compare-0.3/
Jim Keenan
------------------------------
Date: Sun, 06 Jun 2004 05:25:59 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Operator precedence
Message-Id: <HVxwc.56502$Ly.17652@attbi_s01>
David Frauzel wrote:
> I'm building a small lexical analyzer and parser and using perlop /
> perlsyn / perldata as a reference. (I'm not building the lexer in Perl,
> though.)
>
> I've managed to get myself thoroughly confused with how operator
> precedence works in Perl.
You'll find the parsing task well nigh impossible.
Try passing these two lines to your parser:
print time / 2 ;# / and die "This die() will not be executed!";
print cos / 2 ;# / and warn "This warn() is executed.";
Can your lexer+parser properly recognize that one line has a
comment in the middle and the other doesn't?
-Joe
------------------------------
Date: Sun, 6 Jun 2004 12:00:32 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Perl code design award?
Message-Id: <c9v110$3nn$1@reader2.panix.com>
The Obfuscated Perl Contest and Perl Golf are venerable traditions
in the Perl community, and among my favorite sources of puzzles.
Unfortunately, they play too well into the stereotype of Perl
software as being unmaintainable, impenetrable, hackish, "write
only code", etc. (I know that this is an unfair stereotype, but
it's most definitely out there.)
I sure wish there was a yearly "official" award for excellence in
Perl software engineering (for lack of a better term): Perl code
that is well-designed and clearly coded, has excellent performance,
is rock solid, and well documented.
Maybe such award already exists (if so, what is it called?). If
not, I think that, indirectly (as a yearly showcase) it would raise
Perl's status in the software world a couple of notches.
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Sun, 06 Jun 2004 12:30:25 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Perl code design award?
Message-Id: <10c63j1r1pmilc6@corp.supernews.com>
In article <c9v110$3nn$1@reader2.panix.com>,
J Krugman <jkrugman345@yahbitoo.com> wrote:
: [...]
:
: Maybe such award already exists (if so, what is it called?). If
: not, I think that, indirectly (as a yearly showcase) it would raise
: Perl's status in the software world a couple of notches.
Reason won't sway someone who chooses a backward and ignorant position.
It'd be a futile effort in casting Perl before swine.
Greg
--
First fork() emulation and now select()? If we are not careful in ten years
or so NT/W2K/W2010 will be almost as useful as UNIX was in mid-1980's.
-- Jarkko Hietaniemi
------------------------------
Date: Sun, 6 Jun 2004 12:59:26 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Perl code design award?
Message-Id: <c9v4fe$4da$1@reader2.panix.com>
In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon) writes:
>In article <c9v110$3nn$1@reader2.panix.com>,
> J Krugman <jkrugman345@yahbitoo.com> wrote:
>: Maybe such award already exists (if so, what is it called?). If
>: not, I think that, indirectly (as a yearly showcase) it would raise
>: Perl's status in the software world a couple of notches.
>Reason won't sway someone who chooses a backward and ignorant position.
>It'd be a futile effort in casting Perl before swine.
Well, I think such recognition of Perl coding excellence would be
good in itself, irrespective of its effects on Perl's detractors.
(Sorry, I should have made this point clearer.)
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Sun, 6 Jun 2004 11:58:39 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Perl code design award?
Message-Id: <LaHwc.974$8k4.55474@news20.bellglobal.com>
"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:c9v4fe$4da$1@reader2.panix.com...
> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon)
writes:
>
> >In article <c9v110$3nn$1@reader2.panix.com>,
> > J Krugman <jkrugman345@yahbitoo.com> wrote:
>
> >: Maybe such award already exists (if so, what is it called?). If
> >: not, I think that, indirectly (as a yearly showcase) it would raise
> >: Perl's status in the software world a couple of notches.
>
> >Reason won't sway someone who chooses a backward and ignorant position.
> >It'd be a futile effort in casting Perl before swine.
>
> Well, I think such recognition of Perl coding excellence would be
> good in itself, irrespective of its effects on Perl's detractors.
> (Sorry, I should have made this point clearer.)
>
And what would be considered Perl coding excellence?
The way one writes their code will never have an effect on the general
perception of the language. I can make you a pretty safe bet that the vast
majority of Perl coders don't write obfuscated code in their day-to-day
coding, so you wouldn't be changing anything by making a prize for who can
best adhere to the perlstyle guidelines.
Your complaint seems to be against ignorance, and all the prizes in the
world aren't going to change that. I doubt that any of these people even
know there is a prize for obfuscation. You don't get the label of ignorant
by being aware of these things, after all.
I would also suspect that the emergence of PHP for Web scripting will do
wonders for Perl's tarnished image. PHP appears to have taken away Perl's
crown of official language of Web script kiddies, so hopefully Perl will no
longer be associated with bad Web scripting and will instead be seen as the
great glue language it's always been.
And no one's stopping you from creating your own prize if you're so
inclined. Don't expect someone else to do it for you.
Matt
------------------------------
Date: Sun, 6 Jun 2004 17:29:36 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Perl code design award?
Message-Id: <c9vka0$8lc$1@reader2.panix.com>
In <LaHwc.974$8k4.55474@news20.bellglobal.com> "Matt Garrish" <matthew.garrish@sympatico.ca> writes:
>"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
>news:c9v4fe$4da$1@reader2.panix.com...
>> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon)
>writes:
>>
>> >In article <c9v110$3nn$1@reader2.panix.com>,
>> > J Krugman <jkrugman345@yahbitoo.com> wrote:
>>
>> >: Maybe such award already exists (if so, what is it called?). If
>> >: not, I think that, indirectly (as a yearly showcase) it would raise
>> >: Perl's status in the software world a couple of notches.
>>
>> >Reason won't sway someone who chooses a backward and ignorant position.
>> >It'd be a futile effort in casting Perl before swine.
>>
>> Well, I think such recognition of Perl coding excellence would be
^^^^^^^^
>> good in itself, irrespective of its effects on Perl's detractors.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>The way one writes their code will never have an effect on the general
>perception of the language.
Please read what I wrote. I don't think I can say it any more clearly.
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Sun, 6 Jun 2004 14:15:53 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Perl code design award?
Message-Id: <pbJwc.5349$sS2.159117@news20.bellglobal.com>
"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:c9vka0$8lc$1@reader2.panix.com...
> In <LaHwc.974$8k4.55474@news20.bellglobal.com> "Matt Garrish"
<matthew.garrish@sympatico.ca> writes:
>
>
> >"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
> >news:c9v4fe$4da$1@reader2.panix.com...
> >> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon)
> >writes:
> >>
> >> >In article <c9v110$3nn$1@reader2.panix.com>,
> >> > J Krugman <jkrugman345@yahbitoo.com> wrote:
> >>
> >> >: Maybe such award already exists (if so, what is it called?). If
> >> >: not, I think that, indirectly (as a yearly showcase) it would raise
> >> >: Perl's status in the software world a couple of notches.
> >>
> >> >Reason won't sway someone who chooses a backward and ignorant
position.
> >> >It'd be a futile effort in casting Perl before swine.
> >>
> >> Well, I think such recognition of Perl coding excellence would be
> ^^^^^^^^
> >> good in itself, irrespective of its effects on Perl's detractors.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> >The way one writes their code will never have an effect on the general
> >perception of the language.
>
> Please read what I wrote. I don't think I can say it any more clearly.
>
Have Web site of the day/week/month awards made coding on the Web any
better? Does giving out Oscars prove that the quality of movies is getting
any better?
Your premise is naive. Does any other language have these awards you dream
of? Yet you believe that Perl is a lesser language why, because someone you
talked to said so? And because there aren't any awards to prove it isn't so?
Maybe Perl needs stronger advocates who will stand up for the langauge. I've
never run into anyone with such an opinion of the language, but maybe that's
just me.
It's commendable that you want to be an advocate of the language, but awards
at best might stroke a person's ego but are not going to vault Perl to some
position of great esteem that you seem to believe it is lacking.
Matt
------------------------------
Date: Sun, 6 Jun 2004 18:56:30 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Perl code design award?
Message-Id: <c9vpcu$a60$1@reader2.panix.com>
In <pbJwc.5349$sS2.159117@news20.bellglobal.com> "Matt Garrish" <matthew.garrish@sympatico.ca> writes:
>"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
>news:c9vka0$8lc$1@reader2.panix.com...
>> In <LaHwc.974$8k4.55474@news20.bellglobal.com> "Matt Garrish"
><matthew.garrish@sympatico.ca> writes:
>>
>>
>> >"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
>> >news:c9v4fe$4da$1@reader2.panix.com...
>> >> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon)
>> >writes:
>> >>
>> >> >In article <c9v110$3nn$1@reader2.panix.com>,
>> >> > J Krugman <jkrugman345@yahbitoo.com> wrote:
>> >>
>> >> >: Maybe such award already exists (if so, what is it called?). If
>> >> >: not, I think that, indirectly (as a yearly showcase) it would raise
>> >> >: Perl's status in the software world a couple of notches.
>> >>
>> >> >Reason won't sway someone who chooses a backward and ignorant
>position.
>> >> >It'd be a futile effort in casting Perl before swine.
>> >>
>> >> Well, I think such recognition of Perl coding excellence would be
>> ^^^^^^^^
>> >> good in itself, irrespective of its effects on Perl's detractors.
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> >The way one writes their code will never have an effect on the general
>> >perception of the language.
>>
>> Please read what I wrote. I don't think I can say it any more clearly.
>>
>Have Web site of the day/week/month awards made coding on the Web any
>better?
I'm beginning to see why: people can't read... *sheesh*
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Sun, 6 Jun 2004 19:09:04 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: Perl code design award?
Message-Id: <c9vq4g$acc$1@reader2.panix.com>
"Matt Garrish" sez:
"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:c9vka0$8lc$1@reader2.panix.com...
> In <LaHwc.974$8k4.55474@news20.bellglobal.com> "Matt Garrish"
<matthew.garrish@sympatico.ca> writes:
>
>
> >"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
> >news:c9v4fe$4da$1@reader2.panix.com...
> >> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg Bacon)
> >writes:
> >>
> >> >In article <c9v110$3nn$1@reader2.panix.com>,
> >> > J Krugman <jkrugman345@yahbitoo.com> wrote:
> >>
> >> >: Maybe such award already exists (if so, what is it called?). If
> >> >: not, I think that, indirectly (as a yearly showcase) it would raise
> >> >: Perl's status in the software world a couple of notches.
> >>
> >> >Reason won't sway someone who chooses a backward and ignorant
position.
> >> >It'd be a futile effort in casting Perl before swine.
> >>
> >> Well, I think such recognition of Perl coding excellence would be
> ^^^^^^^^
> >> good in itself, irrespective of its effects on Perl's detractors.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> >The way one writes their code will never have an effect on the general
> >perception of the language.
>
> Please read what I wrote. I don't think I can say it any more clearly.
>
Have Web site of the day/week/month awards made coding on the Web any
better?
Your talent for impersonating a grade-A imbecile is indeed
impressive... Please stop! You're killing me!
-bill
------------------------------
Date: Sun, 6 Jun 2004 15:07:10 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Perl code design award?
Message-Id: <sXJwc.6295$sS2.172863@news20.bellglobal.com>
"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
news:c9vpcu$a60$1@reader2.panix.com...
> In <pbJwc.5349$sS2.159117@news20.bellglobal.com> "Matt Garrish"
<matthew.garrish@sympatico.ca> writes:
>
>
> >"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
> >news:c9vka0$8lc$1@reader2.panix.com...
> >> In <LaHwc.974$8k4.55474@news20.bellglobal.com> "Matt Garrish"
> ><matthew.garrish@sympatico.ca> writes:
> >>
> >>
> >> >"J Krugman" <jkrugman345@yahbitoo.com> wrote in message
> >> >news:c9v4fe$4da$1@reader2.panix.com...
> >> >> In <10c63j1r1pmilc6@corp.supernews.com> gbacon@hiwaay.net (Greg
Bacon)
> >> >writes:
> >> >>
> >> >> >In article <c9v110$3nn$1@reader2.panix.com>,
> >> >> > J Krugman <jkrugman345@yahbitoo.com> wrote:
> >> >>
> >> >> >: Maybe such award already exists (if so, what is it called?). If
> >> >> >: not, I think that, indirectly (as a yearly showcase) it would
raise
> >> >> >: Perl's status in the software world a couple of notches.
> >> >>
> >> >> >Reason won't sway someone who chooses a backward and ignorant
> >position.
> >> >> >It'd be a futile effort in casting Perl before swine.
> >> >>
> >> >> Well, I think such recognition of Perl coding excellence would be
> >> ^^^^^^^^
> >> >> good in itself, irrespective of its effects on Perl's detractors.
> >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>
> >> >The way one writes their code will never have an effect on the general
> >> >perception of the language.
> >>
> >> Please read what I wrote. I don't think I can say it any more clearly.
> >>
>
> >Have Web site of the day/week/month awards made coding on the Web any
> >better?
>
> I'm beginning to see why: people can't read... *sheesh*
>
Whatever you think you wrote, you didn't. And whatever intelligent thought
you think you had is nowhere to be found. I see that dialogue is not what
you are after but some affirmation of your laughable idea. Sad I've had
spell it out in so many words for you, but maybe you'll learn to read
through an entire posting next time.
Matt
------------------------------
Date: Sun, 06 Jun 2004 07:48:17 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Please help newbie with sendmail problem !
Message-Id: <5%zwc.14$8k4.2577@news20.bellglobal.com>
Ben Morrow <usenet@morrow.me.uk> wrote:
>
> Quoth Steven Smolinski <steven.smolinski@sympatico.ca>:
>> > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
>> > $!";
>>
>> UUODQ: Useless Use of Double Quotes (around the sendmail path).
>>
>> perldoc -q quoting vars
>
> That faq has nothing to do with it; indeed, there's nothing anywhere
> in the std docs on the merits of "" vs '' where there is no need for
> interpolation. It is purely a matter of style.
You are entirely correct. Thanks for that.
> DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
> if you don't need the fanciness of MIME::Lite.
Always a good idea. Unless you're just playing with piped opens for
laughs and giggles.
Steve
------------------------------
Date: Sat, 5 Jun 2004 21:02:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Putting 3 scalars at a time into an array
Message-Id: <slrncc4uqc.a9n.tadmc@magna.augustmail.com>
Rich Grise <null@example.net> wrote:
> I'm going through a file of the format:
[ snip data ]
I don't think we need to see the data, as I don't think you
are asking about how to get the 3 values, but rather how to
put the 3 values somewhere else once gotten?
If so, then where the 3 values come from is not relevant.
> which are kind of name-value pairs where "ItemX" is a name
> and item "ValueX" is a value.
That suggests using a hash data structure.
> So, I've got it going through the file, picking lines
> and building a little array: ($item1value,$item2value,$item3value),
That is a "list" not an "array".
> Now, I can rearrange the printf to put them in any order in
> the output, so I could run stdout thru sort and sort by
> any field, but then I'd have to rearrange that output
> again.
You are right to not like that idea. :-)
You should be able to get whatever you need right out of Perl.
You can do sorting in native Perl you know.
> So, obviously, I need to store these 3 items in an array,
> like @ITEMS[$count] = ($a,$b,$c); and then increment $count,
> is that right?
^^^^
Which "that" is that?
Yes, you need to store 3 items in an array.
No, that code is not going to get it done.
> Or would it make more sense to make a hash,
Let me pull out a quote I've enshrined on my hard disk:
Message-ID: <slrn95u8og.1cr.rgarciasuarez@rafael.kazibao.net>
I don't know what your original problem is,
but I suggest to use a hash. --Rafael Garcia-Suarez
> like %ITEMS{"$a"} = ($b,$c); , since in a way, $a is a name
^ ^
^ ^ a useless use of quotes.
Don't use quotes where you don't need quotes.
> that values $b and $c are associated with.
You need some kind of multi-level data structure, but I can't
make enough sense of your description thus far to suggest one.
> Also, in my
> reading, ISTR something about adding items to an array by
> just adding them, and let perl take care of indexing, or
perldoc -f push
> was that just hashes? Anyway, I'm reluctant to make a hash,
> because can you then sort it on one of the item values? i.e.
Of course you can.
It is a Frequently Asked Question.
Please do not ask Frequently Asked Questions, just read the answer
first, _then_ ask questions.
perldoc -q sort
How do I sort a hash (optionally by value instead of key)?
> sort "%ITEMS{"$a"} = ($b,$c)" on $b?
We can't really talk about it accurately with your psuedo-Perl, so
I'll attempt to translate what I think you mean into Perl:
Load up an HoL:
$items{$a} = [ $b, $c ]; # this is inside of a loop, many such assignments
later, sort by the 1st field ($b) like in the FAQ answer:
# untested
@keys = sort {
$items{$a}->[0] cmp $items{$b}[0]
} keys %hash; # and by value
> I guess the simple straightforward, non-arcane, way is:
> $count = 0;
> while (<>) {
> # [get the 3 variables]
> @items[$count++] = ($a, $b, $c);
> }
Now that is a _different_ multi-level data structure.
Load up an LoL:
push @items, [ $a, $b, $c ]; # this is inside of a loop too
and sort by the 2nd field
# untested
@keys = sort {
$a->[1] cmp $b->[1]
} @items; # and by value
> if anyone has any suggestions?
Please check the Perl FAQ *before* posting to the Perl newsgroup.
> Y'know, to make
> it more perl-y?
Learn about multi-level data structures in Perl:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 06 Jun 2004 02:39:57 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Putting 3 scalars at a time into an array
Message-Id: <40C283EE.80906@rochester.rr.com>
Rich Grise wrote:
...
> I'm going through a file of the format:
>
> Item1:<discard>Value1<discardthis>
> <discard>
> <discardItem2<discard>Value2<discard>
> <discard>
> <discard>Value3<discard>Item3<discard>
> Item1:<discard>Value4<discardthis>
> <discard>
> <discardItem2<discard>Value5<discard>
> <discard>
> <discard>Value6<discard>Item3<discard>
>
> which are kind of name-value pairs where "ItemX" is a name
> and item "ValueX" is a value.
>
> So, I've got it going through the file, picking lines
> and building a little array: ($item1value,$item2value,$item3value),
> which it printfs.
>
> Now, I can rearrange the printf to put them in any order in
> the output, so I could run stdout thru sort and sort by
> any field, but then I'd have to rearrange that output
> again.
>
> So, obviously, I need to store these 3 items in an array,
> like @ITEMS[$count] = ($a,$b,$c); and then increment $count,
> is that right? Or would it make more sense to make a hash,
Well, not quite. You want to store a reference to ($a,$b,$c) in @ITEMS,
like:
$ITEMS[$count]=[$a,$b,$c];
See:
perldoc perllol
perldoc perlref
for info on this. Note the use of $ITEMS -- you are dealing with a
single subscript, not a list of subscripts, so the value you are storing
is a scalar, not an array, so you need $, not @. @ will work, but will
treat the assignment as an array slice assignment, making the code
harder to follow. Also note the use of [...], which generates a
reference to an anonymous array.
> like %ITEMS{"$a"} = ($b,$c); , since in a way, $a is a name
> that values $b and $c are associated with. Also, in my
> reading, ISTR something about adding items to an array by
> just adding them, and let perl take care of indexing, or
> was that just hashes? Anyway, I'm reluctant to make a hash,
> because can you then sort it on one of the item values? i.e.
> sort "%ITEMS{"$a"} = ($b,$c)" on $b?
---------------^--^
Useless use of " -- see:
perldoc -q quoting
for why.
Sorting on hash values is a FAQ:
perldoc -q sort
You might also look up the Schwartzian Transform, as it can offer a
considerable efficiency improvement on hash sorts over "normal" sort code.
>
> I guess the simple straightforward, non-arcane, way is:
> $count = 0;
> while (<>) {
> # [get the 3 variables]
> @items[$count++] = ($a, $b, $c);
$items[$count++] = [$a, $b, $c];
Also, I note that you changed from ITEMS to items -- Perl is case
sensitive, and cares about that.
> }
>
> But ISTVR something about #items, but don't know where to
> look for it, if anyone has any suggestions? Y'know, to make
> it more perl-y?
More Perl-y would be:
my @items;
while(<>){
#get the three variables
push @items,[$a,$b,$c];
}
You could also consider storing a reference to an anonymous hash rather
than an anonymous array in @items, which would look like:
...
push @items,{Item1=>$a,Item2=>$b,Item3=>$c};
...
Doubtful there are advantages to that given your input above, but I
don't know exactly what you plan to do with your data structure. It
could be clearer to refer to $items[$n]{Item1} than referring to
$items[$n][0] for an "Item1" value, for example.
...
> Rich
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sun, 6 Jun 2004 03:27:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Putting 3 scalars at a time into an array
Message-Id: <c9u2uk$eun$1@wisteria.csv.warwick.ac.uk>
Quoth "Rich Grise" <null@example.net>:
>
> So, obviously, I need to store these 3 items in an array,
> like @ITEMS[$count] = ($a,$b,$c); and then increment $count,
> is that right? Or would it make more sense to make a hash,
> like %ITEMS{"$a"} = ($b,$c); , since in a way, $a is a name
> that values $b and $c are associated with.
When asking 'should I use an array or a hash', the answer is use an
array if you need to preserve the original order, a hash if you just
need to look up items given one of the others. If you need both you can
use Tie::IxHash from CPAN.
If your problem is really as simple as sorting on the second field and
printing, I'd use a hash like this:
my %data;
while ( more_data() ) {
# set $one, $two, $three
# see the $a and $b in perldoc perlvar for why you shouldn't
# use those particular two names
$data{$two} = [ $one, $two, $three ];
}
$, = ", ";
$\ = "\n";
print @{$data{$_}} for sort keys %data;
I have to say, though, that I cannot for the life of me work out how you
get triples out of the data you showed...
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Sun, 6 Jun 2004 14:12:59 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Set functions (Was: Novice how to design...)
Message-Id: <c9v8pb$5g1$1@reader2.panix.com>
In <3763409.4OZSjEB05d@GMT-hosting-and-pickle-farming> Gregory Toomey <nospam@bigpond.com> writes:
>Pass the lists to the "intersection" function below.
>This returns names/codes common to both.
>http://www.gregorytoomey.com/index.php?option=content&task=view&id=9&Itemid=28
Hi, Greg. First, a typo (or two) in your page:
Example: Return the elements that occur more than once:
* duplicate(['apple','banana', 'pear', 'banana'])
Example: Return the elements that occur only once:
* duplicate(['apple','banana', 'pear', 'banana', 'apple'])
The "duplicate" is duplicated. I think you wanted the second one
to be "unique" (it's the only function defined on that page that
does not correspond to an Example). Also (and assuming you indeed
intended the second example above to refer to "unique"), the wording
of your description is ambiguous. My first reading was that
unique(['apple','banana', 'pear', 'banana', 'apple'])
would return ('pear') (the only element that occurs exactly once
in the input list, whereas, looking at the code I see that it would
return ('apple', 'banana', 'pear').
Also, a couple of suggestions. A set theorist would say that union
and intersection can take any number of arguments (including zero
or uncountably many!). That's hard to implement in Perl, but at
least one could generalize your functions to handle @_ arrays of
any size (including zero). Also, since you're implementing sets
as array refs, shouldn't union and intersection return array refs
as well?
# UNTESTED
sub union {
die "union: bad args\n" if grep defined $_ && ref $_ ne 'ARRAY', @_;
# return undef (= "the universe") if one of the arguments
# is undef
return undef if grep !defined, @_;
my %hash = map +($_ => 1), map @$_, @_;
[ keys %hash ];
}
sub intersection {
die "intersection: bad args\n" if grep defined $_ && ref $_ ne 'ARRAY', @_;
# the line below is so that we ignore any element in @_ that
# is the universe, since it does not affect the intersection
my @args = grep $_, @_;
# return undef (= "the universe") if @_ is empty
return undef unless @args;
my %hash;
++$hash{$_} for map @$_, @args;
[ grep $hash{$_} == @_, keys %hash ];
}
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6657
***************************************