[22683] in Perl-Users-Digest
Perl-Users Digest, Issue: 4904 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 28 06:10:39 2003
Date: Mon, 28 Apr 2003 03:10:09 -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 Mon, 28 Apr 2003 Volume: 10 Number: 4904
Today's topics:
Re: Style: Using 'no warnings' in a module <jaspax@u.washington.edu>
Re: Style: Using 'no warnings' in a module <tassilo.parseval@rwth-aachen.de>
Re: Test::Harness annoyance <kalinabears@hdc.com.au>
Re: Tough question for the guru's; Grep Once, Awk Twice (Agrapha)
Re: Tough question for the guru's; Grep Once, Awk Twice <tassilo.parseval@rwth-aachen.de>
two suggestions for the perl posting-statistics reports (David Combs)
Re: uploading photos in e-classified (Malcolm Dew-Jones)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 27 Apr 2003 20:26:52 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Style: Using 'no warnings' in a module
Message-Id: <Pine.A41.4.53.0304272011070.102618@dante18.u.washington.edu>
> > I've got a questions about proper Perl style for a module I'm writing. I
> > always use strict, of course, but when testing my module with use
> > warnings, a handful of trivial warnings crop up. The cases that these
> > warnings describe are expected and unimportant for the overall execution
> > of the module.
> >
> > So, should simply ignore the warnings? Or should I sprinkle 'no warnings'
> > throughout the module to temporarily disable warnings for the offending
> > sections? Which is worse Perl style: a handful of trivial errors, or
> > constantly overriding the users wish to be warned?
>
> Who is the user in your case? Is this module eventually to be released
> on the CPAN? If so, I might be a user of it and here are two things that
> I absolutely detest about modules. When they are...
The module is intended for CPAN at some point, although I'm still in the
pre-alpha stage of writing.
Several people said that it depended on the code and on the warning. The
first example was something like this:
# $value might be text or number
if ($value > 0) {
do_something;
}
The warning came when $value was a text string. However, this case is
anticipated, and the program behaved as desired when $value was a text
string. Fortunately, a trivial bit of code rearrangement made it go away.
The second example is more difficult: it violates both strict and
warnings, and I don't know how to make it go away without using 'no
strict' and 'no warnings'.
# Allows you to call changes to feature settings directly
# with syntax like $segment->feature_name($value, $index)
sub AUTOLOAD {
my $self = shift;
my $feature = $AUTOLOAD;
$feature =~ s/.*:://;
# Pass on function calls that aren't features
# This is the line that causes problems
no strict 'refs';
no warnings;
&$AUTOLOAD if (not $self->feature($feature));
if (scalar(@_) > 0) {
my $value = shift;
$self->value($feature, $value);
if (scalar(@_) > 0) {
my $index = shift;
$self->feature_index($feature, $index);
} # end if
} # end if
return $self->value($feature);
} # end AUTOLOAD
There's probably a workaround for this, but I don't know what it is.
> <slrnb4j3vt.qnk.abigail@alexandra.abigail.nl>
>
> Consult groups.google.com to see it in context and some of the ideas
> brought forth in this thread by several people.
Thanks, I'll check out that thread.
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: 28 Apr 2003 08:40:46 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Style: Using 'no warnings' in a module
Message-Id: <b8ipee$eq2$1@nets3.rz.RWTH-Aachen.DE>
Also sprach JS Bangs:
>> > So, should simply ignore the warnings? Or should I sprinkle 'no warnings'
>> > throughout the module to temporarily disable warnings for the offending
>> > sections? Which is worse Perl style: a handful of trivial errors, or
>> > constantly overriding the users wish to be warned?
>>
>> Who is the user in your case? Is this module eventually to be released
>> on the CPAN? If so, I might be a user of it and here are two things that
>> I absolutely detest about modules. When they are...
>
> The module is intended for CPAN at some point, although I'm still in the
> pre-alpha stage of writing.
[...]
> The second example is more difficult: it violates both strict and
> warnings, and I don't know how to make it go away without using 'no
> strict' and 'no warnings'.
no strict 'refs' is totally ok. Sometimes you just have to allow
symbolic references. AUTOLOAD is a typical example for that. It wont
impose any compatibility issues with older perls either.
> # Allows you to call changes to feature settings directly
> # with syntax like $segment->feature_name($value, $index)
> sub AUTOLOAD {
> my $self = shift;
> my $feature = $AUTOLOAD;
> $feature =~ s/.*:://;
>
> # Pass on function calls that aren't features
> # This is the line that causes problems
> no strict 'refs';
> no warnings;
> &$AUTOLOAD if (not $self->feature($feature));
To me this looks sort of wrong. You are calling the function named
$AUTOLOAD explicitely but it's not defined anywhere. If it were,
AUTOLOAD() would never have been triggered. What is the exact warning
you get for these lines? Also, if you are using a construct like the
above, you should probably change that to
goto &$AUTOLOAD ...;
That way the AUTOLOAD() is stripped from the caller stack and it appears
as though $AUTOLOAD would have been called in the first place.
> if (scalar(@_) > 0) {
> my $value = shift;
> $self->value($feature, $value);
> if (scalar(@_) > 0) {
> my $index = shift;
> $self->feature_index($feature, $index);
> } # end if
> } # end if
> return $self->value($feature);
> } # end AUTOLOAD
Is there a way to turn the above into proper methods that you can
compile on the fly? Right now, AUTOLOAD is triggered for each call to
the same feature. Something like
if ($self->feature($feature)) {
*$AUTOLOAD = eval qq!
sub $feature {
my (\$self, \$idx) = \@_;
...
}
!;
goto &$AUTOLOAD;
}
This is more efficient: AUTOLOAD gets called only once for each feature.
It compiles the new method and calls it. On each successive invocation
the method is defined and directly called. For the above you must not
destroy @_ in AUTOLOAD(), though. Therefore the head of it should read
like this:
sub AUTOLOAD {
my ($self) = @_;
...
That is needed because the new function should receive the original @_
unaltered.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 28 Apr 2003 16:12:00 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Test::Harness annoyance
Message-Id: <3eacc729$0$21262@echo-01.iinet.net.au>
"James E Keenan" <jkeen@concentric.net> wrote in message
news:b8grm6$em@dispatch.concentric.net...
<snip>
>
> Am perplexed too.
>
>
I've got a PII laptop with AS build 633 (5.6.1), and a PIII desktop with AS
build 626 (5.6.1). (They both also have 5.8 builds, but for the moment I'm
looking at the 5.6.1 builds only.)
Both machines have identical Win 2k operating systems.
On the laptop, Test::Harness behaviour is as desired - producing no
superfluous blank lines. On the desktop, however, I get those useless and
annoying blank lines.
On both machines I've run scandeps.pl (which comes with Module::ScanDeps) on
Test\Harness.pm, and on Test.pm.
I've then checked the version numbers of the fifty-odd modules that scandeps
finds - and they're the same on both machines.
This leaves me thinking that it's possibly something in the different
patchlevel between builds 626 and 633.
Or its explained in terms of the difference between PII and PIII ...... time
to warm up the soldering iron ?
:-)
Looks like it's time for me to turf it into the (already overflowing)
"too-hard basket" ....... unless anyone has any ideas on how/where to
proceed ?
In case people don't properly understand what I'm talking about:
On the laptop, 'nmake test' will output something like this:
t/test_01................... ok
t/test_02................... ok
On the desktop, 'nmake test' will output something like this:
t/test_01................... ok
t/test_02................... ok
where the actual number of blank lines between the test_01 result and the
test_02 result is equal to the number of tests that test_02 performs.
On both machines, I'm getting the incremental counter while the tests are
being conducted. That parts ok - it's just that, on the desktop, each time
the counter increments, a new (blank) line is printed to the screen.
I can probably, as James suggests, use the 'verbose' switch to have that
line print the result of the test - but that's not what I want - I simply
don't want that line at all (as per the laptop).
Cheers,
Rob
------------------------------
Date: 28 Apr 2003 00:25:49 -0700
From: brian@box201.com (Agrapha)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <11aabb15.0304272325.22de04b9@posting.google.com>
"Richard Gration" <richard@zync.co.uk> wrote in message news:<20030425.124653.1286966948.18265@richg.zync>...
>
> Happy Perling
> R
For your perusal I present a 90% complete triage.pl. It's not complete
but mostly working. I commented everything. Let me know of you see
something that could be more professionally done.
#!/usr/bin/env perl -w
use strict;
#####
# This script was made possible by the excellent help
# from the people on the perl usenet forum.
# The project would not have been possible without them.
# triage.pl was designed to look up an number and gather
# info about it. We begin by making sure they enter one
# on the command line or give them an example if they
# fail to do so.
###
if (!@ARGV) {
print "Syntax is \"./triag 2015551212\"\n";
die "please include a phone number when starting program\n";
}
### Variable Initialization
my %error_codes;
my %error_users;
my %err_per_usr;
my @selected = ();
my @badcalls = ();
my $code = 0;
my $users = 0;
my $badusr = 0;
### End Variable Init
#####
# Next we go and find all the radius log files
# the push here will push the line into @selected
# if the line matches @ARGV (the command line value)
###
for my $file (glob "/proxy/logs/proxyLogs.*") {
open LOGG, $file or die "Can't open $file: $!";
while (<LOGG>) {
push @selected, $_ if /@ARGV/;
}
close LOGG;
}
#####
# Ok so now we have an effective grep pushed into our
# @selected array. That give us all the calls made to
# an access number. Next we need to sort out the calls
# with zero session time by /,0 / there is a space after
# the ,0 because that is the way to find a failed call
###
foreach (@selected[0..$#selected]) {
push @badcalls, $_ if /,0 /;
}
#####
# now with the failed calls in @badcalls we filter and sort
###
foreach (@badcalls[0..$#badcalls]) {
my @errors = split /\s+/, $_;
$code = $errors[7];
$users = $errors[3];
$badusr = @errors[7,3]; #doesn't work right
$error_codes{$code}++;
$error_users{$users}++;
$err_per_usr{$badusr}++;
}
#####
# perform a little math to get and average call sucess ratio
###
my $total = @selected;
my $fail = @badcalls;
print "\ntotal $total\t$fail\t$ARGV[0]\n";
print "success rate is: ", (100 - (($fail / $total) * 100)), "%\n";
#####
# Finally I print out the information to the screen
###
print "\nErrorCodes / Totals\n";
print "-------------------\n";
foreach my $key (keys %error_codes) {
print "$key\t\/\t$error_codes{$key}\n";
}
print "\nPhoneNumber / TotalFail\n";
print "-----------------------\n";
foreach my $key (keys %error_users) {
print "$key\t\/\t$error_users{$key}\n";
}
#####
# this one is broke I am supposed to get the 3 columns but
# I dont know how to do that yet
###
print "\nNumber / Error / Totals\n";
print "-----------------------\n";
foreach my $key (keys %err_per_usr) {
print "$key\t\/\t$err_per_usr{$key}\n";
}
------------------------------
Date: 28 Apr 2003 09:04:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <b8iqr3$g6r$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Agrapha:
> "Richard Gration" <richard@zync.co.uk> wrote in message news:<20030425.124653.1286966948.18265@richg.zync>...
>>
>> Happy Perling
>> R
>
> For your perusal I present a 90% complete triage.pl. It's not complete
> but mostly working. I commented everything. Let me know of you see
> something that could be more professionally done.
Nothing serious, just a few cosmetic things [I stripped some of the
comments]:
> #!/usr/bin/env perl -w
> use strict;
>
> if (!@ARGV) {
> print "Syntax is \"./triag 2015551212\"\n";
> die "please include a phone number when starting program\n";
> }
>
> ### Variable Initialization
>
> my %error_codes;
> my %error_users;
> my %err_per_usr;
> my @selected = ();
> my @badcalls = ();
> my $code = 0;
> my $users = 0;
> my $badusr = 0;
>
> for my $file (glob "/proxy/logs/proxyLogs.*") {
> open LOGG, $file or die "Can't open $file: $!";
> while (<LOGG>) {
> push @selected, $_ if /@ARGV/;
> }
> close LOGG;
> }
> #####
> # Ok so now we have an effective grep pushed into our
> # @selected array. That give us all the calls made to
> # an access number. Next we need to sort out the calls
> # with zero session time by /,0 / there is a space after
> # the ,0 because that is the way to find a failed call
> ###
> foreach (@selected[0..$#selected]) {
> push @badcalls, $_ if /,0 /;
> }
In your comment you say it's an effective grep. Why not use an actual
grep() then? ;-)
@badcalls = grep /,0/, @selected;
Btw: if you iterate over a complete array, you don't have to use an
array-slice. Simply
foreach (@selected) {
...
}
> foreach (@badcalls[0..$#badcalls]) {
> my @errors = split /\s+/, $_;
> $code = $errors[7];
> $users = $errors[3];
> $badusr = @errors[7,3]; #doesn't work right
(Do you perhaps want to concatenate the two strings?)
> $error_codes{$code}++;
> $error_users{$users}++;
> $err_per_usr{$badusr}++;
> }
Same here. Also, you only ever access the fourth and eigth element of
the list returned by split. You can make that explicit:
foreach (@badcalls) {
my ($users, $code) = (split)[3,7];
$error_codes{ $code }++;
$error_users{ $users }++;
$err_per_usr{ "$users:$code" }++;
}
For $err_per_usr you could also use a nested data-structure, a hash of
hashes probably:
$err_per_usr{ $user }->{ $code }++;
> #####
> # perform a little math to get and average call sucess ratio
> ###
>
> my $total = @selected;
> my $fail = @badcalls;
> print "\ntotal $total\t$fail\t$ARGV[0]\n";
> print "success rate is: ", (100 - (($fail / $total) * 100)), "%\n";
printf() is probably useful here:
printf "\ntotal %i\t%i\t%i\n", $total, $fail, $ARGV[0];
> #####
> # Finally I print out the information to the screen
> ###
> print "\nErrorCodes / Totals\n";
> print "-------------------\n";
> foreach my $key (keys %error_codes) {
> print "$key\t\/\t$error_codes{$key}\n";
> }
> print "\nPhoneNumber / TotalFail\n";
> print "-----------------------\n";
> foreach my $key (keys %error_users) {
> print "$key\t\/\t$error_users{$key}\n";
> }
For those two iterations I'd have probably used each():
while (my ($k, $v) = each %error_codes) {
printf "%i / %i\n", $k, $v;
}
...
while (my ($k, $v) = each %error_users {
printf "%s / %i\n", $k, $v;
}
> #####
> # this one is broke I am supposed to get the 3 columns but
> # I dont know how to do that yet
> ###
> print "\nNumber / Error / Totals\n";
> print "-----------------------\n";
> foreach my $key (keys %err_per_usr) {
> print "$key\t\/\t$err_per_usr{$key}\n";
> }
This is because %err_per_usr wasn't properly created. If it is a
two-dimensional hash, it could look like:
while (my ($user, $val) = each %err_per_usr) {
# $val is now a hash-ref
my %errors = %$val;
# proceed
}
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 28 Apr 2003 00:33:23 -0400
From: dkcombs@panix.com (David Combs)
Subject: two suggestions for the perl posting-statistics reports
Message-Id: <b8iauj$1uk$1@panix1.panix.com>
Here's an email I just sent to gbacon@cs.uah.edu,
who posts those posting-statistics reports:
Some suggestions for your nifty posting-statistics reports:
. top 20 would be much better than top 10, and, considering
all the "overhead" from headings and white-space, wouldn't
add all that much to the length of the report.
Most importantly, if one uses your report as a way to
get hints as to which names to look for in threads
as "educational", 10 misses some of the *most* important
contributors.
For instance, Goldberg, one of the most reliable for
consistent excellence in postings, doesn't even make
the first top-10 list in the report. Top-20 would
probably include him.
Considering all the overhead due to headings and
blank-lines, an extra 10 should not grossly
increase the size of the report, and yet would
greatly increase its usefulness.
. For using the reports as above, ie as a way to
get the names of the major post-answerers, a list
of the top *answerers* would be useful -- ie, not
counting *original* posts, only replies.
Any of the above sound worthwhile?
David
------------------------------
Date: 27 Apr 2003 20:40:59 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: uploading photos in e-classified
Message-Id: <3eaca2cb@news.victoria.tc.ca>
Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote:
: -----BEGIN xxx SIGNED MESSAGE-----
: Hash: SHA1
: "Chris" <chris_12003@yahoo.com> wrote in
: news:vamchfc2dof15f@corp.supernews.com:
: > I'm using the standard edition of e-classifieds and its set to allow
: > the user to upload one photo but I have seen other sites using the
: > same software that allow you to upload 5 or more. Does anyone know
: > what modifications I need to make to the program so my users can
: > upload more than one photo?
: Did you happen to have a Perl question?
The program is probably written in perl?
For the original question, the program was probably modified for the site
in question. If it's perl then you have the source code so you can do
this yourself if you figure out the program and if you figure out perl.
(That may or may not be allowed, based on the license of course, and if
the program was free then there may still be a license you have to
follow.)
I doubt there is a simple way to do this, except possibly buying an
enhanced version of the software.
------------------------------
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 4904
***************************************