[7735] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1360 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 23 03:07:35 1997

Date: Sun, 23 Nov 97 00:00:36 -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           Sun, 23 Nov 1997     Volume: 8 Number: 1360

Today's topics:
     CGI.pm Server Push Problem (Cliff)
     Re: Finding the longest common prefix over a list of st (Tushar Samant)
     Re: Finding the longest common prefix over a list of st (Abigail)
     Re: Hash table troubles (Jason Gloudon)
     help me with zone coasters voting script please. (modif cyberlucky@usa.net
     Re: is it possible to reference a sub-array? (Jason Gloudon)
     Re: Learning Perl in win95 (Pearl Fox)
     Re: open/read/close in PERL (Kevin Reid)
     Re: Perl and Sybase (Abigail)
     Re: perl bad for backgroud job? (Jeremy D. Zawodny)
     Re: Perl Enhancement (was: Re: Last element of an anony <dformosa@st.nepean.uws.edu.au>
     Re: Please help with user log (Pearl Fox)
     Problems with animated gifs in Netscape 3.01/ CGI warp@cia.com.au
     Re: Proxy Client (Abigail)
     Quirky string matching problem <etoon@asdweb.com>
     Re: ref to typeglob and filehandles <bowlin@sirius.com>
     Re: ref to typeglob and filehandles <doug@tc.net>
     Re: Regex for three equal characters <dformosa@st.nepean.uws.edu.au>
     security questions (Laurel Shimer)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 23 Nov 1997 00:06:15 GMT
From: clif@yallara.cs.rmit.edu.au (Cliff)
Subject: CGI.pm Server Push Problem
Message-Id: <657s1n$9qq$2@goanna.cs.rmit.edu.au>


[ Article reposted from comp.infosystems.www.authoring.cgi ]
[ Author was Cliff ]
[ Posted on 23 Nov 1997 00:05:11 GMT ]


I have the following code to use the do_push() method of CGI::Push and it
doesn't work no matter what I try, yet it is almost identical to the example
given in the CGI documentation.

Any ideas, thanks in advance.



use CGI::Push qw(:standard :html3);

do_push(  -next_page => \&page1,
          -last_page => \&page2,
          -delay     => 1);

sub page2
{
   return start_html('Page 1'),h1('Page 1'),end_html();
}

sub page1 
{
   if(!defined($displayed_yet))
   {
      $displayed_yet = "";
      return start_html('Page 2'),h1('Page 2'),end_html();	
   }
   else
   {
      return undef;
   }
}



-- Cliff Wakefield

**********************************************************************
* Masters Student(Info Tech) * http://zulu.cs.rmit.edu.au/~cliff/    *
* WeBTESt Admin/Programmer   * http://zulu.cs.rmit.edu.au/webtest    *
* Distributed Lab Admin(Zulu)* Redhat Linux v4.2, Kernel 2.0.32      *
* CS109 Tutor, CS280 Staff   * "Reboots are for upgrades!"           *
**********************************************************************
* Office 251.2.33        Phone 9407-6131        Mobile 0411110687    *
**********************************************************************





-- Cliff Wakefield

**********************************************************************
* Masters Student(Info Tech) * http://zulu.cs.rmit.edu.au/~cliff/    *
* WeBTESt Admin/Programmer   * http://zulu.cs.rmit.edu.au/webtest    *
* Distributed Lab Admin(Zulu)* Redhat Linux v4.2, Kernel 2.0.32      *
* CS109 Tutor, CS280 Staff   * "Reboots are for upgrades!"           *
**********************************************************************
* Office 251.2.33        Phone 9407-6131        Mobile 0411110687    *
**********************************************************************


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

Date: 22 Nov 1997 21:16:58 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <65877a$39f@shoga.wwa.com>

kfox@ford.com writes:
>For everybody else, here's my implementation of Ilya's algorithm:

How about benchmarking with some kind of check here?
|  
|    my @words = qw(the thick thesis thoroughly threw thor);
|  
|    my $prefix = shift @words;
|    my $len = length($prefix);
|  
|    foreach (@words) {
|
+-->    last unless $len;

         while (substr($_, 0, $len) ne $prefix) {
             --$len;
+------->    $prefix = substr($prefix, 0, $len);
|        }
|    }
|
|    print "$prefix\n";
|
|
Why not just chop $prefix? After all $len is always length($prefix) ...


>Perl's regex is *still* faster than Ilya's algorithm though, but only
>by a few percent.
>
>So, now there's a different question.  Given the fact that this new
>algorithm is just about as fast as the regex approach, which would you
>rather use/maintain?  Here's the regex again:
>
>  (join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;
>
>  print "$1\n";

This is as understandable, or more. Besides, aren't both pieces of code
going to get commented with pretty much the same thing?

You might want to put the commas in front, maybe include them in the
pattern and benchmark that...



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

Date: 23 Nov 1997 04:42:25 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <slrn67fd52.o38.abigail@betelgeuse.wayne.fnx.com>

Tushar Samant (scribble@shoga.wwa.com) wrote on 1545 September 1993 in
<URL: news:65877a$39f@shoga.wwa.com>:
++ kfox@ford.com writes:
++ >For everybody else, here's my implementation of Ilya's algorithm:
++ 
++ How about benchmarking with some kind of check here?

How about trying to *analyze* both algorithms? Let's say we have
N words, and each word is at most k characters long.

++ |    my @words = qw(the thick thesis thoroughly threw thor);
++ |  
++ |    my $prefix = shift @words;
++ |    my $len = length($prefix);
++ |  
++ |    foreach (@words) {

So, we will have O (N) iterations through this loop.

++ |
++ +-->    last unless $len;

That's O (1).

++ 
++          while (substr($_, 0, $len) ne $prefix) {

Clearly, a single test takes O (k) time.

++              --$len;
++ +------->    $prefix = substr($prefix, 0, $len);

With a chop here, both actions take O (1).

++ |        }
++ |    }

Now, note that the inner loop is iterated at most k times - the
length is always decreasing. So, the runtime for this algorithm
is bound by O (k * N). (With $prefix = substr($prefix, 0, $len)
in the inner loop, the bound would be O (k * (N + k)).)

++ |
++ |    print "$prefix\n";
++ |
++ |
++ Why not just chop $prefix? After all $len is always length($prefix) ...
++ 
++ 
++ >Perl's regex is *still* faster than Ilya's algorithm though, but only
++ >by a few percent.

Let's analyze it a bit further, before we drop to conclusions, shall we?

++ >So, now there's a different question.  Given the fact that this new
++ >algorithm is just about as fast as the regex approach, which would you
++ >rather use/maintain?  Here's the regex again:
++ >
++ >  (join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;

For this, I'm going to prove a lowerbound on the run time for a
specific example. I will use W for Omega, as ascii doesn't have
Greek symbols.

Take N - 1 words of length k all sharing the same prefix, and let that
prefix be at least k/2 characters long. Let the last word not have
any prefix in common with the rest (except for the empty string).

The join will generate a string of length W (k * N). Due to the
greedyness and backtracking of the regex machine, after being
discovered a certain prefix didn't make it, the regex machine
will try a prefix one shorter, and start all over again.

After finding the common prefix for the first N - 1 words, it
has to scan W (k * N) words before it fails and needs to backtrack.
It needs to backtrack W (k) times. Hence, a total running time of
W (k^2 * N).

Clearly, Ilya's algorithm beats the regex hands down.


I am almost certain that with a bit more careful analysis, I would
be able to proof that Ilya's algorithm (with Tushar's suggestion) is
linear (and hence optimal) in the size of the input.

++ >  print "$1\n";
++ 
++ This is as understandable, or more. Besides, aren't both pieces of code
++ going to get commented with pretty much the same thing?

Any program that needs to be maintained probably needs to be
efficient too. So, there would be no place for the regex.

(The regex is much cuter though.)

++ You might want to put the commas in front, maybe include them in the
++ pattern and benchmark that...


No need for a benchmark I would say.



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: 23 Nov 1997 03:16:59 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: Hash table troubles
Message-Id: <65877b$fk5$2@daily.bbnplanet.com>

John Dubchak (jdubchak@mb.sympatico.ca) wrote:

: sub hash_load {
:    my $attribute = shift;
:    my $tag_val = shift;

Every time you try to add a new tag_val here, you create a new hash reference,
and the last thing you created with the same attribute gets destroyed. 
I believe this is not what you really want ?

:    @_ ? $ini{$attribute} = {$tag_val => shift} :

If you act as though the hash reference already exists, the first time you
try to use it, it will be created for you. So this line should look like:

   @_ ? $ini{$attribute}->{$tag_val} = shift :

: $ini{$attribute}->{$tag_val};
: }

You only need to say something like 

   $ini{$attribute} = {$tag_val => shift}

if you want to create a new empty hash.

Jason Gloudon


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

Date: Sun, 23 Nov 1997 02:34:46 GMT
From: cyberlucky@usa.net
Subject: help me with zone coasters voting script please. (modifying)
Message-Id: <6584nb$ms5@bgtnsc03.worldnet.att.net>

I am trying to modify Zone Coasters script.

The Script compares stuff such as the results will be A vs A; A vs B : B vs B ; B vs A ect. I want it only to compare A vs  A ; B vs B ; C vs C etc. 

i want it to do something like this
======
Option 1             Occurrences               Percent(Rounded)
3 Musketeers       2 times out of 3            67%
1492 	            1 times out of 3	33%

instead of
=====
Option 1           Option 2             Occurrences         Percent(Rounded)
3 Musketeers    3 Musketeers     2 times out of 3      67%
3 Musketeers    1492                  0 times out of 3       0%
1492                  3 Musketeers     0 times out of 3     0%
1492                 1492                  1 times out of 3      33%

so can you download the vote script at www.zonecoaster.com and see if you can help me. 

these are the current things that I have set other than the script itself

form
======
<form method=post action="http://free.prohosting.com/~sean/cgi-bin/survey.pl">
<select name="midi">
<option value="mess ups" SELECTED>VOTE</option>
<option value="1492">1492</option>
<option value="2001-Space Odyssey">2001-Space Odyssey</option>
<option value="3 Musketeers">3 Musketeers</option>
<option value="4 Weddings & A Funeral">4 Weddings & A Funeral</option>
<option value="633 Squadron">633 Squadron</option>
<option value="9 to 5">9 to 5</option>
</select>

<input type=submit value="Vote">
<input type=hidden name="survey" value="survey1">
</form>


And the setupfile
=====
midi_midi
midi_midi

------
so now you know how my form is setup give it a try and try to modify the script to help me.  I tried to modifie it but I just started to learn perl so I didn't know exactly what to edit.
-----

If you can help me it would be appreciated.

Thanks,
Sean

ps. also if you have a free voting script that can do what I want it would be great.


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

Date: 23 Nov 1997 02:40:43 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: is it possible to reference a sub-array?
Message-Id: <65853b$fk5$1@daily.bbnplanet.com>

Zenin (zenin@best.com) wrote:
: Kevin Eson <keson@uswest.com> wrote:
: : Re-read what Tom had said.
: 	And my example code.

I think this thread has gotten into a semantics war.

: 	In short:
: 		YES!  You CAN pass an array SLICE BY REFERENCE

  Less ambiguously and emotionally : 
		You can pass an array of references to the elements of an array slice.
      eg.

		thefunction(\(@ARGV[1..5])), which passes 5 references to thefunction.

I do not believe we've seen a way of passing a single reference that refers
to a slice of an array, because perl doesn't support this ( and doesn't really
need to).

I think the best solution to this question is to pass the indexes of the
start and end of the slice, or equivalenty the index of the start of the slice
and the number of elements in the slice, as one does when calling splice.

eg. 
thefunction($start, $end, @ARGV);
      or
thefunction($start, $count, @ARGV);

C style code has a place, even in Perl.

Jason Gloudon


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

Date: Sun, 23 Nov 1997 05:02:13 GMT
From: fox@securenet.net (Pearl Fox)
Subject: Re: Learning Perl in win95
Message-Id: <6581r8$hoi$1@news.securenet.net>

Thank you everyone for replying by email to me!
This is a great newsgroup!  Keep it up.
Pearl

fox@securenet.net (Pearl Fox) wrote:

> If there is a site where I can get the information that I need to get
>me  started in learning how to program in Perl with win 95
>environment, I  would really appreciate it.  I downloaded the Perl
>program but don't know how to use it with win 95?

>Thanks
>Pearl

>Pearl S. Fox,
>Montreal (Que.)
>http://www.securenet.net/members/fox/index.html


Pearl S. Fox,
Montreal (Que.)
http://www.securenet.net/members/fox/index.html



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

Date: Sun, 23 Nov 1997 00:54:15 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: open/read/close in PERL
Message-Id: <1d00o8f.1g8psc510qdnoiN@slip166-72-108-130.ny.us.ibm.net>

Mike Snyder <accu-scan@worldnet.att.net> wrote:

> My question is this, considering this code:
> 
> ####
> open FILE, "sn.dat";
> read FILE, $buffer,100000;
> close FILE;
> @pairs = split(/&/, $buffer);
> ####
> 
> The file is really only about 53000 bytes (not 100000) but it might grow
> in the future. I haven't seen any side effects from trying to read MORE
> bytes than are in the file. It seems to work just fine and $#pairs ends
> up being the correct number of records.
> 
> Does anybody see any ill-effects that might be caused from this. I've
> tested it all morning and it's working wonderfully. I then perform a
> second split on the contents of each $pair[] in itterations though a
> hand-made binary search. (only have to split around 13 records total to
> find any serial number in the list).

To quote from the Camel book ("Programming Perl"):

    read FILEHANDLE, SCALAR, LENGTH, OFFSET
    read FILEHANDLE, SCALAR, LENGTH

  This function attempts to read LENGTH bytes of data into variable
  SCALAR from the specified FILEHANDLE. The function returns the bytes
  actually read, 0 at end of file.

I read this to say that reading less than LENGTH bytes is OK.

But may I suggest using the <> operator?

open FILE, "sn.dat";
@pairs = map {split(/&/)} <FILE>;
close FILE;

Or:

open FILE, "sn.dat";
$/ = "&";
@pairs = <FILE>;
close FILE;

-- 
Kevin Reid


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

Date: 23 Nov 1997 01:59:30 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl and Sybase
Message-Id: <slrn67f3ji.o38.abigail@betelgeuse.wayne.fnx.com>

Rick Meldrum (rjk@fprsdev3.fmr.com) wrote on 1543 September 1993 in
<URL: news:3475CC8A.2107@fprsdev3.fmr.com>:
++ Greg Stanfield wrote:
++ > 
++ > I am relatively new to combining Perl and Sybase, and could use some
++ > help, if anyone has the time.
++ > 
++ > I am trying to connect to a Sybase database from a Perl script.  I have
++ > the isql statement ready to go, but cannot figure out the right/best way
++ > to connect to the database to pass the isql statement. 
++ 
++ [.....]
++ 
++ I have had relatively good luck with variations of...
++ 
++ $cmds = "$my_password\n exec $myproc $params\n go\n exit\n";
++ system "isql -Umy_id<<EOF\n$cmds";
++ 
++ Sometimes I add:
++ 
++ @tmp_array = system "isql -Umy_id<<EOF\n$cmds";
++ 
++ and my results are now in hand...

But that means 2 extra processes per query, one to the shell, one
to isql.

Why not just:

use Sybase::DBlib;

my $dbproc = new Sybase::DBlib 'user', 'password', 'server'
    or die "Failed to create dbproc: $!";

$dbproc -> dbuse ('database');

my @results = $dbproc -> sql ("sql command");


Or one of the many other methods defined in the DBlib interface.


You can also use interfaces with other Sybase libraries. Or use
the more generic DBI module.


(All available from your friendly CPAN retailer.)


Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: Sun, 23 Nov 1997 00:33:12 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: perl bad for backgroud job?
Message-Id: <34787930.88007828@woody.wcnet.org>

[original author automagically cc'd via e-mail]

On 22 Nov 1997 02:50:11 GMT, esiu@cs.UAlberta.CA (Ernest Siu) wrote:

>Is perl bad for a job which is run continously on background?

Not any worse then sh, awk, C, python, or other decent languages.

>I have a simple perl program to periodically record some data.
>It is supposed to be run continuously on the background.
>However, after I ran it for couple of days, it seems like it
>is eating up more and more RAM as time goes.  Is there anything
>special about memory allocation in perl?  Any suggestion?

Make sure you're using the latest Perl. If there's a memory leak in an
older Perl, you might be seeing it.

Check to make sure you're not storing data unnecessarily in your code.
Are there any variables that are likely to grow and grow and grow?

I have written background jobs and/or daemons in Perl which have run
for several hundred days without trouble. There *shouldn't* be
anything inherent to Perl which would prevent you from doing that.

Of course, I don't know the specifics of what you're doing. :-)

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: 23 Nov 1997 01:50:17 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Perl Enhancement (was: Re: Last element of an anonymous array)
Message-Id: <880249733.647497@cabal>

In <lq1afeyn47r.fsf_-_@bmers2e5.nortel.ca> Mark Mielke <markm@nortel.ca> writes:

>norm@turing.une.edu.au (Norman Gaywood) writes:

[...]

>How about this :-) Rather than having 1..10 evaluate to (1,2,3,...,9,10)
>which is... just sorta... wrong when it comes to memory concern... how about
>'..' returns an internally tie()'d array when both sides are valid integers.

I understand what you mean, it is simmler to the 'trick' used by mirander
and such langugers to allow it to represent lists of inifinite leanth.

Basicly you say the [n]th element of the array is n.  In fact then you
could this  (1..)  to repersent an array of infinite leanth of all postive
numbers.

--
Please excuse my spelling as I suffer from agraphia see the url in my header. 
Never trust a country with more peaple then sheep. I do not reply to mungged 
Support NoCeM http://www.cm.org/                   addresses.  
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: Sun, 23 Nov 1997 05:04:39 GMT
From: fox@securenet.net (Pearl Fox)
Subject: Re: Please help with user log
Message-Id: <6581vq$hoi$2@news.securenet.net>

I do not have a fixed IP address, and my server does do a username
lookup when connecting, so how do I circumvent these problems when
excluding my visit to my site?
Pearl

comdog@computerdog.com (brian d foy) wrote:

>In article <651jjq$m29$1@news.securenet.net>, fox@securenet.net (Pearl Fox) wrote:

>>I have this user log file on my webpage to log the users.  However I
>>would like to exclude my own entry when visiting my page.  How would I
>>do this?  

>before you let your script open files and so on, check to see that the
>user is not you.  how you do this can vary, but let's assume that you 
>have a development machine with a fixed IP number and your server isn't
>doing hostname lookups:

>   #somewhere near the top.  supply your IP
>   exit if $ENV{'REMOTE_HOST'} eq 'aaa.bbb.ccc.ddd';

>if your situation is a bit different, just salt that test to taste :)

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

