[7872] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1497 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 18 06:17:26 1997

Date: Thu, 18 Dec 97 03:00:26 -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, 18 Dec 1997     Volume: 8 Number: 1497

Today's topics:
     <SELECT MULTIPLE >  Script only gives one value. Can yo <rcd@kiwi.net>
     Changing passwd (Philip Ling)
     Re: Changing passwd (brian d foy)
     Check file's attribute in WinNT ? How? (Fool )
     Re: getting correct web server headers <bowlin@sirius.com>
     Re: Help Needed modifying a text file using perl <rjk@coos.dartmouth.edu>
     Re: How to invoke the Unix VI cmd from perl script to m (Stephen P. Clouse)
     How to load an assoc. array (Tony Reeves)
     Re: How to load an assoc. array (Michael Budash)
     Re: How to load an assoc. array (brian d foy)
     Re: http socket programming <bowlin@sirius.com>
     Re: Iteration within a foreach loop <bowlin@sirius.com>
     Re: last modification date on files (brian d foy)
     Re: last modification date on files (brian d foy)
     Re: last modification date on files <rjk@coos.dartmouth.edu>
     Re: last modification date on files <adavid@netinfo.com.au>
     Re: NEED:  Fast, Fast string trim() <matkin@Owein.DoCS.UU.SE>
     Re: No Flock! -- Now What? <VikR@aol.com>
     Re: Number of items in an array (brian d foy)
     Ordering input <woodya@ibm.net>
     Re: Ordering input (brian d foy)
     Re: Ordering input <bowlin@sirius.com>
     Q: limiting the input array size (Jim Britain)
     Re: Q: limiting the input array size (Jim Britain)
     Re: Q: limiting the input array size (Jim Britain)
     Re: Q: limiting the input array size (brian d foy)
     Q: sorting hash by category <xah@best.com>
     Re: Random access read/write possible in Perl? (Michael Budash)
     Re: running perl with cgi on a NT? <stephan.mankopf@rokd.de>
     Re: setting environment variable within perl script (perl -e "warn unpack 'u*','5<V%M=65L;$!C:7,N=6%B+F5D=0T*';")
     Re: setting environment variable within perl script <adavid@netinfo.com.au>
     Re: test (brian d foy)
     Re: Timeout, fork and exec. <bowlin@sirius.com>
     Re: What kind of machine wouldn't support FLOCK? <VikR@aol.com>
     Re: Which language pays most 17457 -- C++ vs. Java? <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
     Re: Workaround for FLOCK? <sbekman@iil.intel.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Dec 1997 01:42:24 -0800
From: Craig <rcd@kiwi.net>
Subject: <SELECT MULTIPLE >  Script only gives one value. Can you help?
Message-Id: <3498F000.CB9D5674@kiwi.net>

Example:
<SELECT MULTIPLE SIZE=2 NAME="name">
<OPTION>something
<OPTION>somethingelse
</SELECT>

If you have multiple values of a the SELECT tag in a form, the contents
get sent to the Perl script like this:

&name=something&name=somethingelse

In which case the first "name" gets over written and the final value of
"name" is "somethingelse".

The code I use is like this:
$name = $in->param('name');

How can I capture all values of "name"?? I would appreciate it if you
could help.



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

Date: 18 Dec 1997 08:06:00 GMT
From: philip@sgiinda.csc.cuhk.edu.hk (Philip Ling)
Subject: Changing passwd
Message-Id: <67alh8$kr@hpg30a.csc.cuhk.edu.hk>

Hi,

Is there a way for a non-root user to change other users' password ? 
If other users can pass the uid and existing password as parameters.
Of course, the script is in perl.

Thanks.


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

Date: Thu, 18 Dec 1997 05:03:45 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Changing passwd
Message-Id: <comdog-ya02408000R1812970503450001@news.panix.com>

In article <67alh8$kr@hpg30a.csc.cuhk.edu.hk>, philip@sgiinda.csc.cuhk.edu.hk (Philip Ling) wrote:

>Is there a way for a non-root user to change other users' password ? 

yes.

>If other users can pass the uid and existing password as parameters.
>Of course, the script is in perl.

if this is a shell account and you know the password, you can telnet
to the account and change it.  

depending on your system, you might be able to su to that user then
change the passwd (you might also have to pass the username to the
passwd command).

how you implement that is up to you, but don't limit yourself to Perl necessarily.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 18 Dec 1997 06:30:44 GMT
From: vf@cryogen.com (Fool )
Subject: Check file's attribute in WinNT ? How?
Message-Id: <3498c2af.50083651@news.silkera.net>

