[23855] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6058 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 31 18:05:46 2004

Date: Sat, 31 Jan 2004 15:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 31 Jan 2004     Volume: 10 Number: 6058

Today's topics:
        ANN: Preference ballot tabulation script Condorcet with (M G)
        can't find cgi-bin <taylorjo@collegesherbrooke.qc.ca>
    Re: can't find cgi-bin (Walter Roberson)
    Re: can't find cgi-bin <taylorjo@collegesherbrooke.qc.ca>
    Re: can't find cgi-bin <gnari@simnet.is>
    Re: how to check for ip address that falls inside a ran (Walter Roberson)
    Re: how to check for ip address that falls inside a ran <usenet@morrow.me.uk>
    Re: how to check for ip address that falls inside a ran <noreply@gunnar.cc>
    Re: interpreting script <bik.mido@tiscalinet.it>
    Re: interpreting script <usenet@morrow.me.uk>
    Re: interpreting script <dwall@fastmail.fm>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 31 Jan 2004 18:23:32 GMT
From: matt@tidalwave.net (M G)
Subject: ANN: Preference ballot tabulation script Condorcet with Dual Dropping
Message-Id: <HsDA82.1GsE@zorch.sf-bay.org>

Condorcet with Dual Dropping Perl script releaste 5.6

http://condorcet-dd.sourceforge.net/
http://sourceforge.net/projects/condorcet-dd/
http://freshmeat.net/projects/condorcet_dd/?topic_id=234

A vote tabulation and ranking system for deciding single or
multi-winner contests (elections) using preference or approval
ballots. Dual Dropping will compute the Schwartz Sequential Dropping
(SSD) and Tideman's Ranked Pair (RP) results for each contest round
and select the combined SSD and RP contest outcome with the lowest
overall dropping cost. It has options to compute just the SSD or RP
outcome, various optional tie-breakers, and alternative measures of
defeat and dropping cost (winning votes and/or margin).  See
documentation on SourceForge.

Available in RPM package or tar.gz formats and zip format for
Microsoft Windows (with setup.exe install wizard).




------------------------------

Date: Sat, 31 Jan 2004 21:41:04 GMT
From: John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca>
Subject: can't find cgi-bin
Message-Id: <401C21DC.E860A76@collegesherbrooke.qc.ca>

Anyone have an idea where I can find my cgi-bin? I can't run a script to find it.

Bizarre oh bizarre. My Home directory is this:

/home/users/q/qx04t9mu/www

but of  course, I can only see /www as my root. Even phpinfo() (yes I can do PHP) won't tell me much where cgi-bin is hidden. I've placed it in /www/cgi-bin and /cgi-bin. Nothing works.

Ideas?



------------------------------

Date: 31 Jan 2004 21:50:41 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: can't find cgi-bin
Message-Id: <bvh7vh$sg2$1@canopus.cc.umanitoba.ca>

In article <401C21DC.E860A76@collegesherbrooke.qc.ca>,
John Taylor-Johnston  <jt.johnston@USherbrooke.ca> wrote:
:Anyone have an idea where I can find my cgi-bin? I can't run a script to find it.

That's not a perl question.


:Bizarre oh bizarre. My Home directory is this:

:/home/users/q/qx04t9mu/www

:but of  course, I can only see /www as my root. Even phpinfo() (yes I can do PHP) won't tell me much where cgi-bin is hidden. I've placed it in /www/cgi-bin and /cgi-bin. Nothing works.

You might not -have- a cgi-bin. Or your WWW server might be
configured to allow cgi scripts in any directory (if you can
do php from a directory, then it -is- a script directory.)
Or your WWW server might be configured so that you can
designate your own script directories or script filetypes, such as
by adding a line to a .htaccess file that looks something like

AddType application/x-httpd-cgi .cgi


The best thing to do is ask your support people.