Pearl S. Fox,
Montreal (Que.)
http://www.securenet.net/members/fox/index.html



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

Date: Sat, 22 Nov 1997 23:01:41 -0600
From: warp@cia.com.au
Subject: Problems with animated gifs in Netscape 3.01/ CGI
Message-Id: <880260910.11273@dejanews.com>

Hello,

I'm using a Perl CGI script to randomly show animated gifs
on a web page.  The <img src... html tag looks like this:

<img src="..URL../cgi-bin/image.cgi" border="0" align=right>

The gifs are set to loop forever, but for some reason, when
called up by the script, they loop once then stop in Netscape.

They loop fine in MSIE3.0.  Typing http://..../cgi-bin/image.cgi
brings up the gif nicely in NS too - it just won't loop in-situ
when called by html in a Netscape page.

I've tried lots of different scripts (the one above is from Matt's
script archive - nice and simple).  I'm not a Java or HTML guru
and would like some suggestions on a work-around, or just to be
told that it's not possible so I won't waste any more time.

Thanks in advance,
Mark

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


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

Date: 23 Nov 1997 02:00:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Proxy Client
Message-Id: <slrn67f3m7.o38.abigail@betelgeuse.wayne.fnx.com>

Pete Storm (peter.storm@its.cna.com) wrote on 1543 September 1993 in
<URL: news:3475CF06.68395BCE@its.cna.com>:
++ Hello hello hello
++ 
++ I'm trying to program a little web client.  This is an exercise in
++ learning how to deal with headers and such.  I am not interested in
++ using the LWP modul e (because I know how to do it with that).
++ 
++ What I'm looking for is advice/pointers/help on how to authenticate with
++ a proxy.
++ 
++ Anyone have any ideas/maintenance/hints/tips/etc?
++ 
++ What I have so far is this
++ 
++ I connect to proxy
++ pass it the page request
++ 
++ it sends me back a 407 error asking for authentication, but then it
++ sends the error page and close the connection