Hello :
I had installed the Perl for Win32 in my PC (OS : NT4.0 )
But I don't know can I use the 
parameter  ( -e : check if files exit  ,-f,-d. -T.........)
under NT to check the file's attribute ?Or I must use them in UNIX ?

 If I couldn't . How should I modify the function

  if(-d  $filename) {
   ...........
 in order to check the attribute of  file in NT ?

Thanks......


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

Date: Wed, 17 Dec 1997 23:19:32 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: Ray <rgoldber@uiuc.edu>
Subject: Re: getting correct web server headers
Message-Id: <3498CE84.F0ADF7DA@sirius.com>

Ray wrote:
> 
> I wrote a script to check the validity of the links in my bookmarks file.
> The main part of the code grabs the headers from a website but this does
> not appear to be working in all cases. When I call it with some sites,
> such as www.us.pressline.com it returns the 404 not found code.  [snip]

Servers that use virtual hosts *require* that you include a host header.
Try the following modification:

 print SOCKET "HEAD $file HTTP/1.0\nHost: $host\n\n";


HTH - Jim Bowlin


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

Date: Thu, 18 Dec 1997 02:36:32 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Dan Roberts <roberts_d@bms.nospam.com>
Subject: Re: Help Needed modifying a text file using perl
Message-Id: <3498D281.1804718A@coos.dartmouth.edu>

Dan Roberts wrote:
> 
> what I need to do is change only the very first line of the file from
> <wagon to something that would match the existing file name
> so for instance
> if the test file is currently called
> car1245.txt
> I would like to have the first line of the car1245.txt file read
> <car1245-wagon
> instead of it reading
> <wagon
> as it now does.

Took longer than I expected to come up with this command line
(and it's longer than I expected), but it works.

perl -pi -e 's/<(.*)/"<" . substr($ARGV, 0, (rindex($ARGV, ".") > 0 ? \
             rindex($ARGV, ".") : length($ARGV))) . "-$1"/e if $. == 1; \
             close(ARGV) if (eof);'

Replaces <whatever with <basename-whatever on the first line of the 
specified files.
Uses substr and rindex to get the basename so that $1 is not overwritten.
Works for filenames with no extension (i.e. 'foo', '.login').
Closes ARGV on eof so $. is reset for each file.

Chipmunk


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

Date: Thu, 18 Dec 1997 07:08:43 GMT
From: stephenc@granddesign.com (Stephen P. Clouse)
Subject: Re: How to invoke the Unix VI cmd from perl script to move around in a file.
Message-Id: <3499ca71.22039631@news.kc.net>


Hash: SHA1

On Wed, 17 Dec 1997 23:31:51 -0800 in message <<3498D167.666F@us.oracle.com>
comp.lang.perl.misc>, Ananth Makaram <amakaram@us.oracle.com> wrote:

>    However, instead of just spewing the contents of the
>file into the viewing box, I would like to invoke the
>unix VI command to the file.  This would allow to
>move  around the file (while inside the box) searching 
>for certain keywords.  NOTE>  i dont wish to have a 
>separate Search/replace/search engine functionality.

So what I'm reading is you want the end user to be able to use the TEXTAREA as
an interface to vi.  Very wishful thinking...unfortunately, it's also impossible
to do.

You have to remember that HTTP is a stateless protocol...it connects, downloads
the information necessary to display the page, and disconnects.  It doesn't sit
around and wait for input, and even if it did it's not yet sophisticated enough
to pass that input interactively to a program running on the server.  There's
probably a number of security issues involved in this as well.

To accomplish what you're describing would require some kind of weird Java
thing, and well, Java's not in my personal area of expertise.  (Actually, I'm no
Perl god either :)  Or give the person a telnet account.  This just can't be
done from a run-of-the-mill browser.

Of course, if I didn't correctly get the gist of what you were asking then feel
free to ignore this post.

- -- 
Stephen P. Clouse
stephenc@granddesign.com -- steve@warpcore.org -- UIN 135012
Grand Design, Inc. (http://www.granddesign.com) -- Quality Business Web Design
The Warp Core (http://www.warpcore.org) -- The Web's Premier Descent Site
PGP-Encrypted E-Mail Preferred (Key available at www.granddesign.com/~stephenc)
Fight Spam/UCE -- http://www.cauce.org


Version: PGP for Business Security 5.5

iQA/AwUBNJjL9WOLD55Fj/ZkEQKMEQCgt9dES/s38N/rW/ghpzcCaxqH9hIAoKhm
kWsIBrdfyQpAXe3ktUUqzj7x
=PaiJ
-----END PGP SIGNATURE-----



This article was posted from <A HREF="http://www.slurp.net/">Slurp Net</A>.


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

Date: Thu, 18 Dec 1997 04:17:57 GMT
From: n7sf@usa.net (Tony Reeves)
Subject: How to load an assoc. array
Message-Id: <3498a2bf.3172961@news.goodnet.com>

I thought I knew how to do this, but I am stuck..

I have a flat file that I want to load into an associative array. 
I tryed this:

open(LIST, "bus1loc") or die "Can't get the flat file\n";
while(<LIST>) {
($userid, $org) = split(":", $_);
%assocarry = ( $userid, $org,);
}
close(LIST);

yet this does not work.  What is the method to load an assoc arry?
I've looked in the books, can't find it..
please help



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

Date: Wed, 17 Dec 1997 23:39:09 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: How to load an assoc. array
Message-Id: <mbudash-1712972339090001@d180.pm12.sonic.net>

In article <3498a2bf.3172961@news.goodnet.com>, n7sf@usa.net (Tony Reeves)
wrote:

>> I thought I knew how to do this, but I am stuck..
>> 
>> I have a flat file that I want to load into an associative array. 
>> I tryed this:
>> 
>> open(LIST, "bus1loc") or die "Can't get the flat file\n";
>> while(<LIST>) {
>> ($userid, $org) = split(":", $_);
>> %assocarry = ( $userid, $org,);
>> }
>> close(LIST);

change this:

  %assocarry = ( $userid, $org,);

to this:

  $assocarry{'$userid'} = $org;

'course, if you have more than one occurance of the same $userid, you'll
keep redefining that %assocarry element each time, but that's your
problem. what would you _want_ to do with the data?

also, i've never tried using:

  split(":", $_);

i would usually use:

  split(/:/);  # $_ used by default

hope this helps,
michael

-- 
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736


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

Date: Thu, 18 Dec 1997 04:33:31 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to load an assoc. array
Message-Id: <comdog-ya02408000R1812970433310001@news.panix.com>

In article <mbudash-1712972339090001@d180.pm12.sonic.net>, mbudash@sonic.net (Michael Budash) wrote:

>change this:
>
>  %assocarry = ( $userid, $org,);
>
>to this:
>
>  $assocarry{'$userid'} = $org;

i think that just makes the problem worse (hint:  test it and see
what happens, which you should be doing for any code that you post).

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 18 Dec 1997 00:01:13 -0800
From: Jim Bowlin <bowlin@sirius.com>
Subject: Re: http socket programming
Message-Id: <3498D849.DA23538E@sirius.com>

> Most likely: HTTP is a stateless protocol, meaning that for every
> request, it creates a new connection. The server on the other side
> probably has no clue what you're still trying to do on a socket that
> it views as having been dealt with :)

Actually HTTP/1.1 allows Connection: Keep-Alive to use one connection
for multiple requests.  The latest browsers (and latest Apache) now
support this protocol.


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

Date: Wed, 17 Dec 1997 23:54:15 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: paul@pmcg.com
Subject: Re: Iteration within a foreach loop
Message-Id: <3498D6A7.F1292E9E@sirius.com>

I'm clueless here Paul.  What is the question?

Paul wrote:
> 
>         Here's the snippet (we will be checking our named.boot files):
> 
>         foreach $domname (sort keys %prifor) {
>                 @buf = split /\n/, `whois $domname`;
> 
>                 foreach ( @buf ) {
>                         if ( /$match_this_puppy/ ) {
>                                 <ITERATE TWO MORE LINES HERE>;
>                                 ...do somethig way cool here;
>                         }
>                 }
>         }
> 
>         Any clues for the clueless?


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

Date: Thu, 18 Dec 1997 00:43:13 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: last modification date on files
Message-Id: <comdog-ya02408000R1812970043130001@news.panix.com>

In article <67a04f$ddt$1@news.stlnet.com>, psullivan@stlnet.com (psullivan) wrote:

>I am trying to find out the last time a file was modified on unix, and so I 
>figure that i'd just use the -M file tester built into perl. But this gives me 
>time in days since last modification, 

remember the -M and friends returns a time relative to the start of
the script.  perhaps you want to use stat()?

>and so i was wondering how I can convert 
>this to a date field (mm/dd/yy), or if you know of another way to find 
>this out. Thanks.


there are lots of nifty Date and Time modules on CPAN [1] if localtime()
is just not what floats your boat.

good luck!

>P.S. Please email the response as well as posting to the newsgroup. Thanks.

okay... but your mail better not bounce ;)

[1]
Comprehensive Perl Archive Network
find several sites through
<URL:http://www.perl.com>

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 18 Dec 1997 00:48:37 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: last modification date on files
Message-Id: <comdog-ya02408000R1812970048370001@news.panix.com>

In article <349893DE.F57CFF20@coos.dartmouth.edu>, rjk@coos.dartmouth.edu wrote:


>-M actually gives you the age of the file in days from the epoch, not the number
>of days since the last modification.

maybe you meant to say that a bit differently? (see the Camel p. 87) :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 18 Dec 1997 01:59:55 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: brian d foy <comdog@computerdog.com>
Subject: Re: last modification date on files
Message-Id: <3498C9EB.2BC7E468@coos.dartmouth.edu>

brian d foy wrote:
> 
> In article <349893DE.F57CFF20@coos.dartmouth.edu>, rjk@coos.dartmouth.edu wrote:
> 
> >-M actually gives you the age of the file in days from the epoch, not the number
> >of days since the last modification.
> 
> maybe you meant to say that a bit differently? (see the Camel p. 87) :)