If it were a system I was authorized to use a shell on, I
would use 'ps' to see if I could find the httpd binaries, and
deduce from there the likely location of the server configuration
files and read the config for myself. But some admins might
get a bit upset about that.
-- 
   I don't know if there's destiny,
   but there's a decision!                  -- Wim Wenders (WoD)


------------------------------

Date: Sat, 31 Jan 2004 21:56:30 GMT
From: John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca>
Subject: Re: can't find cgi-bin
Message-Id: <401C257A.F8514DA9@collegesherbrooke.qc.ca>

Sigh. Newsgroups are for asking for help.
I must have one, even if I cannot see it. If I type:
http://www.glquebec.org/cgi-bin/

I do get a 403 error, which tells me something; in fact:
"You don't have permission to access /cgi-bin/ on this server"

I have tried "any" directory. Can't shell. I'll try the htaccess thing to see.

O.K. will make phone calls on Monday.

> :Anyone have an idea where I can find my cgi-bin? I can't run a script to find it.
> That's not a perl question.
>
> You might not -have- a cgi-bin. Or your WWW server might be
> configured to allow cgi scripts in any directory (if you can
> do php from a directory, then it -is- a script directory.)
> Or your WWW server might be configured so that you can
> designate your own script directories or script filetypes, such as
> by adding a line to a .htaccess file that looks something like
>
> AddType application/x-httpd-cgi .cgi
>
> The best thing to do is ask your support people.
>
> If it were a system I was authorized to use a shell on, I
> would use 'ps' to see if I could find the httpd binaries, and
> deduce from there the likely location of the server configuration
> files and read the config for myself. But some admins might
> get a bit upset about that.
> --
>    I don't know if there's destiny,
>    but there's a decision!                  -- Wim Wenders (WoD)



------------------------------

Date: Sat, 31 Jan 2004 21:45:11 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: can't find cgi-bin
Message-Id: <bvh7qs$sd6$1@news.simnet.is>

"John Taylor-Johnston" <taylorjo@collegesherbrooke.qc.ca> wrote in message
news:401C21DC.E860A76@collegesherbrooke.qc.ca...
> Anyone have an idea where I can find my cgi-bin? I can't run a script to
find it.
>
> Bizarre oh bizarre. My Home directory is this:
>
> /home/users/q/qx04t9mu/www
>
> but of  course, I can only see /www as my root. Even phpinfo() (yes I can
do PHP) won't tell me much where cgi-bin is hidden. I've placed it in
/www/cgi-bin and /cgi-bin. Nothing works.
>
> Ideas?

yes. ask your system administrator.

gnari





------------------------------

Date: 31 Jan 2004 17:41:14 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: how to check for ip address that falls inside a range.
Message-Id: <bvgpbq$ma5$1@canopus.cc.umanitoba.ca>

In article <bvfdgl$rqqgc$1@ID-184292.news.uni-berlin.de>,
Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote:
:Walter Roberson wrote:
:> Ah, and I just found a theoretical flaw in the inet_aton version. 

:So why not keep it simple, then?

:http://groups.google.se/groups?selm=bvck8u%24kijvq%241%40ID-184292.news.uni-berlin.de

sprintf '%03s' of each quad leads to string comparisons that are
longer than they need be. Not important for a single such test, but
if you are doing many such tests, it could add up. More efficient
string tests can be had by pack()ing each octet as a character.
Looking over some old code last night, I find I have

  pack 'C*', split /\./ $_

The question then would be whether conversions from the textual
multi-character octets into binary characters are more efficient
than the sprintf '%03s'. The %03s requires an internal string to
binary conversion as it is (the '3' into the number 3 internally)
and sprintf has a lot of overhead. Possibly more efficient than
either of these would be some manipulations involving substr
and a leading '000' concatenated on...
-- 
   Entropy is the logarithm of probability   -- Boltzmann


------------------------------

