[10800] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4401 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 10 22:07:18 1998

Date: Thu, 10 Dec 98 19:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 10 Dec 1998     Volume: 8 Number: 4401

Today's topics:
        Authentification program? <kjcox@vii.com>
        blank line (Tri Tram)
    Re: blank line (Sam Holden)
        CGI Varaible: REMOTE_USER <rwang@erols.com>
    Re: Errors with SETUID and Perl Script <asharp@nector.com>
    Re: Forward slash in Win95 ?? & Perl on Win32 (Tye McQueen)
    Re: Help wanted: saving remote URL to local file dturley@pobox.com
    Re: how to make directory tree?? (Clay Irving)
    Re: Info source for Perl for Win32 dturley@pobox.com
    Re: interpolation constipation <antony@fabric8_no_spam.com>
    Re: Interpreting Multipart encoding <gellyfish@btinternet.com>
    Re: mail attachment <preble@ipass.net>
    Re: MySQL or PostGresSQL or ??? (follow-up question) (Victor B Wagner)
    Re: Pattern matching and name parsing <r28629@email.sps.mot.com>
    Re: perl and mac characters (Victor B Wagner)
    Re: Running .pl and .cgi files in dos. (Victor B Wagner)
        Semaphores and IPC question hutchiss@my-dejanews.com
    Re: Solaris 2.6 x86 miniperl compile error (Emmett McLean)
        Sorting problem: Is there a better way? <please@see.sig>
    Re: Sorting problem: Is there a better way? (Sam Holden)
    Re: Sorting problem: Is there a better way? (Sean McAfee)
        Troublesome taint problem Gerben_Wierda@RnA.nl
        unlinking files from Perl CGI under Apache (Emmett McLean)
    Re: unlinking files from Perl CGI under Apache <uri@ibnets.com>
    Re: Using fonts in table built with CGI.pm (Clay Irving)
    Re: Y2K potential problem in localtime() <r28629@email.sps.mot.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 10 Dec 1998 23:09:46 +0000
From: "Kerry J. Cox" <kjcox@vii.com>
Subject: Authentification program?
Message-Id: <367054B9.7A096466@vii.com>

Okay, here's what I am attempting to do.  I am using Apache's htpasswd
to set up a secure site,  However, what I really need is a frontend that
will allow several groups of people to log in, making sure that each
username was in my password file and was valid, and then based upon whom
the person was, direct them to a specific site.
For example, Persons A, B and C wanted to come to my page where I was
placing information about their respective companies.  Since I don't
want anyone else except for A, B and C to see the info, I have created a
a login box using apache.  But I also don't want A to go to B's site or
C to see A's site.  So when A logs in, he sees
http://this.domain.com/testsite.html and when B logs in he sees
http://this.domain.com/anothersite.html
Each of these sites will also be drawing information from a database and
posting it dynamically also, but that's another story.
What I am asking therefore, is there a Perl program out there that will
run on Linux or Solaris that will create dynamic links to separate pages
based upon who is logging in?  Has anyone else tried and done something
like this?  I would assume there is a simple Perl script for this.
Thanks.
KJ


--

 .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