I left my Camel at work (drove home in the car instead) so I was going
by the manpages:

    -M  Age of file in days when script started.

Which I read the wrong way.  Actually, I don't know how I came up
with that interpretation.  Weird.

-M gives you the number of days between when the file was last modified and
when the script was started.

Sorry about the confusion.

Chipmunk


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

Date: Thu, 18 Dec 1997 20:59:27 +1100
From: Anthony David <adavid@netinfo.com.au>
Subject: Re: last modification date on files
Message-Id: <3498F3FF.7670D17A@netinfo.com.au>



Chipmunk wrote:

> I left my Camel at work (drove home in the car instead) so I was going
> by the manpages:
>

That's why I have one at home and wherever I'm working  :-).

--
Anthony David                      |     Opinions expressed ARE
Anthony David & Associates |     those of my employer




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

Date: 18 Dec 1997 09:39:51 +0100
From: Matz Kindahl <matkin@Owein.DoCS.UU.SE>
Subject: Re: NEED:  Fast, Fast string trim()
Message-Id: <yf5zplzujs8.fsf@Owein.DoCS.UU.SE>

tony@crux.blackstar.co.uk (Tony Bowden) writes:

> Re: removing 'unwanted' space:
> 
> Summary of options to date:
> 
> 1) $_ = join(" ", /\S+/g);
> 2) $_ = join(" ", /\S+(?: \S+)*/g); #optimized for single spaces between words
> 3) $_ = join(" ", split);
> 4) $_ = " $_ "; tr/ \n\r\t/ /s; substr($_,0,1) = substr($_,-1,1) = "";
> 
> For short strings:
>   Benchmark: timing 50000 iterations of Exp1, Exp2, Exp3, Exp4...
>       Exp1:  2 secs ( 2.23 usr  0.00 sys =  2.23 cpu)
>       Exp2:  2 secs ( 2.22 usr  0.00 sys =  2.22 cpu)
>       Exp3:  0 secs ( 1.82 usr  0.00 sys =  1.82 cpu)
>       Exp4:  0 secs ( 1.72 usr  0.00 sys =  1.72 cpu)
> 
> For long strings:
>   Benchmark: timing 5000 iterations of Exp1, Exp2, Exp3, Exp4...
>       Exp1: 12 secs (10.92 usr  0.00 sys = 10.92 cpu)
>       Exp2: 11 secs (10.91 usr  0.00 sys = 10.91 cpu)
>       Exp3:  9 secs ( 8.84 usr  0.00 sys =  8.84 cpu)
>       Exp4:  1 secs ( 0.96 usr  0.00 sys =  0.96 cpu)
> 
> So option 4 is better by quite a long shot...
> 
> Any advance?