Try comp.infosystems.www.servers.<your os>.



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: 22 Nov 1997 23:08:41 GMT
From: Eddie Toon <etoon@asdweb.com>
Subject: Quirky string matching problem
Message-Id: <657olp$fee$1@newbabylon.rs.itd.umich.edu>

I recently began a project involving flatfile databases for a simple
web project. The customer's hosting services doesn't provide for any
more efficient options, so I'm limited to small scripts with no background
processes. The following section of my 'search.cgi' script seems to only
work
for the 'title' attribute. I've attempted to use several different
methods, and
all of my colleagues and I agree that this certainly should work:

   if( (($data{'last'} ne "") && ($last =~ /$data{'last'}/) ) ||
       (($data{'title'} ne "") && ($title =~ /$data{'title'}/) ) ||
       (($data{'category'} ne "") && ($category =~ /$data{'category'}/) )
)

The goal is to have any matches show. If anyone has any suggestions as
to why this doesn't work, and any ideas on ways that would, please
respond or email me.

Thank you,
Eddie Toon (etoon@asdweb.com)


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

Date: Sat, 22 Nov 1997 17:56:23 -0800
From: Jim Bowlin <bowlin@sirius.com>
Subject: Re: ref to typeglob and filehandles
Message-Id: <34778D47.458F7793@sirius.com>