| Kerry J. Cox          Vyzynz International Inc.   |
| kjcox@vii.com         Systems Administrator       |
| (801) 596-7795        http://vii.com              |
| All Things Linux      http://quasi.vii.com/linux/ |
`---------------------------------------------------'





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

Date: Fri, 11 Dec 1998 00:16:37 GMT
From: tram@olympic.seas.ucla.edu (Tri Tram)
Subject: blank line
Message-Id: <F3ry3p.9H7@seas.ucla.edu>


I am curious as to what the regular expression would be for a blank line?
I've tried something like:
/^\s\s$/, but that doesn't seem to work.

Suppose I have some text like:

this is a text
  this is more text

the above line is blank
more text

So I was curious as to what I should use for the regular expression
to match the third line above?  Thanks.

-----------------------------------------------------------------
Tri Tram, Computer Science and Engineering at UCLA
http://www.seas.ucla.edu/~tram


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

Date: 11 Dec 1998 00:41:35 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: blank line
Message-Id: <slrn770qhv.jj4.sholden@pgrad.cs.usyd.edu.au>

On Fri, 11 Dec 1998 00:16:37 GMT, Tri Tram <tram@olympic.seas.ucla.edu> wrote:
>
>I am curious as to what the regular expression would be for a blank line?
>I've tried something like:
>/^\s\s$/, but that doesn't seem to work.
That matches a line containing exactly two whitespace characters, or one
white space character and the new line.

/^$/ will match an empty line.
/^\s*$/ will match a line that only contains white space (or is empty).

See 'perldoc perlre'
-- 
Sam

Can you sum up plan 9 in layman's terms? It does everything Unix does
only less reliably.
	--Ken Thompson


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

Date: Fri, 11 Dec 1998 02:54:06 +0000
From: John Wang <rwang@erols.com>
Subject: CGI Varaible: REMOTE_USER
Message-Id: <3670894E.D2448EC4@erols.com>

Hi, all:
    I did a very simple web site with Apache on a HP/UX 10.20.  I
require user entering a password, using basic authentication, htpasswd.
What I want to do is to let the user change their own password.  The
first thing I need to do is to figure out who just logged onto the web.
>From the two books I have Apache Server Bible and CGI Programming on the
WWW, there is a CGI variable, REMOTE_USER.  It seems that that is what I
want.  It says if you have basic authentication, the variable will be
set.  Well, it did not get set.   I wrote a little script to display
everything in %ENV, REMOTE_USER is not there, it has REMOTE_ADDR.  Now,
I am stuck.  If I cannot even figure out who is on, how am I going to
change the password.

    Has anyone experimented with DBM file authentication?  With a
potential of 2000 users, the book says authenticating with flat file is
kinda slow.  I just am just wondering has anyone tried it.  How good is
it?

Thanks

John Wang.



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

Date: Thu, 10 Dec 1998 16:10:19 -0700
From: Andy Sharp <asharp@nector.com>
Subject: Re: Errors with SETUID and Perl Script
Message-Id: <367054DB.92B2A014@nector.com>

Are you Certain that your system allows setuid Scripts?

Look for something like 
/usr/local on /dev/dsk/c0t0d0s5 setuid/read/write/largefiles
				^^^^^^^
in the output of /sbin/mount

If so, are you certain that perl was compiled with setuid allowed on
said system?

if not, then use a .c wrapper

mike_orourke@em.fcnbd.com wrote:

> >I created a perl script that will allow users to "chown" files that they own
> >to another valid UID on the server.  I seemed to have resolved the "tainted"
> >data problem, but now the "chown" command is still failing. The Perl script
> >has "4755" permissions and is owned by "root". When I run the script as
> >"root", everything works O.K. But when I run the script while connected as
> >the "owner" of the file I am trying to modify, I get the following message :
> 
> >chown: /export/home/lddv/test_chmod.txt: Not owner
> >Could not run CHMOD at /dev/fd/3 line 48.


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

Date: 10 Dec 1998 18:52:13 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Forward slash in Win95 ?? & Perl on Win32
Message-Id: <74pqbt$lld@fohnix.metronet.com>

lr@hpl.hp.com (Larry Rosler) writes:
) 
) Forward slash is a command line switch only to the command interpreter.  
) In the Windows/DOS file system, it is exactly equivalent to backslash, 
) and can be used interchangeably.  In fact, in a Perl program there is no 
) need to use backslash (which requires extra ugly escaping) except when 
) communicating with the command interpreter (one-argument system(), 
) etc.).

Deja vu?  The command interpreter doesn't interpret much of most
commands and does allow / as a directory delimiter (as in
    C:> c:/perl/bin/perl -de 0
works just fine in NT's cmd.exe, for example).

However, many commands (all of which have to parse their own
command line under Microsoft systems, and can choose to do it
differently) always interpret "/" as the start of an option --
including the commands built into the command interpreter.

So you can always use "/" as a directory separator in Perl except
in command-line arguments to specific external programs that don't
allow it.

And more-than-one-argument calls to C<system()> aren't (much?)
different than one-argument calls to C<system()> when you are on
a Microsoft platform -- they still end up invoking the command
interpreter.  And even if they didn't, the program that got run
would still reparse its command line, treating "/" as the start of
an option if that is what it normally does.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Fri, 11 Dec 1998 01:16:31 GMT
From: dturley@pobox.com
Subject: Re: Help wanted: saving remote URL to local file
Message-Id: <74prpe$ek9$1@nnrp1.dejanews.com>

In article <01be2472$54648ca0$b2c548c2@is>,
  "Simmo" <simsi@hotmail.com.nospam> wrote:
> Hi....a virtual beer for anyone that can give me a simple answer to this
> one :)
>
> I want to retrieve the contents of a text file i have created on a remote
> server and display it on the local server within a web page (but not AS the
> web page) using Perl. Is it possible to:
>
> use "Location: http://blah" to print to a file rather than the screen

perldoc LWP::Simple

 getstore($url, $file)
          Gets a document identified by a URL and stores it in
          the file. The return value is the HTTP response code.


David Turley
dturley@pobox.com
http://www.binary.net/dturley/

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 10 Dec 1998 21:20:35 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: how to make directory tree??
Message-Id: <74pvhj$g14@panix.com>

In <366f2350.0@nemo.idirect.com> "Gorbatchev Dmitri" <dimag@idirect.com> writes:

>i'm trying to make a directory tree, but i can't. Next code show each
>directory, but don't show path to directoryes :( how to make a directory
>tree??? plz, tell me somebody!!

>$dir = 0;
>sub SearchDir
>{
> chdir $_[0] || die "can't opendir $_[0]: $!";
> opendir(DIR, ".");
> foreach (readdir DIR) {
>  if(($_ ne ".") && ($_ ne "..") && (-d $_)) {
>   local($d) = "";
>   push(@dirs, "$_\\");
>   $deep++;
>   SearchDir($dirs[$dir++]);
>   $deep--;
>   chdir "..";
>  }
> }
> closedir(DIR);
>}
>SearchDir(".");
>foreach (@dirs) {
> print "$_\n";
>}

This is a program I ran across awhile back (I don't know the author of
the program):

#!/usr/local/bin/perl
##############################################################################
#
#
# Display a tree structure like the DOS tree command                         #
#
#
# Usage: perl tree.pl [source [depth]]                                       #
#
#
##############################################################################
my $tree;
my $prefix;
my $maxlevel;

$tree     = $ARGV[0];
$maxlevel = $ARGV[1];

if (! defined $tree) {$tree = '.'}
if ($tree =~ /\?/)    {die ("Usage: perl tree.pl [source [depth]]\n")}
if ($maxlevel !~ /d*/) {die ("Usage: perl tree.pl [source [depth]]\n")}
if ($maxlevel == 0) {$maxlevel = -1}

$prefix = '';
disptree ($tree,$prefix,$maxlevel);

sub disptree {

    my $tree;
    my $maxlevel;
    my $current_entry;
    my $next_entry;
    my $prefix ;
    my $more_dirs;
    my $dirh;
    my $skip_entry;

    $tree      = $_[0];
    $prefix    = $_[1];
    $maxlevel  = $_[2];

    if ($maxlevel == 0) {return}

    $tree =~ s|/*$|/|; # keep exactly one /

    # Read the target directory
    $dirh = 'DIRH'.$maxlevel; # create a unique dir handle
    (opendir ($dirh , $tree)) || (warn "Can't read $tree $!\n");

    # skip files until directory found
    $skip_entry = 1;
    while ($skip_entry) {
        $current_entry = readdir($dirh);
        if    (! defined ($current_entry)) {$skip_entry = 0} # End Of Dir
        elsif ( ($current_entry ne '.') && ($current_entry ne '..') && (-d $tree
 .$current_entry))  {$skip_entry = 0;}
    }
    #
    # --- Now check the rest of the entries for directories
    #
    if (defined $current_entry) { # did we hit EOD (EndOfDir) ?
        $more_dirs = 1; # No, raise the 'more_dirs' flag
        while ($more_dirs) {
            # skip files until directory found
            $skip_entry = 1;
            while ($skip_entry) {
                $next_entry = readdir ($dirh);
                if (-d $tree.$next_entry) { $skip_entry = 0 } ;
            }
            # process the current dir
            print ($prefix.'+ '.$current_entry."\n"); # print the current direct
ory
            if (defined $next_entry) { # is this the last dir ?
                disptree ($tree.$current_entry , $prefix.'|   ' , $maxlevel-1);
# no, prepend the 'history'
                $current_entry = $next_entry;
            } else {
                disptree ($tree.$current_entry , $prefix.'    ' , $maxlevel-1);
# yes. print this entry plainly
                $more_dirs = 0;
            }
        }
    }
    closedir $dirh;
}

-- 
Clay Irving
clay@panix.com


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

Date: Fri, 11 Dec 1998 01:18:02 GMT
From: dturley@pobox.com
Subject: Re: Info source for Perl for Win32
Message-Id: <74prs9$ekn$1@nnrp1.dejanews.com>

In article <36701854.0@amhnt2.amherst.edu>,
  "Paul Chapin" <pdchapin@unix.amherst.edu> wrote:
> According the the documentation that came with my copy of Perl for Win32,
> the FAQ is at www.perl.hip.com and the mailing list is at mail.hip.com.
> However, I'm not showing either of these to be valid addresses.  Has this
> material moved?  Does it mean that my copy of Perl is out of date?

http://www.activestate.com

You can get a 'modern' copy of Perl there too. :-)

--
David Turley
dturley@pobox.com
http://www.binary.net/dturley/

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 10 Dec 1998 15:23:27 -0800
From: antony quintal <antony@fabric8_no_spam.com>
Subject: Re: interpolation constipation
Message-Id: <367057EF.766761AB@fabric8_no_spam.com>


Greg Bacon wrote:

> This is a FAQ. 


whoops. thanks to all....

i repeat: a method is simply a subroutine expecting an object which is
simply a referenced thingy.


:)

anyway it all flows much more freely now.  %)

antony

-- 
   8888
 888  888   
888    888  :::::::::::::::::::::::
 888  888   http://www.fabric8.com
   8888     san francisco
 888  888   415.487.9702
888    888  :::::::::::::::::::::::
 888  888   
   8888


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

Date: 8 Dec 1998 18:43:31 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Interpreting Multipart encoding
Message-Id: <74js0j$1ej$1@gellyfish.btinternet.com>

On Tue, 8 Dec 1998 17:19:50 -0000 Artoo <r2-d2@REMOVEbigfoot.com> wrote:
> Hi all
> 
> How can you have a CGI script Interpret the Multipart Encoding type?  I have
> a form that has both normal text fields and a file upload field and need to
> be able to interpret the encoded text fields.
> 

use CGI;

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Thu, 10 Dec 1998 18:46:38 -0500
From: "E. Preble" <preble@ipass.net>
Subject: Re: mail attachment
Message-Id: <p4Zb2.969$kx1.1398@news.ipass.net>


Michael Renshaw wrote in message
<366FFEFD.AE7@lndn.tensor.pgs.com>...
does anyone know how to send a file as an attachment in perl.

<-snip->

I've made a PERL file attaching script publically available at:
http://www.datatrendsoftware.com/automail_lite.html

It uses MIME::ENTITY to send attachments (binary or otherwise)
from Formmail (Matt Wrights script) inputs.

If you disect that code, you can see how it works quite easily.

E. Preble




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

Date: 7 Dec 1998 13:12:23 GMT
From: vitus@brass.fe.msk.ru (Victor B Wagner)
Subject: Re: MySQL or PostGresSQL or ??? (follow-up question)
Message-Id: <74gk7n$44c$3@zware.space.ru>

Peter Smith (psmith01@mindspring.com) wrote:
: Peter Smith wrote:
: > 
: > I'm about to write a web-to-database ecommerce application.  I plan on
: > using Apache web server with Perl to access the database.  Which
: > database is better, MySQL or PostGresSQL??  Are there others I missed??
: > The cheaper the database, the better!
: > 

It depends. If you need no more than simple queries, MySQL is faster.
If you need constraints, nested queries and stored procedures,
PostgreSQL is only solution in price class $0.

: Also, should I use the RPM-based MySQL since I'm running RedHat, or
: should I just grab the latest binary??

Neither. Grab the latest source and compile yourself tuning to your
environment carefully. Same for perl and apache. You probably know what
you need better than package maintainer.

: -- 
: --Peter--
: psmith01@mindspring.com

--
--------------------------------------------------
Victor Wagner			vitus@ice.ru
Programmer			Office:7-(095)-964-0380
Institute for Commerce 		Home: 7-(095)-135-46-61
Engineering                     http://www.ice.ru/~vitus


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

Date: Thu, 10 Dec 1998 17:33:14 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: baliga@synopsys.com
Subject: Re: Pattern matching and name parsing
Message-Id: <36705A3A.4DA43A21@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

Yogish Baliga wrote:
> 
> @array2 = map { m/^(.)/; $1; } @array;

not need to explicitly return $1 here:

  @array2 = map { m/^(.)/ } @array;
or
  @array2 = map /^(.)/, @array;   # save a few chars ;-)

-TK


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

Date: 8 Dec 1998 14:12:13 GMT
From: vitus@brass.fe.msk.ru (Victor B Wagner)
Subject: Re: perl and mac characters
Message-Id: <74jc3t$m0c$1@zware.space.ru>

Steve Nite (sramchar@centernet.ca) wrote:
: Whenever I use a mac to produce an html docoment, characters are
: produced to look like an apostrophy('), but look like a question mark(?)
: on the pc. How can I use perl to translate the characters to look
: consistantly like an apostrophy(').

You can try to convert your HTML to unicode using
Unicode::String and Unicode::Map8 modules from CPAN.
In Unicode this charachers have fixed positions. And only thing
you'll need to do is to define input charset.(but, there is a chance
that your mac-based software already done this for you inserting
<META HTTP-EQUIV name="content-type" value="text/html; charset=...">
into document.

--
--------------------------------------------------
Victor Wagner			vitus@ice.ru
Programmer			Office:7-(095)-964-0380
Institute for Commerce 		Home: 7-(095)-135-46-61
Engineering                     http://www.ice.ru/~vitus


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

Date: 7 Dec 1998 13:09:33 GMT
From: vitus@brass.fe.msk.ru (Victor B Wagner)
Subject: Re: Running .pl and .cgi files in dos.
Message-Id: <74gk2d$44c$2@zware.space.ru>

brad (bradnix@geocities.com) wrote:
: Would there be any possible way to simply type  myprog.cgi instead of perl
: myprog.cgi in dos?

Yes. Replace command.com with something more sensible, like 4dos.

: Thanks



--
--------------------------------------------------
Victor Wagner			vitus@ice.ru
Programmer			Office:7-(095)-964-0380
Institute for Commerce 		Home: 7-(095)-135-46-61
Engineering                     http://www.ice.ru/~vitus


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

Date: Thu, 10 Dec 1998 23:15:22 GMT
From: hutchiss@my-dejanews.com
Subject: Semaphores and IPC question
Message-Id: <74pkm8$8km$1@nnrp1.dejanews.com>

I have an application where I need to be able to check the value of a
semaphore or flag set by another process without blocking.

Sockets and UDP don't work for this.  perlIPC documentation mentions
SysV semaphores.  It doesn't make much sense to me.

I need something that will work on ActiveState's NT port and on Solaris.

Am I going to be reduced to using the filesystem for my semaphores?

Any help, direction, or commiseration is welcome.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 10 Dec 1998 16:04:29 -0800
From: emclean@slip.net (Emmett McLean)
Subject: Re: Solaris 2.6 x86 miniperl compile error
Message-Id: <74pnid$q77@slip.net>

Try :

gcc   -o miniperl miniperlmain.o libperl.a -lm

In article <366c8b24.836062@news.ucsc.edu>,
Darren Littlejohn <darrenl@cats.ucsc.edu> wrote:
>Would you happen to know anything about this:
>
>rm -f libperl.a
>ar rcu libperl.a perl.o  gv.o toke.o perly.o op.o regcomp.o dump.o
>util.o mg.o byterun.o hv.o av.o run.o pp_hot.o sv.o pp.o scope.o
>pp_ctl.o pp_sys.o doop.o doio.o regexec.o taint.o deb.o universal.o
>globals.o perlio.o 
>gcc   -o miniperl miniperlmain.o libperl.a 
>Undefined                       first referenced
> symbol                             in file
>log                                 libperl.a(pp.o)
>pow                                 libperl.a(pp.o)
>sqrt                                libperl.a(pp.o)
>floor                               libperl.a(pp.o)
>atan2                               libperl.a(pp.o)
>exp                                 libperl.a(pp.o)
>sin                                 libperl.a(pp.o)
>cos                                 libperl.a(pp.o)
>ld: fatal: Symbol referencing errors. No output written to miniperl
>*** Error code 1
>make: Fatal error: Command failed for target `miniperl'
>
>I'm on Solaris 2.6 for Intel x86. 
>
>Darren Littlejohn
>darrenl@cats.ucsc.edu
>
>
>




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

