[7100] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 724 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 12 05:17:20 1997

Date: Sat, 12 Jul 97 01:00:53 -0700
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, 12 Jul 1997     Volume: 8 Number: 724

Today's topics:
     "bad name" help needed <bfc@porte.com>
     Re: $ENV{'QUERY_STRING"} problem <sanford@halcyon.com>
     'use strict' with CGI.pm (Bernard Cosell)
     Re: Best idiom for defaulting, getting & untainting an  (M.J.T. Guy)
     Re: Checking for valid Email... (Even Holen)
     CPAN help (Will Linden)
     Re: eof() && sockets? <tex@collegenet.com>
     Re: Exception package? <wiese@datatools.com>
     foreach array indices <erick@servtech.com>
     Re: Foreach with lists of arrays (Jean-Damien Durand)
     Re: Foreach with lists of arrays (Jonathan King)
     Re: Global Vars : Why would I want to use "use strict" <cs@zip.com.au>
     Re: Help me to find my loose change !!! <deforres@acs.ucalgary.ca>
     Help needed with Perl on IIS Server <wmunroe@bulldog.ca>
     Re: Help! Need to run a script! (Tung-chiang Yang)
     HELP: 'grepping' large files taking TOO LONG <mark@uunet.ca>
     Re: HELP: force a <CR> in DOS <tex@collegenet.com>
     How do I lock a file in MacPerl? (Jeff Schneider)
     Re: How to substract a uniq integer from a ASCI string (John L. Allen)
     IRC Program in Perl? <Me@myisp.net>
     monitor web page, How? <266443@emc.fedex.com>
     Need Info On Using PERL.DLL <rbattepa@qualcomm.com>
     Re: Newbie Array pass by reference question (Andrew M. Langmead)
     OOP question <jpm@iti-oh.com>
     open file and read part of host address to block entire <guitarweb@hotmail.com>
     OraPerl - oracle database objects ? rahuljm@hotmail.com
     Re: Output to a file (David Zeng)
     Re: Password program.... <will@cs.ucr.edu>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 11 Jul 1997 22:23:23 -0500
From: Brian Clare <bfc@porte.com>
Subject: "bad name" help needed
Message-Id: <33C6F8AB.4C43C73D@porte.com>

Warning!! Newbie in trouble...

Can anyone tell me where I'm going wrong with the statement at the
bottom?  I just don't understand why I'm getting the bad name diag
message when this runs.  I get the message regarding the line containing
'cat' (line 4).   

>From the perldiag page...

Bad name after %s::
           (F) You started to name a symbol by using a package
           prefix, and then didn't finish the symbol.  In
           particular, you can't interpolate outside of quotes,
           so

               $var = 'myvar';
               $sym = mypack::$var;

           is not the same as

               $var = 'myvar';
               $sym = "mypack::$var";

How am I naming a "symbol" incorrectly?

Sure appreciate any pointers.


 print       

        $s->start_form(-action=>"bfc_update.cgi?section=2"),
        "\n<LEFT>",
        "\nCategory<BR>",
       
$s->popup_menu(-name=>'cat',-values=>,['Porte','Personal','Film',
        'Convergence','Misc.'], -default=>$var20)"<BR><BR>",
        "First Name<BR>",
        $s->textfield(-name=>'f_nam',-default=>$var23,-size=>30),"<BR>",
        "\nLast Name<BR>",
        $s->textfield(-name=>'l_nam',-default=>$var24,-size=>30),"<BR>",
        "\nCompany<BR>",
        $s->textfield(-name=>'comp',-default=>$var22,-size=>30),"<BR>",
        "\nAddress<BR>",
        $s->textfield(-name=>'addr',-default=>$var32,-size=>30,),"<BR>",
        "\nCity<BR>",
        $s->textfield(-name=>'cty',-default=>$var19,-size=>30,),"<BR>",
        "\nState / Province<BR>",
        $s->textfield(-name=>'st',-default=>$var21,-size=>30,),"<BR>",
        "\nZip<BR>",
        $s->textfield(-name=>'zp',-default=>$var34,-size=>6,),"<BR>",
        "\nOffice Number<BR>",
        $s->textfield(-name=>'ph',-default=>$var25,-size=>30),"<BR>",
        "\nHome Number<BR>",
        $s->textfield(-name=>'h_ph',-default=>$var31,-size=>30),"<BR>",
        "\nFax Number<BR>",
        $s->textfield(-name=>'fx',-default=>$var26,-size=>30),"<BR>",
        "\nMobile Number<BR>",
        $s->textfield(-name=>'mob',-default=>$var27,-size=>30),"<BR>",
        "\nEmail Address<BR>",
        $s->textfield(-name=>'em',-default=>$var28,-size=>30),"<BR>",
        "\nDOB<BR>",
        $s->textfield(-name=>'db',-default=>$var33,-size=>6),"<BR>",
        "\nNotes<BR>",
        $s->textarea(-name=>'comm',-default=>$var30,-ROWS=>4,\
        -COLS=>40),"<BR>",
        $s->submit(-label=>'UPDATE'),"</LEFT>",
        $s->end_form();



-- 
Regards...

Brian Clare
Porte Communications


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

Date: 11 Jul 1997 20:03:19 -0700
From: Sanford Morton <sanford@halcyon.com>
Subject: Re: $ENV{'QUERY_STRING"} problem
Message-Id: <m3en95q8eg.fsf@halcyon.com>

tcyang@netcom.com (Tung-chiang Yang) writes:

> 
> You can check out the mouse book published by O'Reilly by Shishir
> Gundavaram, which provides a solution.
> 
> =====================================
> Trang Ngo wrote after zapping the scum of the universe:
> : Hello 
> :   when I am passing the data to my perl cgi.  If the data has more than
> : 1 word, I 
> : will lose everything except the first word.  

You need to replace spaces ( ) with pluses (+) in the query string you
submit to a cgi script. There's a brief tutorial at
    http://www.halcyon.com/sanford/cgi/readdata/

--------
Sanford Morton, Ph.D.                           CGI Resources
sanford@halcyon.com       http://www.halcyon.com/sanford/cgi/



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

Date: Thu, 10 Jul 1997 20:38:26 GMT
From: bernie@rev.net (Bernard Cosell)
Subject: 'use strict' with CGI.pm
Message-Id: <33c64832.94737973@news.rev.net>

Hi--

I'm fond of using 'use strict', but I run into trouble when I try to
use various modules.  The problem de jour is with CGI.pm.  First sign
of trouble is when I went to do:
   use CGI shortcuts;
and got a 'bareword' error.  And throughout I get errors like:

 Unquoted string "startform" may clash with future reserved word at
checkhours.pl line 43.

Is there some general way to arrange 'tidy' access to CGI.pm so that
use strict; will be happy?  Thanks!

  /Bernie\
-- 
Bernie Cosell                        mailto:bernie@rev.net
Roanoke Electronic Village


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

Date: 10 Jul 1997 17:00:06 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Best idiom for defaulting, getting & untainting an env variable.
Message-Id: <5q34em$agm@lyra.csx.cam.ac.uk>

In article <33c309d6.23660261@news.one.net>, dave <over@the.net> wrote:
>
>($inval = $ENV{INVAL} ||= "default") =~ /^(exp)$/ and $inval = $1;

That's not doing what you think: it parses as

  $inval = ($ENV{INVAL} ||= "default")

so it spuriously sets $ENV{INVAL}.   Probably harmless in this case but ...

This should do it:

 ($ENV{INVAL} || "default") =~ /^(exp)$/ and $inval = $1;


Mike Guy


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

Date: 10 Jul 1997 09:39:34 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Checking for valid Email...
Message-Id: <slrn5s9bcg.kto.evenh@ra.pvv.ntnu.no>

In article <5q1tq8$4on$1@news5.gte.net>, Brandon Wilkins wrote:
>How do I go about checking if a email address is basically valid (In
>form...)?

See answer of this somewhere previuos... If your news server haven't got
them then try http://www.dejanews.com/ and search for valid email or 
something similar.

This question has been asked and answered before.

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: 11 Jul 1997 23:08:58 -0400
From: wlinden@panix.com (Will Linden)
Subject: CPAN help
Message-Id: <5q6sga$nkl@panix2.panix.com>

   I badly need guidance in how to install CPAN modules on my account.
   Yes, I already asked for help at my home site, and it was not enough.
   Following the "usual instructions" I tried "perl5 Makefile.PL" and got

Error: Unable to locate installed Perl libraries or Perl source code.
 
It is recommended that you install perl in a standard location before
building extensions. You can say:
 
    perl5 Makefile.PL PERL_SRC=/path/to/perl/source/directory
 and several other variations, all of which responded:

 
if you have not yet installed perl but still want to build this
extension now.
(You get this message, because MakeMaker could not find 
"/usr/local/lib/perl5/sun4-sunos/5.003/CORE/perl.h")

So after asking about locations, I tried:

perl5 Makefile.PL PERL_SRC=/usr/local/lib/perl5.003
 
You cannot build extensions below the perl source tree after executing
a 'make clean' in the perl source tree.
 
To rebuild extensions distributed with the perl source you should
simply Configure (to include those extensions) and then build perl as
normal. After installing perl the source tree can be deleted. It is
not needed for building extensions by running 'perl Makefile.PL'
usually without extra arguments.
 
It is recommended that you unpack and build additional extensions away
from the perl source tree.
Warning: PERL_LIB (/usr/local/lib/perl5.003/lib) seems not to be a perl library directory
        (Exporter.pm not found) at /usr/local/lib/perl5.003/ExtUtils/MM_Unix.pm line 1589.
 
Warning: I could not locate your pod2man program. Please make sure,
         your pod2man program is in your PATH before you execute 'make'
 
Writing Makefile for Date::Convert

  I went ahead and tried "make", and always got:

 
make: Fatal error: Don't know how to make target 
`/usr/local/lib/perl5.003/config.sh'
   

    Is there something else I am doing wrong? Or are non-superusers unable
to use the modules?

-- 
Will Linden  wlinden@panix.com
http://www.panix.com/~wlinden/
Magic Code: MAS/GD S++ W++ N+ PWM++ Ds/r+ A-> a++ C+ G- QO++ 666 Y


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

Date: Fri, 11 Jul 1997 20:16:03 -0700
From: Austin Schutz <tex@collegenet.com>
Subject: Re: eof() && sockets?
Message-Id: <33C6F6F3.7DDD@collegenet.com>

Chris Mason wrote:
> 
> All-
> 
>         Having some problems with eof() and nonblocking sockets. For example

> fcntl(Incoming, F_SETFL, O_NONBLOCK) || die (...);
[stuff]
>                 eof ($storesocket) && die("oh dear.\n");
>                 # always "oh dear."
>         }
>         select(), etc...
> }
> 
> This is contrived, but the only way I can think to tell if the socket
> has closed on me, is to use eof(), and it always returns true.

	eof() is a kludge as mentioned in the blue camel book. It does
something bizarre like try to read a character in and then unread it.
This has basically no meaning in a nonblocking situation.
	I'm not sure if this applies to socket io but what can work for files
is to use the 4 argument version of select() and sysread(). With 
files, select will return true if the filehandle is ready and wants to
spit an eof at you. When you actually sysread() from the handle it will
return 0 if it hits an eof.
	Make sure you don't combine sysread() and read() (eof() uses read()),
and make sure you flush the handle.
	There's probably an easier less bastardized way to do this which I'm
sure someone else will point out, but hey-- it works :-).

	Tex


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

Date: Thu, 10 Jul 1997 09:11:00 -0700
From: Jim Wiese <wiese@datatools.com>
To: Robert Pang <rpang@us.oracle.com>
Subject: Re: Exception package?
Message-Id: <33C50994.44DB@datatools.com>

Robert,
	If you have found any more information about the "try" and "catch"
blocks, can you please email them?  Currently, one can make the
following definitions :

sub try (&$) {
  my ($try, $catch) = @_ ; 
  eval { &$try };
  if ( $@ ) {
    local $_ = $@; 
    &$catch ; 
  }
}
sub catch (&) { @_ }

*From Programming Perl, Second Edition.  Wall, Christansen & Schwartz.
O'Reilly & Associates Inc. (1996)

Thus one can make the statement,

try {
  die "Died here";
} catch {
  print "caught dying process";
}

But..... I haven't been able to make this function work properly,
because the catch block evaluates first and returns a '1' , and not it's
argument list.  I've been try different variations, but I haven't had
any success. 

)Robert Pang wrote:
> 
> Hi everyone,
> 
> I am looking for an exception management (C++ throw-and-catch stuff)
> package for Perl.  I came across a package called Experimental::Exception
> by Torsten Ekedahl.  In his README file, he mentions that there is
> currently a discussion on a built-in exception mechanism in Perl.  Does
> anyone know the details?
> 
> Thanks.
> 
> Rober Pang
> rpang@us.oracle.com
> Oracle Corp.


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

Date: Thu, 10 Jul 1997 11:09:26 -0400
From: Eric Kissinger <erick@servtech.com>
Subject: foreach array indices
Message-Id: <33C4FB26.1820@servtech.com>

in a 'foreach (@array)'  command, is it possible to find out what
indice
 the array is at when a condition is met?

 i.e.  say I have an array, @array that I want to check to see if it
 contains a value $value.

     foreach (@array) {
       if ($_ eq $value) {
          'manipulate the next four values in the array'
          'only, I don't know current array index, unless I use a
counter'
       }
     }

 is there a variable the contains the current indice during the foreach
loop iteration?


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

Date: Thu, 10 Jul 1997 10:01:19 GMT
From: ddurand@hpplus17.cern.ch (Jean-Damien Durand)
To: joshg@ola.bc.ca
Subject: Re: Foreach with lists of arrays
Message-Id: <ED3L68.B5M@news.cern.ch>


> But if I try this with a list of arrays, things get screwy.
> 
> @List = (['one','two','three'],['a','b','c'],['1','2','3']);
> foreach $Thing (@List) {
>    print "  This is $Thing\n";
> }
> 
> And the output is...
>   This is ARRAY(0x217e738)
>   This is ARRAY(0x2180288)
>   This is ARRAY(0x21802c4)

@List = (['one','two','three'],['a','b','c'],['1','2','3']);
for $RefThing ( @List ) {
    print "\t [ @$RefThing ],\n";
}

  Kept from (and please read carefully this important and very usefull page) 
"Perl Data Structures Cookbook": http://www.isg.sfu.ca/doc/perl-cookbook.html

  Cheers,               Jean-Damien.
--
       *******************************************************
       *   Jean-Damien Durand (Jean-Damien.Durand@cern.ch)   *
       *         www : http://wwwcn.cern.ch/~ddurand/        *
       *******************************************************


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

Date: 10 Jul 1997 23:42:05 GMT
From: king@cogsci.ucsd.edu (Jonathan King)
Subject: Re: Foreach with lists of arrays
Message-Id: <5q3s0e$ffm$1@news1.ucsd.edu>

In article <33c41f3f.5887589@news.telecom.at> 
beryte@leb.net (beryte) writes:
>Joshua Gemmell <joshg@ola.bc.ca> wrote:
>>
>>But if I try this with a list of arrays, things get screwy.
>>
>>@List = (['one','two','three'],['a','b','c'],['1','2','3']);
>>foreach $Thing (@List) {
>>   print "  This is $Thing\n";
>>}
>>And the output is...
>>  This is ARRAY(0x217e738)
>>  This is ARRAY(0x2180288)
>>  This is ARRAY(0x21802c4)
>
>Maybe you should use "( )" instead of "[ ]" in this case.
>
>@array1 = ("one", "two", "three");
>@array2 = ("a", "b", "c");
>@array3 = ("1", "2", "3");
>
>@list_of_arrays = (@array1, @array2, @array3);
>foreach $item (@list_of_arrays) {
> print "This is $item\n";
> }

That works, but Perl will interpolate your arrays into one big list,
which might not be what you want.  If you really want a list of
lists, then you might want to look at the relevant parts of the Perl
manual, which are:

perldsc (Perl datastructures cookbook)
perllol (Manipulating Lists of Lists in Perl)

Yes, this is a FAQ.  In the mean time, here's a hint:

    @List = ([a, b, c], [d, e, f], [g, h, i]);

    foreach $thing (@list) {
	print "This is @{$thing}\n";
    }

This wil produce:

Thing is a b c
Thing is d e f
Thing is g h i

jking


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

Date: 11 Jul 1997 01:03:13 GMT
From: Cameron Simpson <cs@zip.com.au>
To: "mashfiel" <ashfield.matthew@miti.nb.ca>
Subject: Re: Global Vars : Why would I want to use "use strict"
Message-Id: <19970711112642-cameron-1-18286@sid.research.canon.com.au>

"mashfiel" <ashfield.matthew@miti.nb.ca> writes:
| Hi, kinda new to Perl, so this may be a dumb question, if so, my apologies.
| I've been doing a program in Perl, and through the loads of documentation
| on the web, I keep seeing the recommendation to use the statement 
| use strict;
| From what I understand this enforces me to declare all my variables with 
| my()
| Now, from my understanding of my(), this makes the variable statically
| local. Ie. it can only be seen in the block in which it is contained. Now
| if I do this, how would I use global variables? This will probably end up
| in an argument on the use of global variables (sorry!).  I personally don't
| mind using them in moderation, but I understand a lot of people despise
| them. So if I use the 'use strict;' command, which forces me to declare all
| my variables with 'my()' then I can't use global variables right?? If this
| is correct, then I guess I'll have to read the passing by reference section
| about 5 more times! Anyway, any discussion/advice would be appreciated!

It actually requires globals to be fully qualified, so you can still say
	local(thing)
but "thing" has to be something like
	$::X
i.e. the package name needs to be there. You'll find this results in a program
where all globals are clearly marked. The checking also seems to result in
catching a large number of incidental bugs (mostly undeclared variables,
whcih end up glabel when you probably wanted them to be local).

In practice I find that most variables are done with my(), some few globals
still float around for specific needs and VERY VERY VERY few local()s get used
(mostly for things like nested contexts and indent levels, etc).

I recently stuck
	use strict qw(vars)
on all my modules and found several small bugs thereby, and have also
coerced myself into a better coding style.

It's a lot like making C code get past lint without warnings - it's a win
despite the effort you need to make.
	- Cameron Simpson, cs@zip.com.au, DoD#743
	  http://www.zip.com.au/~cs/
--
Are you trying to tell us that you get up incredibly early, just to
spend an hour reading news and not having any breakfast? [...]
I'm aghast that any human being would ever leave the sweet arms of
Morpheus, unless forced to by powers beyond his control.
	- Dan Sorenson <z1dan@exnet.iastate.edu>


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

Date: Thu, 10 Jul 1997 10:07:58 -0600
From: Euan Forrester <deforres@acs.ucalgary.ca>
Subject: Re: Help me to find my loose change !!!
Message-Id: <5q31f0$on6@ds2.acs.ucalgary.ca>

On Wed, 9 Jul 1997, Ben Sandler wrote:

> Martin Williams wrote:
> > 
> > I have written a few scripts that procee financial transactions but thus
> > far I have been unable to round my numbers up to 2 decimal places !!!
> > 
> > Please help me as I think I'm going crazy.
> > 
> > Martin Williams
> 
> Try this:
> 
> $num = 345.6789;
> $num = $num*100;
> print "$num\n";
> if ($num =~ /\.[5-9]/) {$num =~ s/\..+//g; $num=$num/100;
> $num=$num+.01;}
> else {$num =~ s/\..+$//g; $num=$num/100;}                               
> - Ben

Why not just do this:

$num = 345.6789;
$num *= 100;
$num = int($num + 0.5);
$num /= 100;

It definitely looks prettier!



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

Date: 10 Jul 1997 14:41:25 GMT
From: "William Munroe" <wmunroe@bulldog.ca>
Subject: Help needed with Perl on IIS Server
Message-Id: <01bc8d3f$56e474c0$3e8d65cc@Romainia.earth>

I have a Web application running on Unix and NT (Netscape server) that I
am trying to get working on NT using an IIS Web server. Part of my
application is written in Perl. Everything works except for one script
(it's actually a fairly standard one, cgi-bin.pl, which reads in GET or
POST data, converts it to unescaped text, and puts key/varlue pairs in
%in). 

When the request method is POST, and the Perl script tries to read from
STDIN, the script hangs. I have tried with several different versions of
NT Perl interpreters, as well as mucking about in the bowels of the Type
Registry, as IIS documentation suggests. I got a response from the
people who wrote cgi-bin.pl in the first place, but they could only say
they believed it would work with the right IIS configuration.

Any ideas out there?
________________________________________________
William Munroe, Senior Programmer
The Bulldog Group Inc.
wmunroe@bulldog.ca	http://www.bulldog.ca
T (416) 594 9207 x234
F (416) 594 9577



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

Date: Sat, 12 Jul 1997 06:11:09 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Help! Need to run a script!
Message-Id: <tcyangED6zuL.M5n@netcom.com>

You need to describe where you are going to run it (Mac, Windows NT,
Unix, and so on).

Read the group please.  You cannot expect a free pizza with a free
delivery service.

====================================
Joshua Senecal wrote after zapping the scum of the universe:
: I'm new to the PERL scene. I have a PERL script (.pl file) that I need
: to run, but I haven't a clue how. Can anyone help me out?

: Please reply by mail.

: Thanks!

--
====== Try the low-crossposting robomoderated 'alt.culture.taiwan' ======

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: Thu, 10 Jul 1997 11:20:11 -0400
From: Mark Buckaway <mark@uunet.ca>
Subject: HELP: 'grepping' large files taking TOO LONG
Message-Id: <33C4FDAB.69A5@uunet.ca>

I am a bit of a purist and hate using shell commands in perl scripts. I
try to use perl code in place of anything that a shell command should
do. However, I have one instance here I find puzzling. incidentally,
this is perl 5.003 under SunOS.

I have three large text files to go thru and find a string of
characters. If the string of characters is found in a line, I keep the
line in an array for later processing. Memory is not an issue here so
making a big array is no big deal.

I've used code to run thru the files with an open, while, etc, but to go
thru the three files (about 4-6M each) takes about 5 mins.

I re-wrote the code to use the FileHandle lib, and it's faster...about
1.5 mins now. I now have:

	# Create a file handle to work on our large file
	return(0) if (!($fh=new FileHandle($filename,'r')));

	# Suck in all the records that match what we are looking for
	@records=grep(/$opt_a/,$fh->getlines());
	$fh->close();

However, if use the unix command grep command in the script, the file
search takes about 10 seconds:

	$items=`grep $opt_a $filename`;
	@records=split(/\n/,$items);

Am I missing something here? Or should I just stop being a purist?

Mark
-- 
-----------------------------------------------------------------------

Mark Buckaway                       mark@uunet.ca       +1 888 UUNET OK
Software Programmer                 Systems Group       +1 416 216 5146
UUNET Canada Inc.                                     Internet Services
-----------------------------------------------------------------------


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

Date: Thu, 10 Jul 1997 18:15:18 -0700
From: Austin Schutz <tex@collegenet.com>
Subject: Re: HELP: force a <CR> in DOS
Message-Id: <33C587E7.12D6@collegenet.com>

a.maclennan@rgu.ac.uk wrote:
> 
> I'm running Perl 5.001, in a  DOS window under Win95. Iwant to get the
> current date into a scalar, so I thought I'd do it like this:
> 
> open(DIR, 'date |') ;
> 
	You might try localtime(time); I think that's supported under 
winperl. Otherwise you might take a look at the IPC::Open2 module though
I have a sneaky suspicion it's probably not supported.

	Good luck, etc.

	Austin


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

Date: Fri, 11 Jul 1997 01:13:58 GMT
From: shaggy@redrobin.oswego.edu (Jeff Schneider)
Subject: How do I lock a file in MacPerl?
Message-Id: <shaggy-ya02408000R1007972013580001@news.oswego.edu>

Hi all:

I've modified some Perl code for a cgi that allows my students to add URLs
to a web page for their homework. It checks for duplicate entries so that
students can't merely copy from one another, etc. It runs off of my
PowerMac 7100 under MacPerl v5.13r2. Here's my dilemma: A friend pointed
out that there is the potential for a student's homework to be lost should
the cgi be called simultaneously or nearly so by more than one student. I'd
like to lock the file(s) used to check for duplicates so that only one
student can access at a time, but MacPerl doesn't support "flock". I would
be grateful if anyone could make some suggestions. Could I do the
following?



while ( -f $lockfile) {
   select(undef, undef, undef, 0.1);
}
open(LOCKFILE, ">$lockfile");

 ... do all the duplicate checking, file writing, etc in here ...

close(LOCKFILE);
unlink($lockfile);



Thanks in advance. You could post here or email me at
<mailto:shaggy@redrobin.oswego.edu>

Jeff, the wannabe Perl programmer


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

Date: 10 Jul 1997 17:22:12 -0400
From: allen@gateway.grumman.com (John L. Allen)
Subject: Re: How to substract a uniq integer from a ASCI string
Message-Id: <5q3jq4$6g7@gateway.grumman.com>

In article <toutatis-ya023180001007972039030001@news.euro.net>,
Toutatis <toutatis@remove.this.toutatis.net> wrote:
>Hi,
>
>Could anybody advise me on how to create from a given string
>an integer that somehow is (quite) unique for that character string?
>
>I came up with the following solution myself in perl:
>
>foreach(unpack('C*',$string)){
>      $code += $_;
>}
>
>It simply returns the sum of all ASCI values.
>
>but this way, toutatis results in the same code as titatous. I need
>something less easy to "crack" than this.
>And my returned codes vary from string-length * 97 to string-length * 122,
>where I prefer to use the *complete* integer "spectrum" to represent this
>string.
>Although I prefer the returned code to be an integer, a fixed width string of 
>say 6 characters would be fine too.

What you're asking for is a good hash function.  MD5 and SHA are two
cryptographically strong hash functions, but they produce 128 and 160
bits of output respectively.  You could use the first 32 bits of their
output as an integer if you wanted.

Here's a fairly efficient perl5 version of SHA as a subroutine.  For
your purposes, instead of the sprintf at the end, you could return, say,
$aa.  Feel free to use and modify as you see fit.  It's slow, but should
perform respectably if given only a few hundred bytes to hash.

I've also got MD5, if you're interested.  There are also MUCH FASTER
MD5 and SHA modules available on CPAN, and I think the MD5 module is
included in Sarathy's awesome perl 5.004 package for win32.

John.
----
#!/bin/perl -- RSA's SHA-1 in perl5 - "Fast" version.
#
# Usage:
#	sha < file
#
# Test Case:
#	$ echo 1234567890 | sha
#	12039d6d d9a7e276 22301e93 5b6eefc7 8846802e
#
# This version has been somewhat optimized for speed, and gets about
# 10 KB per second on a PPC604-120 42T workstation.  Still pitiful
# compared with C.  Feel free to improve it if you can.
#
# Author: John L. Allen, allen@gateway.grumman.com, 3/8/97
#

sub SHA {

use integer;

my $data = $_[0];

my ($aa, $bb, $cc, $dd, $ee) =
	(0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0);

my ($a, $b, $c, $d, $e, $t, $l, $r, $p) = (0)x9;

my @W;

local $_;

do {
  $_ = substr $data, $l, 64;
  $l += ($r = length);
  $r++, $_.="\x80" if ($r<64 && !$p++);	# handle padding, but once only ($p)
  @W = unpack N16, $_."\0"x7;		# unpack block into array of 16 ints
  $W[15] = $l*8 if ($r<57);		# bit length of file in final block

	# initialize working vars from the accumulators

  $a=$aa, $b=$bb, $c=$cc, $d=$dd, $e=$ee;

	# the meat of SHA is 80 iterations applied to the working vars

  for(@W){
    $t = ($b&($c^$d)^$d)	+ $e + $_ + 0x5a827999 + ($a<<5|31&$a>>27);
    $e = $d; $d = $c; $c = $b<<30 | 0x3fffffff & $b>>2; $b = $a; $a = $t;
  }
  for($_=16;$_<20;$_++){
    $t = $W[$_-3]^$W[$_-8]^$W[$_-14]^$W[$_-16];
    $W[$_] = $t = ($t<<1|1&$t>>31);
    $t += ($b&($c^$d)^$d)	+ $e + 0x5a827999 + ($a<<5|31&$a>>27);
    $e = $d; $d = $c; $c = $b<<30 | 0x3fffffff & $b>>2; $b = $a; $a = $t;
  }
  for(;$_<40;$_++){
    $t = $W[$_-3]^$W[$_-8]^$W[$_-14]^$W[$_-16];
    $W[$_] = $t = ($t<<1|1&$t>>31);
    $t += ($b^$c^$d)		+ $e + 0x6ed9eba1 + ($a<<5|31&$a>>27);
    $e = $d; $d = $c; $c = $b<<30 | 0x3fffffff & $b>>2; $b = $a; $a = $t;
  }
  for(;$_<60;$_++){
    $t = $W[$_-3]^$W[$_-8]^$W[$_-14]^$W[$_-16];
    $W[$_] = $t = ($t<<1|1&$t>>31);
    $t += ($b&$c|($b|$c)&$d)	+ $e + 0x8f1bbcdc + ($a<<5|31&$a>>27);
    $e = $d; $d = $c; $c = $b<<30 | 0x3fffffff & $b>>2; $b = $a; $a = $t;
  }
  for(;$_<80;$_++){
    $t = $W[$_-3]^$W[$_-8]^$W[$_-14]^$W[$_-16];
    $W[$_] = $t = ($t<<1|1&$t>>31);
    $t += ($b^$c^$d)		+ $e + 0xca62c1d6 + ($a<<5|31&$a>>27);
    $e = $d; $d = $c; $c = $b<<30 | 0x3fffffff & $b>>2; $b = $a; $a = $t;
  }

	# add in the working vars to the accumulators, modulo 2**32

  $aa+=$a, $bb+=$b, $cc+=$c, $dd+=$d, $ee+=$e;

} while$r>56;

sprintf "%.8x %.8x %.8x %.8x %.8x\n", $aa, $bb, $cc, $dd, $ee;
}

undef $/;
$_ = <>;
print SHA $_;
-- 

John.


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

Date: Thu, 10 Jul 1997 20:26:43 -0400
From: CbN <Me@myisp.net>
Subject: IRC Program in Perl?
Message-Id: <33C57DC3.19A7@myisp.net>

Is there a program for IRC written in Perl?

Please e-mail me at: slam5@earthlink.net


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

Date: Thu, 10 Jul 1997 16:44:31 -0400
From: Bin Chen <266443@emc.fedex.com>
Subject: monitor web page, How?
Message-Id: <33C549AF.232B@emc.fedex.com>

How do know who is accessing you web page? Are there any scripts
available for this purpose?

Thanks.

Bin


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

Date: Tue, 08 Jul 1997 13:22:22 -0700
From: Roopesh Battepati <rbattepa@qualcomm.com>
Subject: Need Info On Using PERL.DLL
Message-Id: <33C2A17E.7E23DFB9@qualcomm.com>

I am a PERL & Windows newbie and know a little bit about DLL's. The
Win32
port of PERL distribution comes with PERL.DLL, but I could not find any
documentation /examples about how to use the PERL.DLL (In specific how
to
use it in C/C++ programs etc).

Could someone please point me to information/books/example-programs etc
about using PERL.DLL

Thank You
Babu R.C

P.S: Please direct all responses to: "rcb3766@omega.uta.edu"



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

Date: Thu, 10 Jul 1997 22:36:12 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Newbie Array pass by reference question
Message-Id: <ED4K4C.8uv@world.std.com>

"mashfiel" <ashfield.matthew@miti.nb.ca> writes:

>Hi all, 
>Well, as the subject line says I'm a newbie. That said, here's the problem.
>I've been creating a program, and after getting it to work, I decided to
>'tune' it, by using the 'use strict' statement, (yep, everything was global
>before! ) 

Oh, thats why you posted the "how do you use globals with use strict"
message. Twice.

>Anyway, I have it all working but for one part. The problem
>arises when I go to pass an array to a sub which will then edit it.

[stuff deleted]
>			&Initialise($i, \@Array);

Here you tell perl to take a reference to an array, and pass it to
Initialise. Remember, references are scalars.

>sub Initialise{
>	my ($index, @subArr) = @_;

Here you tell perl put the first element of the argument list into
$index, and the rest (which is one scalar, a reference to @Array) into
the list @subArr.) Now @subArr is a list of one element.

>	@$subArr[$index] = $index;

Now you refer to the global scalar $subArr, which is entirely distinct
from the array @subArr. You use it as a symbolic reference to an
array.


Unfortunately, "use strict" disallows symbolic references, and since
the scalar variable $subArr is uninitialized, I don't think it can be
a reference to anything.

If you change things to:

sub Initialise {
  my($index, $subArr) = @_;

Things should be better.
-- 
Andrew Langmead


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

Date: 10 Jul 1997 20:44:28 GMT
From: "Joshua Marotti" <jpm@iti-oh.com>
Subject: OOP question
Message-Id: <01bc8d72$0d074660$36601ec6@bach>

I have several objects.. I use the same reference for those objects..
example (pseudo code)
loop...
	ref = new Object "Name that changes each loop";
endloop...
now I want to go back to one of those previous references...  How would I
accomplish this?
Can I call
newref = new Object "one of the names used before";
and recieve the old object ref?
my new function looks like this
sub new
{
	my $type = shift;
	my $self = shift;
	$self->{info} = {};
	$self->{info1} = [];
	$self->{info2} = undef;
	bless \$self, $type;
}

All help is welcome...
Please reply by e-mail... I don't have time to check posts...
Thanks a bunch
Josh Marotti



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

Date: Fri, 11 Jul 1997 20:33:43 -0700
From: perl <guitarweb@hotmail.com>
Subject: open file and read part of host address to block entire domain.. how?
Message-Id: <33C6FB16.5399@hotmail.com>

Sorry, I can't think of an appropriate subject line.  
What I'm trying to do, is have my chat program (or any other) open a
file and look for a host or IP address and if it matches one on the
list, then lock them (their server) out of the script. I have this
working great, other then the fact, that if I need to ban an entire
server domain, I've been forced to go in via telnet and edit the script
and add the server domain with asterics..  I am only wondering if there
is a way, that I can block an entire domain (anything before, or
anything after their server address), obviously, in case they dial into
another modem.  can this be done? 
For exmaple (this works fine), this is at the top of the script (before
any comands where they can do anything), and it works fine, yet only
bans their exact modem.
**This is all done, by a ban page that you input their server address
and hit "ban them", and it writes to the HTML page**

$ban_page="jerks_list.html";
   
   open (BANNED,"$ban_page") || &unable("did not open ban file");
   @servers = <BANNED>;
   close (BANNED);
   
        foreach $jerk (@servers)
        {
        if($jerk =~ /^*$ENV{'REMOTE_HOST'}*/)
         {
          &YouRBanned; # the sub for the ban page telling them they're
banned... 
          die;
          }
        }  

Otherwise, when I have to ban an entire server domain, I am having to
telnet in, or FTP a new script and have another domain added like so
(for example)..
     
if ($ENV{'REMOTE_HOST'} =~ /^*23.34.56.*|^*203.203.11*/)
  {
   &YouRBanned;
   die;  
  }


I find more and more jerks coming to my site, adn this list in the
script is growing to be way too long. Is there a way I can have it ban a
domain from the list? As if they were at the IP address of
"234.142.34.34"  I can ban that modem, but if I want to ban the
"234.142.34" domain, how can I go about doing this? 

	I have ran out of ideas, please offer any advice if you know.. and
thank you..


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

Date: Thu, 10 Jul 1997 04:35:28 -0600
From: rahuljm@hotmail.com
Subject: OraPerl - oracle database objects ?
Message-Id: <868526940.5318@dejanews.com>

Hi,

  Can anyone inform me about how to access the Oracle Stored subprogram
(packages, stored procedures, functions) thro' OraPerl ? Is there any
particular syntax to achieve this? Pls reply on the above email id, don't
post it on Usenet. I require this info desparately...


Thanks in advance,

Rahul Mahajani

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 10 Jul 1997 11:56:48 -0700
From: dizzy@soda.CSUA.Berkeley.EDU (David Zeng)
Subject: Re: Output to a file
Message-Id: <5q3b9g$qci@soda.CSUA.Berkeley.EDU>

In article <tcyangED2y7G.14F@netcom.com>,
Tung-chiang Yang <tcyang@netcom.com> wrote:
>In this group you are supposed to post your code (or at least part of
>it which you believe to be relevant) for anyone to offer help.

Oh... here's the part of the code the is relevant to what I was asking:

Here's the main loop.  The subroutine &gather simply gathers all the
information I need to output to a file, and store them in a string
to be wrote into a file.

for ($k = 0; $k < $array_length; $k++)
{
    &gather($cache[$k]);         # Gather various data

    &output($cache[$k]);         # Pumping data into files
}

Here is what the &output subroutine looks like...

sub output
{
    $outline = $user_name . " - - " . $full_date . " " ."\"" . $prefix . "\n";

    print OUTFILE $outline;
}

$outline is the string to be written into OUTFILE.

Thanks for any help.

David Zeng



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

Date: Thu, 10 Jul 1997 14:05:18 -0700
From: Will Johnston <will@cs.ucr.edu>
To: mmartinez@techstaff.com
Subject: Re: Password program....
Message-Id: <33C54E8E.8380FFEC@cs.ucr.edu>

Mark Martinez wrote:
> Hello, I am new to Perl but can program in
> C / C++.  I was wondering if any one could help me with
> a little problem...  I want to Check a Name and Password
> before giving out put...
[etc.]

To give you an answer, I have to make a few assumptions:

1.) You're running this on a UN*X system and you want to authenticate
    users who have accounts on that machine.

2.) That you have access to each user's encrypted password.  This can
    be a problem if you are using shadow passwords and your script
    isn't run with root privilages.

3.) That your system uses the same crypt() routine to store passwords
    that your version of Perl does.

If those assumptions are correct, you should be able to authenticate
using this little routine:

$real_password = (getpwnam($username))[1];
if (crypt($given_password, $real_password) eq $real_password) {
   # password is valid, do your thing
} else {
   # password is bad, print error message
}


--
Will Johnston                       Systems Administrator
will@cs.ucr.edu                     Department of Computer Science     
http://www.cs.ucr.edu/~will         University of California, Riverside


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

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

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