Charles DeRykus wrote:

> That was a nice feature. Could you live with a "no strict" block:
> 
> 
>   sub process {
>      my $file = shift;
>      { no strict;
>        open($file, $file) or croak "open failed: $!";
>        while (<$file>) {
>           ...
>      }
> 

Thanks for the response.  There are two problems with this:

1) I am using the same routine to read from a socket and from a file so 
I _have_ to pass a file handle to process().  In fact I am currently passing 
a string containing 'process' to a routine that creates an open socket so that 
I can timeout in case the socket stops sending me data. 

2) The no strict block is pretty darn big and complicated. If it were a choice
between having the system echo filenames on error and compiling the block
strictly, then
I would choose to give up the filename echo and keep my code strict.

I will take your response as a vote that it can't be done.  

Thanks again, Jim Bowlin


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

Date: 22 Nov 1997 23:28:08 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: ref to typeglob and filehandles
Message-Id: <m2vhxk6xpj.fsf@ono.tc.net>

Jim Bowlin <bowlin@sirius.com> writes:

> Charles DeRykus wrote:
> 

> 1) I am using the same routine to read from a socket and from a file
> so I _have_ to pass a file handle to process().  In fact I am
> currently passing a string containing 'process' to a routine that
> creates an open socket so that I can timeout in case the socket
> stops sending me data.
>
> 2) The no strict block is pretty darn big and complicated. If it
> were a choice between having the system echo filenames on error and
> compiling the block strictly, then I would choose to give up the
> filename echo and keep my code strict.
> 
> I will take your response as a vote that it can't be done.  