Date: Fri, 11 Dec 1998 11:50:08 +1100
From: Erik de Castro Lopo <please@see.sig>
Subject: Sorting problem: Is there a better way?
Message-Id: <36706C40.2AA1@see.sig>

Hi all,

I've got a list of items which are all of the form
of one or more alpahbetic charaters followed by
one or more digits and I need to sort them. The 
sorting should be done on the alphabetic part
first. If there are two list items with the same
alphabetic part they should be ordered on the basis
of the size of the numeric part.

Fortunately I have read the documentation and come
up with a working solution but I've been using Perl
long enough to know there is a least one more way
of doing this and probably even a better way.

My solution is included after my .sig. Any takers
for improvements/other solutions?

Thanks,
Erik
-- 
-------------------------------
Erik de Castro Lopo
Fairlight ESP Pty Ltd
e.de.castro AT fairlightesp.com.au


#!/usr/bin/perl -w

use strict ;

sub designator_order () ;

my (@list, @sorted) ;

@list = ( 'R5', 'AX23', 'R11', 'AB41', 'R1', 'R200', 'X12' ) ;
print "list   : [@list]\n" ;

@sorted = sort designator_order (@list) ;
print "sorted : [@sorted]\n" ;

sub designator_order ()
{	my ($ta, $tb, $order) ;

	$ta = uc ($::a) ;
	$ta =~ s/[0-9]//g ;
	$tb = uc ($::b) ;
	$tb =~ s/[0-9]//g ;

	$order = $ta cmp $tb ;
	if ($order)
	{	return $order ;
		} ;

	$ta = uc ($::a) ;
	$ta =~ s/[A-Z]//g ;
	$tb = uc ($::b) ;
	$tb =~ s/[A-Z]//g ;

	return ($ta <=> $tb) ;
}


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