Date: Sat, 31 Jan 2004 17:53:32 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: how to check for ip address that falls inside a range.
Message-Id: <bvgq2s$sf4$2@wisteria.csv.warwick.ac.uk>


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
> In article <bvfdgl$rqqgc$1@ID-184292.news.uni-berlin.de>,
> Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote:
> :Walter Roberson wrote:
> :> Ah, and I just found a theoretical flaw in the inet_aton version. 
> 
> :So why not keep it simple, then?
> 
> :http://groups.google.se/groups?selm=bvck8u%24kijvq%241%40ID-184292.news.uni-berlin.de
> 
> sprintf '%03s' of each quad leads to string comparisons that are
> longer than they need be. Not important for a single such test, but
> if you are doing many such tests, it could add up.

Premature optimization is the root of all evil.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


------------------------------

Date: Sat, 31 Jan 2004 19:52:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to check for ip address that falls inside a range.
Message-Id: <bvgts8$s150d$1@ID-184292.news.uni-berlin.de>

Walter Roberson wrote:
> sprintf '%03s' of each quad leads to string comparisons that are 
> longer than they need be.

That's undoubtedly true.

> Not important for a single such test, but if you are doing many
> such tests, it could add up. More efficient string tests can be had
> by pack()ing each octet as a character. Looking over some old code
> last night, I find I have
> 
>   pack 'C*', split /\./ $_
> 
> The question then would be whether conversions from the textual 
> multi-character octets into binary characters are more efficient 
> than the sprintf '%03s'.

I made a benchmark (code below), and this is the result:

                Rate sprintf    pack
     sprintf  8035/s      --    -46%
     pack    14923/s     86%      --

> The %03s requires an internal string to binary conversion as it is
> (the '3' into the number 3 internally) and sprintf has a lot of
> overhead.

Seems as if you are right, i.e. using pack() is more efficient.

Here is the benchmarking code:

     use Benchmark 'cmpthese';
     cmpthese( -5, {
         pack => sub {
             my @ip = ('10.1.2.2', '10.1.2.255');
             for ( @ip ) {
                 $_ = pack 'C*', split /\./, $_;
             }
             return 1 if $ip[0] lt $ip[1];
         },
         sprintf => sub {
             my @ip = ('10.1.2.2', '10.1.2.255');
             for ( @ip ) {
                 $_ = join '',
                   map { sprintf '%03s', $_ } split /\./, $_;
             }
             return 1 if $ip[0] lt $ip[1];
         },
     } );

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Sun, 01 Feb 2004 16:56:38 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: interpreting script
Message-Id: <rc8q10192j9a3rrkcmemad2b6vpguqlc4l@4ax.com>

On Fri, 30 Jan 2004 21:56:44 -0700, in comp.lang.perl.misc you wrote:

>I'm having a hard time interpreting a portion of a perl script (below).  I
>think its looking for the file pattern then determining the age and removing
>it if its over 30 days old.  The line with >30 has kind of got me.  Any help
>would be greatly appreciated.

Short answer: Yes, sort of!

[OT wrt you request/subject line:]

Maybe you had a hard time interpreting it because it is an especially
bad example of Perl code. Bad programming habits/techniques include
but are probably not limited to:

>   @down_file_list = `/bin/ls *.downloaded *.kl2_download | grep -v
    ^^^^^^^^^^^^^^^    ^^^^^^^                               ^^^^

1. (Probably) not using strict

2. Useless use of an external cmd

3. Double useless use of an external cmd

>"_ppsd.zip" 2> /dev/null`;
>
>   foreach $down_file (@down_file_list) {
            ^^^^^^^^^^

4. (Definitely) not using strict

>       chop($down_file);        #remove newline
                                 ^^^^^^^^^^^^^^^
5. Use of old-fashioned chop() instead of more modern and secure
chomp().

>       if (-M $down_file > 30 ) {
>          print "Removing file $down_file in $search_dir/$home_dir\n";
>          system("/bin/rm -f $down_file");

6. Yet another usless use of an external cmd.

7. (Overall:) multiple selections happen at different places whereas
they *could* (easily) be done at the same time.

More effective (mind you, though: I'm *not* saying these are the best
WTDI) code may be as follows:

  for (grep /\Q_ppsd.zip/ && -M >30, 
       <*.downloaded *.kl2_download>) {
  	 unlink $_ or
  	   warn("Can't remove `$_': $!\n"), next;
  	  print "Removing `$_'\n";
       }

or perhaps:

  unlink $_ and
    !print "Removing `$_'\n" or
    warn "Can't remove `$_': $!\n" for 
    grep /\Q_ppsd.zip/ && -M >30, 
    <*.downloaded *.kl2_download>

[both untested]


HTH,
Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


------------------------------

Date: Sat, 31 Jan 2004 17:52:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: interpreting script
Message-Id: <bvgq09$sf4$1@wisteria.csv.warwick.ac.uk>


Michele Dondi <bik.mido@tiscalinet.it> wrote:
> More effective (mind you, though: I'm *not* saying these are the best
> WTDI) code may be as follows:
>
>   for (grep /\Q_ppsd.zip/ && -M >30, 

Err... this is wrong (though perhaps you just don't know what `grep
-v` does):

    for (grep -M > 30 && ! /\Q_ppsd.zip/,

or

    for (grep { -M > 30 and not /\Q_ppsd.zip/ }

as that expr is quite complicated enough to deserve a block of its
own (I find '... and not ...' much less confusing than 'not ... and
 ...', and I don't care about the unnecessary stat()s).

>        <*.downloaded *.kl2_download>) {
>   	 unlink $_ or
>   	   warn("Can't remove `$_': $!\n"), next;
>   	  print "Removing `$_'\n";

Surely the print should come before the unlink? Don't put "\n" on the
end of warn and die messages: it suppresses the line number info. Set
$\ rather than put "\n" on the end of every print statement.

If you don't want to print if the unlink fails, I would have written 

    unlink                           ?
        warn "can't unlink '$_': $!" :
        print "removed '$_'";

>        }
> 
> or perhaps:
> 
>   unlink $_ and
>     !print "Removing `$_'\n" or
>     warn "Can't remove `$_': $!\n" for 
>     grep /\Q_ppsd.zip/ && -M >30, 
>     <*.downloaded *.kl2_download>

Ouch! What's that ! there for? Assuming the print will always
succeed, this evaluates as

    (unlink and 0) or warn

which means that the warn will always happen. Even without that, it's
clearer as

   unlink ? print : warn

; and it could have done with more friendly formatting:

unlink ? print "removed $_" : warn "can't unlink $_: $!"
    for grep { -M > 30 and not /\Q_ppsed.zip/ }
        glob "*.downloaded *.kl2_download";

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


------------------------------

Date: Sat, 31 Jan 2004 19:31:55 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: interpreting script
Message-Id: <Xns948193D3F2D5Fdkwwashere@216.168.3.30>

Ben Morrow <usenet@morrow.me.uk> wrote:

>[snip...]     Even without that, it's clearer as
> 
>    unlink ? print : warn
> 
> ; and it could have done with more friendly formatting:
> 
> unlink ? print "removed $_" : warn "can't unlink $_: $!"
>     for grep { -M > 30 and not /\Q_ppsed.zip/ }
>         glob "*.downloaded *.kl2_download";

I don't like any of the ways you all have written it. :-)

    for my $file (glob "*.downloaded *.kl2_download") {
        next unless -M $file > 30 and $file !~ /\Q_ppsed.zip/;
        unlink $file or do {
            warn "Can't unlink '$file': $!";
            next;
        };
        print "Removed '$file'\n";
    }

It's a bit more verbose, but easier (at least for me) to read.


------------------------------

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 6058
***************************************


home help back first fref pref prev next nref lref last post