How about this: 

[requires 5.004 for the IO:: stuff]

When you open a data source (file or socket), create an anonymous
array containing an IO::Handle and a descriptive string, and take a
ref to it--something like this (stolen from the IO::Socket manpage):

$datasource = [IO::Socket::INET->new(PeerAddr => 'www.perl.org',
                                 PeerPort => http(80),
                                 Proto    => 'tcp'),
               "Socket to www.perl.org:80"];
warn "Socket error: $!\n" if not defined ${$datasource}[0];

Use IO::File->new when you need to open a file instead of a socket.
Pass this ref to your process() routine:

process($datasource);

 ...

sub process {
  my $dsrc = shift;
  my ($fh, $name) = @$dsrc;
  my $bytesread = $fh->sysread($buf, 255) or 
    warn "Error reading from $name: $!\n";
  print "Read $bytesread bytes from $name.\n";
  # etc etc etc
}

Eh?  Looks pretty clean to me, and should run under 'use strict'. 

-Doug
-- 
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";


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

Date: 23 Nov 1997 01:52:08 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Regex for three equal characters
Message-Id: <880249844.222361@cabal>

In <34718702.E20CA18@siemens.ch> Markus Bubendorf <markus.bubendorf@siemens.ch> writes:

>I'm looking for a regex which matches three or more consecutive equal
>characters. Any ideas?