Date: 11 Dec 1998 01:24:14 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <slrn770t1u.k64.sholden@pgrad.cs.usyd.edu.au>

On Fri, 11 Dec 1998 11:50:08 +1100, Erik de Castro Lopo <please@see.sig> wrote:
>Hi all,
>
>I've got a list of items which are all of the form
>of one or more alpahbetic charaters followed by
>one or more digits and I need to sort them. The 
>sorting should be done on the alphabetic part
>first. If there are two list items with the same
>alphabetic part they should be ordered on the basis
>of the size of the numeric part.
>
>Fortunately I have read the documentation and come
>up with a working solution but I've been using Perl
>long enough to know there is a least one more way
>of doing this and probably even a better way.

I would probably do the following :
@sorted = map {$_->[2]}
          sort { ($a->[0] cmp $b->[0]) || ($a->[1] <=> $b->[1]) }
          map {[ (/^([A-Z]*)([0-9]*)$/g), $_ ] } @list;

Which is different than your solution since I don't uppercase the the
values (that could be added I guess). The difference is that I split
the elements into the string and numeric part once, and then do nlogn
comparisons in the sort. Your solution does the hard work of splitting
the values up nlogn times, but had much less overhead in terms of memory
(and playing around with memory costs runtime speed).

Some benchmark results :