Yup!

I tried the following version; seems to be ~25% faster than my
previous version.

5) $_ = " $_ "; tr/ \n\r\t/ /s; $_ = substr($_,1,-1)

-- 
Mats Kindahl                    ! matkin@docs.uu.se
Department of Computer Systems  ! 
Box 325                         ! Tel  +46 18 18 10 66
S-751 05 Uppsala                ! Fax  +46 18 55 02 25
SWEDEN                          ! URL  http://www.docs.uu.se/~matkin/

PGP Key fingerprint =  92 5C FC 39 32 A8 7F 91  01 56 A0 D3 9C A9 6C 81 
PGP key available under finger matkin@kay.docs.uu.se

"People do strange things when you give them money."
        -- Simple Minds


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

Date: Wed, 17 Dec 1997 23:57:45 -0800
From: Vik Rubenfeld <VikR@aol.com>
To: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: No Flock! -- Now What?
Message-Id: <3498D776.FE501246@aol.com>

Mark S. Reibert wrote:

> BTW, what systems are you dealing with?

My software, PowerTab, can produce a PERL script which is used as a CGI. Since
all kinds of different folks use PowerTab, the PERL script needs to be able to
run almost anywhere. We've found that almost any system has been able to run
our PERl script -- until we added a call to FLOCK for use in cases where
multiple people were running the CGI at the same time, and trying to access
the same files. 

If FLOCK isn't available, what's the next best thing? There must be some way
to handle this on every system -- no?

- Vik


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

Date: Thu, 18 Dec 1997 00:39:35 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Number of items in an array
Message-Id: <comdog-ya02408000R1812970039350001@news.panix.com>

In article <01bd0b5f$45b7bd30$79706420@akis>, "Christopher Lambrou" <alambro@ibm.net> wrote:

>$items = $#array; # to get number of items in array @array

unless you've fiddled with something which i won't mention, that
will give you the index of the last element of the array, which to
one-based counting schemes, is one less than the number of elements
in the array.

some alternatives:

* use scalar()

   $number_of_elements = scalar @array;

* add one to $#array

   $number_of_elements = $#array + 1;

* use @array in a scalar context (ick! i think this leads to lots
of coding errors, so no example, although it works).

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 17 Dec 1997 23:47:43 -0700
From: Anthony Woody <woodya@ibm.net>
Subject: Ordering input
Message-Id: <3498C70F.544AC847@ibm.net>

I have a problem, I want to take from a file, lines of input consisting
of name/ID-number pairs and reverse each line so the ID precedes the
name and the entries are sorted by the last 4 digits of the ID.

If the input file looked like this:

Fred Jones 34315647
Mary Smith 123123123
Herb Blackwell 934561862
Anne Wilson 213243546

The output would look like this:

934561862 Herb Blackwell
123123123 Mary Smith
213243645 Anne Wilson
343415647 Fred Jones

I can get the Name and ID number separated and reversed, but I can't
figure out how to sort the ID numbers by the last 4 digits.

Any suggestions would be greatly appreciated...



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

Date: Thu, 18 Dec 1997 02:20:43 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Ordering input
Message-Id: <comdog-ya02408000R1812970220430001@news.panix.com>

In article <3498C70F.544AC847@ibm.net>, Anthony Woody <woodya@ibm.net> wrote:

>I have a problem, I want to take from a file, lines of input consisting
>of name/ID-number pairs and reverse each line so the ID precedes the
>name and the entries are sorted by the last 4 digits of the ID.