/(.)\1\1/ should do it.




--
Please excuse my spelling as I suffer from agraphia see the url in my header. 
Never trust a country with more peaple then sheep. I do not reply to mungged 
Support NoCeM http://www.cm.org/                   addresses.  
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: Sat, 22 Nov 1997 18:25:25 -0700
From: autopen@autopen.com (Laurel Shimer)
Subject: security questions
Message-Id: <autopen-2211971825250001@dynamic12.pm03.mv.best.com>

I know this is Unix/cgi related but I think it is also perl related. So
please don't give me that message you send the 'not-trying-to-think
zombies'! I've been trying to use my brain as much as possible. Note: I
have also been looking in newsgroup faq's as much as I can think to. No
doubt this is somewhere in one and some kind soul will point me to it.

I have been working on setting up (multiple levels) of security on an
internal web application. My unix skills are so- so. I'm ok with basic
commands and shell scripting but often use the wrong approach (my
background is mainframes and minis and I sometimes tend to think wrong and
look up the wrong words).

I recently realized that I was having a problem because likely the perl
procedures, or as someone kindly explained to me in email

"The proper file permission settings are very much system specific.  The goal of
the script is to provide file access (through perl) which is disallowed by the
http server directly.  If you are
having problems, it is probably because perl and the http server are operating
with the same UID, meaning that you cannot set permission settings that can
differentiate between perl and the http server.  There are a few ways around
this.  The easiest way is to open up permission settings so that perl can have
access, but dissallow the servers access through an .htaccess file.  If your
server does not use this sort of thing, you can also set the uid that the
script runs with using the chown command, or you can run the script as the
owner with cgi-wrap.