@list = ( 'R5', 'AX23', 'R11', 'AB41', 'R1', 'R200', 'X12' ) ;
timing 4096 iterations 
   original:  2 wallclock secs ( 1.83 usr +  0.00 sys =  1.83 CPU)
s.transform:  2 wallclock secs ( 1.95 usr +  0.01 sys =  1.96 CPU)

@list = ( 'R5', 'AX23', 'R11', 'AB41', 'R1', 'R200', 'X12' ) x 100;
timing 256 iterations
   original: 20 wallclock secs (19.60 usr +  0.00 sys = 19.60 CPU)
s.transform: 12 wallclock secs (12.25 usr +  0.00 sys = 12.25 CPU)

I prefer my solution for readable reasons, because it is an idiom for
sorting I see a lot. 

-- 
Sam

Remember that the P in Perl stands for Practical.  The P in Python
doesn't seem to stand for anything.
	--Randal Schwartz in <8cemsabtef.fsf@gadget.cscaper.com>



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

Date: Fri, 11 Dec 1998 01:26:23 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Sorting problem: Is there a better way?
Message-Id: <3x_b2.943$4w2.4276876@news.itd.umich.edu>

In article <36706C40.2AA1@see.sig>,
Erik de Castro Lopo  <please@see.sig> wrote:
>I've got a list of items which are all of the form
>of one or more alpahbetic charaters followed by
>one or more digits and I need to sort them. The 
>sorting should be done on the alphabetic part
>first. If there are two list items with the same
>alphabetic part they should be ordered on the basis
>of the size of the numeric part.