>Fred Jones 34315647
>Mary Smith 123123123
>Herb Blackwell 934561862
>Anne Wilson 213243546

>The output would look like this:

>343415647 Fred Jones

   this is a different ID number than the input.  if all the ID
   numbers are the same number of digits, then you can do a
   normal numerical sort (well, not if leading zeroes are
   allowed).

>I can get the Name and ID number separated and reversed, but I can't
>figure out how to sort the ID numbers by the last 4 digits.

here's an example of sorting by the last four digits given that
the ID numbers may be of different lengths (preventing a vanilla
numerical sort):

   #!/usr/bin/perl -w
   
   %hash = ( 34315647 => 'Fred Jones',
            123123123 => 'Mary Smith' ,
            934561862 => 'Herb Blackwell' ,
            213243546 => 'Anne Wilson'
           );
           
   foreach( sort _by_last_four_digits keys %hash )
      {
      printf "%9d %s\n", $_, $hash{$_};
      }
   
   sub _by_last_four_digits
      {
      my ($a4, $b4);
   
      #we get $a and $b for free
      ($a4) = ($a =~ m/(\d\d\d\d)$/);
      ($b4) = ($b =~ m/(\d\d\d\d)$/);
   
      $a4 <=> $b4;   
      }

   __END__

   934561862 Herb Blackwell
   123123123 Mary Smith
   213243546 Anne Wilson
    34315647 Fred Jones

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 17 Dec 1997 23:49:09 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: Anthony Woody <woodya@ibm.net>
Subject: Re: Ordering input
Message-Id: <3498D575.BDC41428@sirius.com>

Anthony Woody wrote:
> 
> I have a problem, I want to take from a file, lines of input consisting
> of name/ID-number pairs and reverse each line so the ID precedes the
> name and the entries are sorted by the last 4 digits of the ID.

Try:

while (<DATA>) {
    my ($nam1,$nam2,$num) = split(/\s+/);
    $num && $num =~ /(\d{4})$/ or next;
    $hash{$1} = "$num $nam1 $nam2";
}

foreach ( sort { $a <=> $b } keys %hash) {
    print "$hash{$_}\n";
}

__DATA__

Fred Jones 34315647
Mary Smith 123123123
Herb Blackwell 934561862
Anne Wilson 213243546


HTH - Jim Bowlin


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

Date: Thu, 18 Dec 1997 07:33:57 GMT
From: jbritain@home.com (Jim Britain)
Subject: Q: limiting the input array size
Message-Id: <3498cf05.8821592@news>

In CGI programming, a common input method is:

 local (*FORM_DATA) = @_;

However, malicious input, may not necessarily agree with what is
stated in CONTENT_LENGTH variable -- and even when reading that value
-- it comes after the array buffer is built.

What is a good or reasonable method of setting a limit to the storage
area allocated? (It has been demonstrated to me, that on some systems,
it is possible to do a good ole core dumping overrun on the input).

Quite obviously, I can come up with a solid number for max value, but
what's a good way in PERL implementing that restriction on the input?


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

Date: Thu, 18 Dec 1997 08:07:29 GMT
From: jbritain@home.com (Jim Britain)
Subject: Re: Q: limiting the input array size
Message-Id: <3498d77e.10991830@news>

I guess I answer my own question.

This construct:  local (*FORM_DATA) = @_;
only sets the local address of the array accessed by the handle
*FORM_DATA

The actual read into the array is performed by (surprise!) a
subsequent READ function, of all things:

    read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});

Gee whiz Mr. Wizard -- all I have to do is test the value of
$ENV{'CONTENT_LENGTH'}. 

Now that, I can figure out..

5 languages is too many to use in one day.

On Thu, 18 Dec 1997 07:33:57 GMT, jbritain@home.com (Jim Britain)
wrote:

>In CGI programming, a common input method is:
>
> local (*FORM_DATA) = @_;
>
>However, malicious input, may not necessarily agree with what is
>stated in CONTENT_LENGTH variable -- and even when reading that value
>-- it comes after the array buffer is built.
>
>What is a good or reasonable method of setting a limit to the storage
>area allocated? (It has been demonstrated to me, that on some systems,
>it is possible to do a good ole core dumping overrun on the input).
>
>Quite obviously, I can come up with a solid number for max value, but
>what's a good way in PERL implementing that restriction on the input?



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

Date: Thu, 18 Dec 1997 09:23:48 GMT
From: jbritain@home.com (Jim Britain)
Subject: Re: Q: limiting the input array size
Message-Id: <3498e8f9.15466568@news>

On Thu, 18 Dec 1997 03:08:55 -0500, comdog@computerdog.com (brian d
foy) wrote:

>In article <3498cf05.8821592@news>, jbritain@cts.com wrote:
>
>>In CGI programming, a common input method is:
>>
>> local (*FORM_DATA) = @_;
>
>using modules such as CGI.pm will shield you from such concerns :)
>
>>However, malicious input, may not necessarily agree with what is
>>stated in CONTENT_LENGTH variable -- and even when reading that value
>>-- it comes after the array buffer is built.
>
>i would expect a good CGI program to only read the number of bytes
>specified in CONTENT_LENGTH.  however, i guess you could make the server
>wait by not sending as many bytes as you said you were going to, hence
>creating a denial of service style attack.  oy - i don't think
>CGI.pm could recover from such a thing, but i hestitate to test it.
>
>>What is a good or reasonable method of setting a limit to the storage
>>area allocated? (It has been demonstrated to me, that on some systems,
>>it is possible to do a good ole core dumping overrun on the input).
>
>this happens with Perl scripts?  i'd be interested in the details of
>that demonstration. :)