Chown sets the uid of the script.  Some http servers set a default uid for
scripts that are launched by the server, often to user "nobody", so that the
script doesn't have any rights.  If you set the uid of the perl script to the
owner, with the chown command, it will cause the running perl script to have
owner rights.  This means that you could give files fewer permission settings,
perl could read the files, but the http server could not.
"

* I did figure out how to use an .htaccess file - but then realized since
this was an INTERNAL web application that it didn't provide much security.
(Too bad my brain didn't think of that earlier!)

So I've been trying to figure out how to use chown - because it sounds
less awe inspiring than a C procedure. At least I have a UNIX book that I
can look in for chown. I've been looking in the book and got the
impression I should try using the sticky bit. But I have a feeling I may
be barking up the wrong tree entirely.


 I attempted to set permissions for the directories and file I wanted the
perl procedures to access using the sticky bit. Is this even the right
approach? Anyway it didn't seem to work

1) I only saw the sticky bit show up for directories. Not for files (see
permissions log below)

2) My test bombed anyway. The procedure runs okay when the file
permissions are set as 775 but when set as shown below I get an 'unable to
open file' message - as I might expect if a perl scrirpt invoked from the
web just couldn't get access.

Am I'm barking up the wrong tree?

Woof.

Laurel

------ Permissions log-----


jam% ls -l
total 16
-r--------   1 laurel       1099 Nov 20 16:18 html-ex1.html
-r--------   1 laurel       1269 Nov 20 16:18 html-ex2.html
drw-------   2 laurel       4096 Nov 21 12:23 normal
drw-------   2 laurel       4096 Nov 21 12:22 special
jam% chmod 1400 *.html  

HUMM DON'T SEE STICKY BIT 

jam% ls -l
total 16
-r--------   1 laurel       1099 Nov 20 16:18 html-ex1.html
-r--------   1 laurel       1269 Nov 20 16:18 html-ex2.html
drw-------   2 laurel       4096 Nov 21 12:23 normal
drw-------   2 laurel       4096 Nov 21 12:22 special
jam% cd ..
jam% ls -l
total 16
 
drwx-----t   4 laurel       4096 Nov 21 12:21 Secure-html
 

jam% chmod 1400 Secure-html
 
dr-------t   4 laurel       4096 Nov 21 12:21 Secure-html
 HERE THE STICKY BIT SHOWS - BECAUSE IT'S A DIRECTORY?
jam% cd ..
 
jam% chmod 1600 Secure-WWW
jam% ls -l
total 4
drw------t   6 laurel       4096 Nov 20 16:16 Secure-WWW
 AND HERE THE STICKY BIT SHOWS ALSO, ANOTHER  DIR


jam%

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
         http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
 Did you miss? The Pigeon, A St.John Bathshirker Mystery
    http://www.autopen.com/pigeon.shtml


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

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

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