>Fortunately I have read the documentation and come
>up with a working solution but I've been using Perl
>long enough to know there is a least one more way
>of doing this and probably even a better way.

With Perl, this is almost always the case.  I suggest an old-fashioned
Schwartzian Transform (see perlfaq4):

@list = ( 'R5', 'AX23', 'R11', 'AB41', 'R1', 'R200', 'X12' ) ;

@sorted = map  { $_->[0] }
          sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
          map  { [ $_, /([A-Za-z]+)(\d+)/ ] } @list;

Your sample code sorted the alphabetic part case-insensitively, although
you didn't mention that part in your problem statement.  If that's in fact
what you need, this will do the trick:

@sorted = map  { $_->[0] }
          sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
          map  { /([A-Za-z]+)(\d+)/; [ $_, uc($1), $2 ] } @list;

More robust versions are possible; these both assume that all of the elements
of @list are in the format you described (alphabetic followed by numeric).

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Thu, 10 Dec 1998 21:47:16 GMT
From: Gerben_Wierda@RnA.nl
Subject: Troublesome taint problem
Message-Id: <F3rr6s.11o@RnA.nl>

I have a subroutine that complains about an insecure dependency when 
appending to a mailbox, but it looks like the variables are not tainted. 
Using perl 5.005_02. The routine doesn;t complain about tainted vars using 
the tainted routine but crashes anyway when opening the mboxfile