It was last year, after I'd had a whole 3 weeks of PERL experience, I
used a while (<>) -- as input.  Operating system was Solaris 2.5.1,
PERL 5.0.1, and I'm not sure what server software they installed my
script on..  But it bombed when input went over something like 32k (at
least the customer said so)  it was on a demo of a prototype script
installation.

Since then, my style, and resources have improved (books and borrowed
code), but I don't spend enough time doing PERL -- most of my time is
spent with systems administration, and cross platform Bourne scripts.
I've been doing some C, but no C++ since school.  Plus I'm having to
learn SQL, and Xwindows on the fly.  I'm ready to quit work, and
concentrate on one language for a while..  Or maybe two..

I think PERL could easily qualify as two langages..



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

Date: Thu, 18 Dec 1997 03:08:55 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Q: limiting the input array size
Message-Id: <comdog-ya02408000R1812970308550001@news.panix.com>

In article <3498cf05.8821592@news>, jbritain@cts.com wrote:

>In CGI programming, a common input method is:
>
> local (*FORM_DATA) = @_;

using modules such as CGI.pm will shield you from such concerns :)

>However, malicious input, may not necessarily agree with what is
>stated in CONTENT_LENGTH variable -- and even when reading that value
>-- it comes after the array buffer is built.

i would expect a good CGI program to only read the number of bytes
specified in CONTENT_LENGTH.  however, i guess you could make the server
wait by not sending as many bytes as you said you were going to, hence
creating a denial of service style attack.  oy - i don't think
CGI.pm could recover from such a thing, but i hestitate to test it.

>What is a good or reasonable method of setting a limit to the storage
>area allocated? (It has been demonstrated to me, that on some systems,
>it is possible to do a good ole core dumping overrun on the input).

this happens with Perl scripts?  i'd be interested in the details of
that demonstration. :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 18 Dec 1997 01:59:40 -0800
From: "Xah" <xah@best.com>
Subject: Q: sorting hash by category
Message-Id: <67aruj$7lv$1@nntp1.ba.best.com>

Suppose I have a hash like this

# about 1000 pairs.
%hh = (
'wallpaperSmall15.gif' => 1,
'mandellaIcon.gif' => 75,
'astroidTrammel.fig' => 1,
'parabolaReflector.gif' => 6,
'nephroidByEnvOfCircleProof.fig' => 1,
'mathGraphicsGallery.html' => 17,
'invParallel4.gif' => 6,
'cardioidParallelTangents.gif' => 7,
'pedalCosQuetzal.gif' => 6,
'nebula_HeartIcon.gif' => 6,
'LimaconGG2_2.gif' => 4,
'involuteCircleRainbow.gif' => 1,
'deltoidTangent1.gsp' => 2,
'newtstalks1.html' => 1,
'ellipseGenPointwise.mov' => 1
);

I want to sort files into categories by extensions then sort them by count
value. The result should print like this

75	mandellaIcon.gif
7	cardioidParallelTangents.gif
6	pedalCosQuetzal.gif
6	parabolaReflector.gif
6	nebula_HeartIcon.gif
6	invParallel4.gif
4	LimaconGG2_2.gif
1	wallpaperSmall15.gif
1	involuteCircleRainbow.gif

1	astroidTrammel.fig
1	nephroidByEnvOfCircleProof.fig

2	deltoidTangent1.gsp

17	mathGraphicsGallery.html
1	newtstalks1.html

1	ellipseGenPointwise.mov


What's a *GOOD* way to do it? A guide will do me good. Thanks. 

(this script is intended to calc stats of my web log. Yes, I knew about
Analog and the like.)

 Xah, xah@best.com
 http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
 "Perl my ass" (there are more than one way to express love)



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

Date: Wed, 17 Dec 1997 23:28:45 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: Random access read/write possible in Perl?
Message-Id: <mbudash-1712972328460001@d180.pm12.sonic.net>

In article <678njm$i0g@bgtnsc01.worldnet.att.net>, hagani@worldnet.att.net
wrote:

>> Is there any way to perform a RANDOM ACCESS read or write in a perl
>> script?  I know how to do sequential reads/writes, but they are far
>> less efficient in many cases (eg., i want to read only the last XX
>> bytes of a file)....
>> 

see perl functions seek() and read().

-- 
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736


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

Date: Thu, 18 Dec 1997 11:09:35 +0100
From: Stephan Mankopf <stephan.mankopf@rokd.de>
Subject: Re: running perl with cgi on a NT?
Message-Id: <3498F65F.73CA@rokd.de>

Calle ]sman wrote:
> 
> I wonder if someone want to share experience with running
> some cgi-scripts on a NT-webserver.
> 
> What differs from running it on a unix?
> what do one has to think about regarding security?
> 
> is there some neat webserver one can download that I can run on W95/NT so I
> can try out the stuff at home? (the computer
> shall not be connected to the net, I just want to see that the cgi-scripts
> works as supposed to)
> 
> what things exist on NT instead of sendmail?
> 
> /Calle
> 
> **************************************************************************
> *         *         My homepage about the author Tom Holt:               *
> *        /_\        http://www.mdstud.chalmers.se/~md4calle/holt/        *
> *     { ~._.~ }                                                          *
> *      (  Y  )      other things like OnLine Guitar Archive linkpage     *
> *     ( )~*~( )     and heaps of musiclinks can be found at              *
> *     (__)-(__)     http://www.mdstud.chalmers.se/~md4calle/             *
> **************************************************************************
We use Microsoft Internet Information Server 2.0 or 3.0 with
Perl5 for Win32 (FAQ at
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html)
in our Intranet (IIS not in the WEB!). You could download Perl5
for Win32 from ftp://gate.rokd.de/pub/swhup/ [pw32i306.exe].
As an SMTP-Gateway you could use "blat1.5" Part of NT4.0
Resource-Kit (http://gepasi.dbs.aber.ac.uk/softw/Blat.html)
Greetings stev
-- 
Stephan Mankopf       
Phone     ++49 (521) 1457-308 (business)
FAX       ++49 (521) 1457-180 (business)
e-Mail    stephan.mankopf@rokd.de
Internet: http://www.rokd.de/soha/


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

Date: Thu, 18 Dec 1997 09:03:55 GMT
From: no@non.org (perl -e "warn unpack 'u*','5<V%M=65L;$!C:7,N=6%B+F5D=0T*';")
Subject: Re: setting environment variable within perl script
Message-Id: <882434883.4098@207.53.4.34>


In article <Pine.GSO.3.96.971213142337.23745G-100000@user2.teleport.com> on Sat, 13 Dec 1997 14:24:15 -0800,
 Tom Phoenix <rootbeer@teleport.com> wrote:

> On Sat, 13 Dec 1997, brian d foy wrote:

>> In article <Pine.GSO.3.96.971212184841.14102U-100000@user2.teleport.com>,
>> Tom Phoenix <rootbeer@teleport.com> wrote:

>>> Why aren't you using a module? 

>>  in all fairness, the PGP module on CPAN is an alpha module.  it gave me
>> so many problems that i wrote my own :)

> So you, at least, _are_ using a module. :-)  When will you be uploading it
> to CPAN? :-)


There are a couple reasons why I don't publish my modules:

Chiefly, I don't have the time to answer questions about them.
I have written software for 30+ years and if you distribute it
you have a responsibility to support it and I know from
experience that goes way beyond the rare correction of bugs.  ;-)

Secondly, many dependencies have grown over the years between
my modules that would necessitate the issuance of many more than
I would want to support.  For example, for a spam detection/
notification piece I have written, I developed quite useful
Net::Contact and Net::WHOIS object modules which modules would 
also require that I distribute my Mail::Client, my Net::Client,
my Net::LocalHost, my Net::Failsafe and my Person::Object modules
some of which in turn use my Mail::Message, my Document::Memo,
my MIME::Object, my File::Object and my Info::URL modules.
Several of these overlap the CPAN set but suit my purposes better
than the existing CPAN modules--  for example, Net::Client 
supports a site failure memory feature.  So for some of us to 
publish a particularly useful module, we might need to support
our own CPAN.  ;)


Sam, I am
--
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ::                                                                      ::
  ::                       THE PRINCIPLE OF FREEDOM                       ::
  ::                                                                      ::
  ::     I am free to do what I will,  |  <-- The Basic Notion            ::
  ::   except I violate your freedom,  |  <-- The Restraint Requirement   ::
  ::       unless you violate theirs.  |  <-- The Intervention Clause     ::
  ::                                                                      ::
  ::::rl3s::::::::::::::::::::::::freedom.sig:::::::::::::::::::7/4/1993::::



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

Date: Thu, 18 Dec 1997 21:22:14 +1100
From: Anthony David <adavid@netinfo.com.au>
Subject: Re: setting environment variable within perl script
Message-Id: <3498F956.7D4FB665@netinfo.com.au>



 perl -e warn unpack 'u*','5

^^^^ he said :-)

> >> In article <Pine.GSO.3.96.971212184841.14102U-100000@user2.teleport.com>,
> >> Tom Phoenix <rootbeer@teleport.com> wrote:
>
> >>> Why aren't you using a module?
>
> >>  in all fairness, the PGP module on CPAN is an alpha module.  it gave me
> >> so many problems that i wrote my own :)
>
> > So you, at least, _are_ using a module. :-)  When will you be uploading it
> > to CPAN? :-)
>
> There are a couple reasons why I don't publish my modules:
>
> Chiefly, I don't have the time to answer questions about them.
> I have written software for 30+ years and if you distribute it
> you have a responsibility to support it and I know from
> experience that goes way beyond the rare correction of bugs.  ;-)
>

Generally, unless you make suggestions/contributions to the module authors who have taken that responsibility
themselves.