requite 'tainted.pl';

sub append_mbox {
    my $frommboxref = shift;
    my $tomboxref = shift;

    warn "Tainted $filenameref" if &tainted( $filenameref);
    warn "Tainted $tomboxref" if &tainted( $tomboxref);
    warn "Tainted $$filenameref" if &tainted( $$filenameref);
    warn "Tainted $$tomboxref" if &tainted( $$tomboxref);
    if (open TMPMSG, "<$$frommboxref") {
        my $old_umask = umask;
        umask 066;
        if (open( MBOX, ">>" . $$tomboxref)) {
            &lock_open_file( *MBOX{IO});

What can I do to find out what is going wrong? It used to work fine before 
installing 5.005_02 (though this is not 100% sure because the software was 
changed) so i suspect it might be a perl bug in this version for this 
machine.

-- 
Gerben_Wierda@RnA.nl (Gerben Wierda)
"If you don't know where you're going, any road will take you there"
Paraphrased in Alice in Wonderland, originally from the Talmud.

"Your io is pretty std" -- Larry Wall


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

Date: 10 Dec 1998 15:59:18 -0800
From: emclean@slip.net (Emmett McLean)
Subject: unlinking files from Perl CGI under Apache
Message-Id: <74pn8m$psh@slip.net>


Hi,
 
I'm running Apache on a UNIX machine.
 
When I attempt to remove (unlink) a file with a
perl cgi script the file doesn't get removed.
 
For example :
 
unlink $fname;
system ("rm $fname");
 
where in different scripts $fname had 
either relative or absolute path references ....
 
Of course, the script works fine
when I run it from the UNIX command line.
 
Is there some parameter I should have set
in my Apache configuration to enable the
deletion of files?

If so, what?


BTW, I've tried various permutations of
file permissions so I don't think that
is the source of the problem, the files
are chmod 1777 and owned by nobody
which runs Apache.
 
 
Thanks,
 
Emmett
 



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

Date: 10 Dec 1998 19:07:07 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: unlinking files from Perl CGI under Apache
Message-Id: <39u2z3mthw.fsf@ibnets.com>

>>>>> "EM" == Emmett McLean <emclean@slip.net> writes:

  EM> When I attempt to remove (unlink) a file with a perl cgi script
  EM> the file doesn't get removed.
 
  EM> unlink $fname; system ("rm $fname");
 
why are you doing both? or is that just an example of how you might do
it?

no reason to ever use system to just remove a file. if unlink can't do
it, system( "rm blah" ) can't do it either.

  EM> BTW, I've tried various permutations of file permissions so I
  EM> don't think that is the source of the problem, the files are chmod
  EM> 1777 and owned by nobody which runs Apache.
 
the permission of the directory is key. you can't modify the directory
to remove the file unless you have write permission there. in fact if
you have write permission on a directory, you don't even need write perm
on the file to remove it.

hth,

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: 10 Dec 1998 21:48:35 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Using fonts in table built with CGI.pm
Message-Id: <74q163$htg@panix.com>

In <74ph2f$5ei$1@nnrp1.dejanews.com> brandtr3769@my-dejanews.com writes:

> In the code snip below, I would like the $title varible to use a font. Is it
>possible to put a font tag in the brackets?

>print
>table({-align=>'CENTER',-bgcolor=>'LIGHTBLUE'},
>             Tr({-align=>CENTER,-valign=>TOP},
>             [
>                th({-BGCOLOR=>DARKBLUE},[$title])
>             ]
>           )
>     );

Hold on...

Let me go read the docs and write some test code -- I'll get right back
to you.

-- 
Clay Irving
clay@panix.com


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

Date: Thu, 10 Dec 1998 17:54:45 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: finsol@ts.co.nz
Subject: Re: Y2K potential problem in localtime()
Message-Id: <36705F45.2E195BF1@email.sps.mot.com>

finsol@ts.co.nz wrote:
> 
> In article <01be22f2$9aab4c20$a4c448c2@is>,
>   "Simmo" <simsi@hotmail.com.nospam> wrote:
> > Hi,
> >
> > Apologies if this has been posted or if i'm doing something silly but i've
> > noticed in my localtime() calls that when the year gets to 2000, the year
> > gets returned as 100.
> 
> Warning, Simmo, Perl programmers can get very tetchy when this subject is
> discussed. According to the experts out there is no problem with
> localtime()usage - despite continued evidence to the contrary such as yours.
> Their opinion is that anyone who does misuse it should not be programming.
> Many Perl programmers are certainly not amenable to having other programmers
> alerted to the issue via this forum.
> 
> If you would like to learn more about the 'booby trap code' problem and the
> associated programmer denial, you can access my articles published in
> Computerworld at URL:
> http://www.ts.co.nz/~finsol/y2k_articles.htm
> 
> You are not alone in misunderstanding the localtime() year value.

Just another prove that it is so easy to start a war, if you want to.
You should stop selling your articles here (I admire your guts to keep
posting provocative messages about Perl in a perl ng though).

-TK


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4401
**************************************

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