> Secondly, many dependencies have grown over the years between
> my modules that would necessitate the issuance of many more than
> I would want to support.  For example, for a spam detection/
> notification piece I have written, I developed quite useful
> Net::Contact and Net::WHOIS object modules which modules would
> <snip dependant modules>

I'm sure there should be some "perls" in there that can be extracted to bolsterthese deficiencies you speak of.

My *personal* approach is to make an effort, however small, to offer gratitude
for the efforts of so many people in making my job a lot easier and a lot more
enjoyable.

It sounds like you are a very thorough person, however time and
other priorities dictate that module support is not possible. Perhaps your PGP
module efforts could be given to the author of the current CPAN PGP and let
him pick the 'perls' out for himself.

--
Anthony David                      |     Opinions expressed ARE
Anthony David & Associates |     those of my employer




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

Date: Thu, 18 Dec 1997 00:49:19 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: test
Message-Id: <comdog-ya02408000R1812970049190001@news.panix.com>

In article <679t5n$pcg$2@pnn.projo.com>, jgesuald@projo.com (John A. Gesualdi) wrote:

>test only

that's a novel way to get the FAQ :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 17 Dec 1997 23:25:21 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: Christopher Lambrou <alambro@ibm.net>
Subject: Re: Timeout, fork and exec.
Message-Id: <3498CFE1.BF3371F2@sirius.com>

Christopher Lambrou wrote:
> 
> I have a Perl script that takes a long time to finish (it imports an 8meg
> file into a mySQL database) and it always produces a "Request Timeout" HTTP
> error. Is there a way to bypass the HTTP timeout error?  [snip]

This is server dependent.  Some tricks to try are:

1) send the Content-type header line ASAP.
2) if this fails, check out the techniques in "CGI Programming on the World
Wide Web" by Shishir Gundavaram (O'Reilly), pp 308 - 310.

HTH - Jim Bowlin


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

Date: Wed, 17 Dec 1997 23:59:44 -0800
From: Vik Rubenfeld <VikR@aol.com>
To: Steve <syarbrou@ais.net>
Subject: Re: What kind of machine wouldn't support FLOCK?
Message-Id: <3498D7EC.E118520F@aol.com>

Steve wrote:
> 
> I have done extensive testing of flock on unix systems anyways and
> several systems have it, but only Linux truely seems to support it.
> All the other flavors of UNIX accept the command but do not work.

So if you have a PERL script running as a CGI, and multiple people run it
simultaneously, is there no way to keep its data files from being corrupted?

- Vik


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

Date: 18 Dec 1997 09:52:31 +0100
From: Klaus-Georg Adams <Klaus-Georg.Adams@chemie.uni-karlsruhe.de>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <qmbtyfc9tc.fsf@chemie.uni-karlsruhe.de>

tadmc@metronet.com (Tad McClellan) writes:

> 
> Mark Framness (framness@EMIRATES.NET.AE) wrote:
> : In message <34958D16.190C@gsg.eds.com> - "Shmuel (Seymour J.) Metz"
> : <nospam@gsg.eds.com>Mon, 15 Dec 1997 12:03:34 -0800 writes:
> : #>
> 
> : #>> C provides the needed primitives to do anything you need.  
> : #>
> : #>You got this wrong; C does not have the needed primitives to handle
> : #>sets, do string matching, do record-oriented I/O, etc., except in the
> : #>trivial sense that anything can be simultated on anything else.
> 
> : What do you mean sets?  As in the mathematical sense?  String matching?  Huh? 
> : what do strcmp, strstr etc do?
>           ^^^^^^  ^^^^^^
> 
> Those are not *primitives* (ie. built-in to the language).
> 
> Those are library calls (ie. add-ons to the language).
> 
> You won't find 'strcmp' in a C compiler's grammar.

Which is of course completely irrelevant. They are part of the
language definition (as in ANSI Standard).

-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie II                           Tel: 0721 608 3485
Uni Karlsruhe
-------------------------------------------------------------------------


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

Date: Thu, 18 Dec 1997 10:38:53 +0200
From: Bekman Stanislav <sbekman@iil.intel.com>
To: VikR@aol.com
Subject: Re: Workaround for FLOCK?
Message-Id: <3498E11D.36A6@iil.intel.com>

Vik Rubenfeld wrote:
> 
> I've got a machine that doesn't support FLOCK. (Error message "# The flock()
> function is unimplemented.") I'd rather not tell my client to update his PERL
> installation. Is there a workaround I can use instead of FLOCK? Also, is there
> a way to test for the presence of FLOCK, and use it if it is available? Thanks
> in advance to all for any info.
 
If you can't use lockf() (flock() emulation - read perl docs, I think
there is some module which does it... never tried it)
try my file-lib.pl
to create/release external lock  - works for web too!
See
http://www.eprotect.com/stas/TULARC/works/dbmanager/file-lib.pl
from http://www.eprotect.com/stas/TULARC/works/dbmanager/

______________________________________________________________________
Stas Bekman     mailto:sbekman@iil.intel.com [just another webmaster]
Linux Installation Party [Technion] http://instaparty.israel.eu.org/
Home Page:      http://www.eprotect.com/stas
A must visit: 	http://www.eprotect.com/stas/TULARC (Java,CGI,PC,Linux)
Linux-il Home:  http://www.linux.org.il/


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 1497
**************************************

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