[10864] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4465 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 20 06:26:51 1998

Date: Sun, 20 Dec 98 03:00:19 -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, 20 Dec 1998     Volume: 8 Number: 4465

Today's topics:
    Re: bless Perl objects or references <rakesh_puthalath@hotmail.com>
    Re: bless Perl objects or references (Mark-Jason Dominus)
    Re: glob() returns empty list <ebohlman@netcom.com>
        How do I catch this eval exception? (Maurice Aubrey)
    Re: How do I create a password protected web site <rich_guy@hotmail.com>
        How to get start ? Help <ex5316@netvigator.com>
    Re: How to get start ? Help <rich_guy@hotmail.com>
        I must be blind... <trent@jps.net>
        Is it possible with perl? <khw101@chollian.net>
    Re: numbers in base 36 <uri@sysarch.com>
        Quick Substitution Question <jesse@savalas.com>
        Regular expressions <jmaas@execpc.com>
    Re: Regular expressions <rra@stanford.edu>
    Re: Regular expressions (Mark-Jason Dominus)
    Re: Regular expressions <ebohlman@netcom.com>
        replacement question <groans@mailexcite.com>
    Re: Retrospective on comp.lang.perl.moderated? <rra@stanford.edu>
    Re: Retrospective on comp.lang.perl.moderated? <rhodri@wildebst.demon.co.uk>
        trouble with a script <bergerac@maxisp.com.au>
    Re: trouble with a script (John Moreno)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sun, 20 Dec 1998 12:44:59 +0800
From: Rakesh Puthalath <rakesh_puthalath@hotmail.com>
Subject: Re: bless Perl objects or references
Message-Id: <367C80CA.5D46AEA0@hotmail.com>

Thanks BenJamin for responding and giving an appropriate example. But still I
think I am going wrong somewhere. Let me try to explain my case:

  $a = {};
  $b = $a;
  bless $a, BLAH;
  print "\$b is a ", ref($b), "\n";

This reports $b as being a BLAH, so obviously bless()
                                                          ^^^^^^^^^^^^^^^
 operated on the object and not on the reference.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What would have been a hypothetical output for the above print statement , if
we negate the above statement ie :
bless() had not  operated on the object, instead on the reference.
 

Thanks
Rakesh

BenJamin Prater wrote:

> Rakesh,
>
> Blessing an object simly means that Perl now knows where it belongs.
>
> It's like giving (or blessing) the object with an additional knowledge of
> where it comes from.
>
> My name is BenJamin, and suppose I was blessed a Catholic. Whenever you run
> BenJamin, you know that you should use the Catholic module, because in this
> instance, that's the faith I belong to. (I feel compeled to note that I'm
> not Catholic). That's what blessing does.
>
> Ref simply tells you how the bless worked out.
>
> BenJamin

 



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

Date: 20 Dec 1998 01:12:20 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: bless Perl objects or references
Message-Id: <75i4g4$l90$1@monet.op.net>

In article <367C80CA.5D46AEA0@hotmail.com>,
Rakesh Puthalath  <rakesh_puthalath@hotmail.com> wrote:
>Thanks BenJamin for responding and giving an appropriate example. But still I
>think I am going wrong somewhere. Let me try to explain my case:
>
>  $a = {};
>  $b = $a;
>  bless $a, BLAH;
>  print "\$b is a ", ref($b), "\n";
>
>What would have been a hypothetical output for the above print statement , if
>bless() had not  operated on the object, instead on the reference.

$a and $b both refer to the same underlying object, which is an empty
hash.  $a appeared in the `bless' statement, but $b did not.

If the `bless' applied directly to the reference, $a would be blessed,
and $b would not.  Because $b was still unblessed, `ref $b' would
yield the empty string.  The output would have been

	$b is a

with nothing on the end.

However, the blessing doesn't apply to $a or to $b, but rather to the
underlying hash to which they refer, so the output is actually `$b is
a BLAH'.



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

Date: Sun, 20 Dec 1998 07:30:10 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: glob() returns empty list
Message-Id: <ebohlmanF4966A.8E3@netcom.com>

roger-spamfree@sinasohn.com wrote:
: I have a CGI script that works fine locally and on a couple of Unix boxen,
: but when installed in the cgi-bin directory on my server, returns an empty
: list from the glob() function.  

: Icut out everything but the glob() and it runs with no errors, but the
: glob() doesn't find any files.  Other scripts in the same directory also
: run fine (but this is my first pgm using glob()).

: The directory is rwxr-xr-x, as is the program.  My ISP has been
: spectacularly unhelpful (web page coming soon) in even telling me what
: operating system I'm dealing with.  After nearly a month, they finally
: admitted that it might be a unix system running BSDi 3.0.

In all the implementations of Perl that I'm aware of, glob() (and the <*>
operator) works by spawning a separate program (e.g. the shell under Unix)
to build the list of files.  Is it possible that that program isn't on
your path, or that the user the HTTP server runs as doesn't have
permission to execute it (servers often run as extremely "underprivileged"
users for security reasons)? 

Those last two questions are really moot, because you can always use
opendir(), readdir(), etc. in conjunction with pattern matching and the
file test operators (and possibly the File::Find module) to build a list
of filenames without spawning subprocesses.  For a CGI application, this
will be faster and will reduce server load, as well as be more robust
(some shells have a limit on the number of filenames they'll glob, whereas
the do-it-yourself method is limited only by available virtual memory). 



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

Date: Sun, 20 Dec 1998 04:01:57 GMT
From: maurice@hevanet.com (Maurice Aubrey)
Subject: How do I catch this eval exception?
Message-Id: <slrn77otlo.n3v.maurice@we-24-130-58-139.we.mediaone.net>

This script:

#!/usr/bin/perl
$code = q( use strict; $try = 'foo' );
eval $code;

produces:

[maurice@we-24-130-58-139 www]$ ./eval
Global symbol "$try" requires explicit package name at (eval 1) line 1.    

How can I catch that exception?

Thanks.

- Maurice


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

Date: Sat, 19 Dec 1998 23:18:01 -0800
From: Ryan <rich_guy@hotmail.com>
Subject: Re: How do I create a password protected web site
Message-Id: <367CA4A9.E24@hotmail.com>

stan232@yahoo.com wrote:
> 
> please email me
> short stories
> www.freeyellow.com/members2/kkkkkk
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

Uhh... *pause*....  no!


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

Date: Sun, 20 Dec 1998 14:38:21 +0800
From: Free Stuff <ex5316@netvigator.com>
Subject: How to get start ? Help
Message-Id: <367C9B5D.8B18B201@netvigator.com>

I'm a very beginner.
I have a question, please help
I'll apply a virtual hosting service next week, so I'll learn Perl
Language to write the cgi
But I don't know how to get start!
My first question is :
1. Do I need to install a Perl language software in my computer to write
the program
Thank you
Alex



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

Date: Sat, 19 Dec 1998 23:15:37 -0800
From: Ryan <rich_guy@hotmail.com>
Subject: Re: How to get start ? Help
Message-Id: <367CA419.17CF@hotmail.com>

Free Stuff wrote:
> 
> I'm a very beginner.
> I have a question, please help
> I'll apply a virtual hosting service next week, so I'll learn Perl
> Language to write the cgi

Or you can use one of many other languages to write for cgi. :-)

> But I don't know how to get start!

http://www.perl.com has all the links and links of links, and faq's and
faq's of faq's..,. and on and on! Books: O'Reilly, Learning Perl,
Programming Perl, Perl Cookbook (The O'Reilly one!).

> My first question is :
> 1. Do I need to install a Perl language software in my computer to write
> the program

Not to write it. You can use Notepad for writting. To run it however,
you'll need perl installed.

> Thank you
> Alex

No problem.
Ryan.


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

Date: Sun, 20 Dec 1998 07:28:23 GMT
From: Trent <trent@jps.net>
Subject: I must be blind...
Message-Id: <367CA7FE.B7E@jps.net>

I know I'll take a beating for the unchecked opens etc.... but I'll ask
anyway. I'm trying (unsuccessfully) to push a new user into a text file,
but I have screwed up the the textbook example somehow.... I've tried a
while (<>) loop etc. to no avail.

Any clues large or small appreciated. Except that complete car reference
witht the ingear(), push() yada yada yada.....

---------------- SNIPPET --------------------
open(READ,$filename);
open(TEMP,">$tempfile");
flock (TEMP, $EXCLUSIVE);
@lines = <READ>;
	
push(@lines, $newuser);  # everything works fine but this line!!
	
print TEMP @lines;
flock (TEMP, $UNLOCK);
close(READ);
close(TEMP);
unlink($filename);
rename($tempfile,$filename);

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


Thanks, and Happy Holidays
Trent


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

Date: Sun, 20 Dec 1998 15:32:19 +0900
From: "Ys_Kim" <khw101@chollian.net>
Subject: Is it possible with perl?
Message-Id: <rZ0f2.412$Zp4.375@news.bora.net>

Is it possible to submit a form to multiful cgi scripts at the same time
and each script located in different places?
I'm making an web site which automatically cross-post messages
from the site to 5 different sites's message boards at the same time.
I saw the similar scripts which help registering my homepage to
serveral search engine.
But They have many submit buttons in a page for the search engines
and I had to click on all submit buttons.
Is it possible to post messages to several places at the same time
automatically by just one clicking?
Any good advice will be highly appreciated.

Yong




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

Date: 20 Dec 1998 00:24:58 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: numbers in base 36
Message-Id: <x7soebl711.fsf@sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

  RLS> Well, here's a hack that just dawned on me:

  RLS>     sub base36_to_dec {
  RLS>       my $x = shift;
  RLS>       $x =~ tr/0-9a-zA-Z/\x00-\x09\x0a-\x23\x0a-\x23/d;
  RLS>       my $y = 0;
  RLS>       for (unpack "C*", $x) {
  RLS> 	$y = $y * 36 + $_;
  RLS>       }
  RLS>       $y;
  RLS>     }

i am surprised that you didn't follow the rest of the thread and make
this a general purpose routine. all you have to do is take the base as
an argument and use it instead of the 36. it doesn't do any error
checking but none of the other entries do either.

and yours is much faster than matt's or my speedup of his.

Benchmark: timing 4096 iterations of matt, randal, uri...
      matt:  6 secs ( 6.37 usr  0.00 sys =  6.37 cpu)
    randal:  4 secs ( 3.60 usr  0.00 sys =  3.60 cpu)
       uri:  6 secs ( 5.44 usr  0.00 sys =  5.44 cpu)

my change to yours was just adding $base

sub base_to_dec {
	my $base = shift ;
      my $x = shift;
      $x =~ tr/0-9a-zA-Z/\x00-\x09\x0a-\x23\x0a-\x23/d;
      my $y = 0;
      for (unpack "C*", $x) {
	$y = $y * $base + $_;
      }
      $y;
    }


is the unpack the fastest way to get at chars in a string from left to
right? i think my chop might be the fastest from right to left but maybe
a substr could do it better.

	while( $c = chop $number, length( $c ) ) {

try hacking the other way randal, decimal to base!

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sun, 20 Dec 1998 07:53:38 GMT
From: Jesse Rosenberger <jesse@savalas.com>
Subject: Quick Substitution Question
Message-Id: <367CACE0.ADE0950A@savalas.com>

Okay let's say we've got:

$textstring = "$4Rat$.%23%";

Now, what do we need to run that string through to get:

$textstring = "4.23";

I know you can do a:

$textstring =~ s/\D//g;

But that just gives you "423".

What can be done to keep the period (and only the period) in there along
with the numbers?

Thanks in advance,
Jesse


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

Date: Sat, 19 Dec 1998 23:52:38 -0600
From: John Maas <jmaas@execpc.com>
Subject: Regular expressions
Message-Id: <75i3aj$4gq@newsops.execpc.com>

I am new to Perl and I've come across something that doesn't make any
sense to me.

Using $test = "this.is.it";

$test =~ /.*\.//; #produces "it", while

$test =~ /\..*// #produces "this".

What I can't understand is how can it be consistent for one expression
to match on the first period while the second expression matches on the
second period? What I am thinking of here is the string being evaluated
from left to right, and expecting the match to take place when the first
possible match occurs. How can this happen in one instance and not the
other?

    -John



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

Date: 19 Dec 1998 23:00:45 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Regular expressions
Message-Id: <ylu2yrfgbm.fsf@windlord.stanford.edu>

John Maas <jmaas@execpc.com> writes:

> I am new to Perl and I've come across something that doesn't make any
> sense to me.

> Using $test = "this.is.it";

> $test =~ /.*\.//; #produces "it", while

> $test =~ /\..*// #produces "this".

I assume you wanted s's before those first slashes, if you're doing
substitution.

> What I can't understand is how can it be consistent for one expression
> to match on the first period while the second expression matches on the
> second period? What I am thinking of here is the string being evaluated
> from left to right, and expecting the match to take place when the first
> possible match occurs. How can this happen in one instance and not the
> other?

Because Perl regular expressions are not evaluated globally; they're
evaluated locally.  In other words, to think like the regular expression
engine, you need to look at the *smallest* portion of the expression you
can.

Starting with the second one, because it's easier, the first thing it
tries to match is a literal period.  So the engine goes along in the
string until it can match a literal period, finding the first one, and
then considers that part done.  It then goes on to try to match any amount
of anything, matches the whole rest of the string with that, considers
itself successful, and finishes.

Now for the first one, the engine sees "match any amount of anything" and
since it's greedy, it proceeds to match the entire string.  It then moves
on to see that it needs to match a literal period, but it's out of
characters to match, so now it backtracks until it can match.  The least
amount of backtracking required to cause a match is backing up to the
second period and matching there.  So that's what it does.

The book _Mastering Regular Expressions_ from O'Reilly is a great resource
on how this stuff works.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 20 Dec 1998 01:58:38 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Regular expressions
Message-Id: <75i76u$naj$1@monet.op.net>

In article <75i3aj$4gq@newsops.execpc.com>,
John Maas  <jmaas@execpc.com> wrote:
>Using $test = "this.is.it";
>$test =~ s/.*\.//; #produces "it", while
>$test =~ s/\..*// #produces "this".

The regex engine is like a little machine executing a search program.
When it has a choice of how to looks for something, it tries one way,
and if that doesn't lead to a match, it backs off and tries again.

Here's a simple example first:

	"Plover" =~ /l.*e/;

First, it starts at the `P' and tries to match it with the `l'.  That
fails right away, so it tries a different alternative: it tries
starting at the `l' and matching it with the `l'.  That works.

Then it tries matching the .* against something.  It has many choices.
Which does it try first?  The rule is simple:  it tries the longest
ones first, and works its way back to the shortest.  So first it tries
matching the .* against `over'., but that leaves nothing on the end of
the string to match the `e'.  So it backs off and tries assigning a
shorter string to `.*'; it lets .* match against the `ove'.  Then it
tries matching the `e' in the regex against the `r' in the string, and
that fails.  So it backs off again and lets the .* match just `ov'.
Then the `e' in the regex matches the `e' in the string. 

That is the end of the regex, so the match is successful.  The regex
engine found the following correspondence:

	P  l  ov  e  r
          /l  .*  e/

The important point here is that it had to try several alternatives,
and it tries them in a certain order.  It tries looking for the
pattern at the leftmost part of the string first, and tries to find a
way to make the pattern match; if none of those ways work, it moves
over to the right and tries again.  When it wants to match something
to .*, it tries making .* eat up the whole rest of the string, and
then if that doesn't work, it backs off, making .* match shorter and
shorter strings, looking for one that makes the following part of the
regex work.

Now let's see your example.  I'm going to change the dots to hyphens
to make them easier to see.

>Using $test = "this-is-it";
>$test =~ s/.*-//; #produces "it", while

The first thing it tries is to make the .* match all of `this-is-it',
but that doesn't work, because it leaves no - at the end for the - to
match.  So it backs off one character and tries with .* matching
`this-is-i', but the `t' that remains on the end still won't match -.
So it tries again with .* matching `this-is-', and that leaves `i' to
match the -, and that doesn't work.  So it backs off once more and
tries matching the .* to `this-is' and then the - matches the - in the
regex just fine, so the match succeeds:

	 .*	this-is
	 -	-

The entire matched string is `this-is-'; the part that's unmatched is
`it'.  Since s/// says to remove the matched part, all that's left is
`it'.

>$test =~ s/-.*// #produces "this".

Now here the first thing it tries to do is match the - to the `t' at
the beginning of `this-is-it', but hyphens and t's are not the same,
so that doesn't work, and it moves over one character and tries
starting at the `h'.  But it can't match there either, and it moves
over again, until eventually it gets to the - between `this' and `is'.
it is going left to right, so it gets to the leftmost hyphen first and
matches it to the - in the regex.

Then it needs to match the .* to something, and, as usual, it makes it
match as much as possible, everything after the first hyphen, up to
the end of the string.  That's the end of the regex, so the match is
successful, and the correspondence was:

	-	-
	.*	is-it

So the matched string is `-is-it'.  The unmatched part that is left
over after the substitution is `this'.

Now you might like to see what hjappens when you try this:

	$string = "I <em>said</em> I don't <em>like</em> oysters.";
	$string =~ s/<em>.*<\/em>//;

There is a version of the * operator that tries the alternatives
in reverse order, from shortest to longest, instead of starting with
the longest; it's written 

	.*?	instead of	.*

People sometimes say that the .* is `greedy', because it always takes
as much as it can, whereas .*? takes only as much as it needs.

Also see http://www.plover.com/~mjd/perl/Regex/.



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

Date: Sun, 20 Dec 1998 07:56:09 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Regular expressions
Message-Id: <ebohlmanF497DM.9AJ@netcom.com>

John Maas <jmaas@execpc.com> wrote:
: Using $test = "this.is.it";

: $test =~ /.*\.//; #produces "it", while

: $test =~ /\..*// #produces "this".

I'm assuming that your real code was "$test =~ s/..."; quite a few people 
here recommend that posters always cut-and-paste code into their postings 
rather than retyping it, in order to avoid confusion like this.

: What I can't understand is how can it be consistent for one expression
: to match on the first period while the second expression matches on the
: second period? What I am thinking of here is the string being evaluated
: from left to right, and expecting the match to take place when the first
: possible match occurs. How can this happen in one instance and not the
: other?

In the first example, your '.*', being greedy, would gobble up your whole
string if it were used alone.  But because you put a literal character
(period) after it, it can't gobble the whole string because there's no
period at the end of the string.  Therefore, it quits gobbling right 
before the last period in the string (which is then gobbled by your 
literal period).

In the second example, your '.*' isn't even allowed to start gobbling 
until the regex engine has found a literal period in the string.  From 
there, it gobbles to the end, since there's nothing more in your regex to 
stop it.

I mentioned that '.*' is "greedy."  That means that it will match the 
*longest* sequence of characters that it can while letting the rest of 
the pattern match.  It *doesn't* stop at the first possible match.  You 
can make it do that (match the *shortest* sequence of characters that 
will allow the rest of the pattern to match) by putting a '?' after it.

Greedy vs. non-greedy matching is discussed in the perlre (pod file | man 
page | HTML document) that came with your copy of Perl.  It's worth 
reading several times, since it's the definitive explanation of how 
regular expressions work in Perl, and using regular expressions is a 
fundamental part of Perl programming.



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

Date: Sat, 19 Dec 1998 23:59:30 -0800
From: me <groans@mailexcite.com>
Subject: replacement question
Message-Id: <367CAE61.7B5BA3FC@mailexcite.com>

I am sort of up a creek.  A while back I wrote a proxy server in Perl.
This is different than Mr. Schwartz's because I could not get that
version to work with the Perl Modules.  Anyhow, this one does not
require any modules, and it works fine, except to use it one has to
configure their browser to talk to the proxy first.  Big deal right?
Well the problem is when someone is already behind a proxy accessing the
net, and still wants to use the proxy.  It can't work because their
browser would have to be able to talk to two proxies.
ANYHOW.  What I wanted to do was make it work like the anonymizer, so
that all they would need to do is type in an address into a text field
on a web page, and viola.  Now I already have a redirect script so that
is fine.  Now all I need to do is get my proxy to replace all of the the
links on each of the pages it sends me with:

(the proxy's address) + (the root address of the server I want the page
from) + (the path of the file)

This tricks the browser into talking to my proxy before it talks to the
target server.  I have been trying to do this with pattern matching with
little luck.  Does anyone have any suggestions?  Am I doing this the
hard way?

~Prime




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

Date: 19 Dec 1998 19:52:40 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Retrospective on comp.lang.perl.moderated?
Message-Id: <ylzp8jh3lj.fsf@windlord.stanford.edu>

birgitt <birgitt@my-dejanews.com> writes:

> But I wonder, if the amount of time, effort and nerves which goes into
> creating and maintaining a moderated group within the current system, is
> not too high.

Hitting S D p in my mail reader a couple times a day after reading an
article I would have read anyway, occasionally writing a quick note to
someone explaining why they have the wrong newsgroup, and even more
occasionally tuning a script or two is not much in the way of time,
effort, and nerves.  The group is running fairly smoothly at this point.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 19 Dec 1998 22:06:26 +0000 (GMT)
From: Rhodri James <rhodri@wildebst.demon.co.uk>
Subject: Re: Retrospective on comp.lang.perl.moderated?
Message-Id: <48b7173c4drhodri@wildebst.demon.co.uk>

In article <MPG.10e2d95848e744bd989963@nntp.hpl.hp.com>,
   Larry Rosler <lr@hpl.hp.com> wrote:
> With year-end-assessment time rapidly approaching, would anyone care to 
> comment on how comp.lang.perl.moderated has performed over its life of 
> six months or so, relative to the hopes and expectations of its 
> proponents?

Well, I'd have to give it the thumbs up.  clp.mod is exactly what I had
been wanting; a newsgroup about Perl that has informed comment,
illuminates some of the odd corners that I bang my head in regularly, and
has a volume low enough not to overwhelm my poor little phone line.

-- 
Rhodri James  *-*  Wildebeeste herder to the masses
If you don't know who I work for, you can't misattribute my words to them

 ... I have too much time on my hands.  Let's run another convention.


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

Date: Sun, 20 Dec 1998 14:59:10 +1030
From: Kingsley Foreman <bergerac@maxisp.com.au>
Subject: trouble with a script
Message-Id: <367C7D16.5A90569D@maxisp.com.au>

I have this script that i wrote

it works for perl win32 but won't work under lynix

its log has

[error] Premature end of script headers: /usr/lib/cgi-bin/table.pl

can someone who nows have a look and tell me what im doing wrong

the script is

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

#!/usr/bin/perl


  $PAGENAME ="Heading.txt";
  $querystring = $ENV{'QUERY_STRING'};
  $basedir = "/home/bergerac/Public_html/";   # base directory where to
find the text file
  $querystring =~ tr/+/ /;

  ($filename,$query) = split(/\s*\,\s*/,$querystring,9);

  $filename =~ s/\|//g;
  $filename =~ s/\<//g;
  $filename =~ s/\>//g;
  $filename =~ s/\+//g;
  $filename =~ s/\\//g;
  $filename =~ s/\///g;


    &open_file("FILE1","","$basedir$filename");
    $counter = 0;

    print "Content-type: text/html\n\n";
    print "<HTML>\n";
    print "<HEAD>\n";
    print "<META HTTP-EQUIV=Content-Type CONTENT=text/html;
charset=windows-1252>\n";
    print "<TITLE>Australian Music Links $query</TITLE>\n";

open (INDEX,"$basedir$PAGENAME");
while (<INDEX>) {print; }
close (INDEX);


    &open_file("FILE1","","$basedir$filename");
    $counter = 0;

    while (($line = &read_file("FILE1")) && ($counter < 100)) {
         # split the fields at the | character
         @tabledata = split(/\s*\|\s*/,$line ,$fields);

       #see if first field matches query
       if ($tabledata[0] =~ /^$query$/i) {
          print "<TR>\n";

          for ($x=1) {
              print "<TABLE WIDTH=770 col=2><TD width=50%><A
HREF=$tabledata[2] TARGET=_top><b><FONT SIZE=2>$tabledata[1]</TD>\n";
              print "<TD width=50%><b><FONT
SIZE=2>$tabledata[2]</TABLE>\n";
         }


         $counter++;
       }
    }
    close(FILE1);
    if ($counter == 0) {
       print "<B> Sorry, No Matches were found.</B>\n";
    }
    if ($counter == 100) {
       print "<BR><B>Only 100 matches have been retrieved, you may want
to add more keywords to narrow your search.</B>\n";
    }

    print "</TABLE>\n";
    print "</CENTER>\n";
    print "</BODY></HTML>\n";



sub open_file {

  local ($filevar, $filemode, $filename) = @_;

  open ($filevar,$filemode . $filename) ||
     die ("Can't open $filename");
}

sub read_file {

  local ($filevar) = @_;

  <$filevar>;
}

sub write_file {

  local ($filevar, $line) = @_;

  print $filevar ($line);
}




--
**************************************************

Australian Music Links

http://203.38.204.200/

**************************************************
Kinglsey Foreman




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

Date: Sun, 20 Dec 1998 01:06:11 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: trouble with a script
Message-Id: <1dkb95b.tgaueunis3jN@roxboro0-040.dyn.interpath.net>

Kingsley Foreman <bergerac@maxisp.com.au> wrote:

> I have this script that i wrote
> 
> it works for perl win32 but won't work under lynix
> 
> its log has
> 
> [error] Premature end of script headers: /usr/lib/cgi-bin/table.pl
> 
> can someone who nows have a look and tell me what im doing wrong
> 
> the script is
> 
> 
> #!/usr/bin/perl

Here's at least one big mistake: not using -w

-snip-
> 
>           for ($x=1) {
>               print "<TABLE WIDTH=770 col=2><TD width=50%><A
> HREF=$tabledata[2] TARGET=_top><b><FONT SIZE=2>$tabledata[1]</TD>\n";
>               print "<TD width=50%><b><FONT
> SIZE=2>$tabledata[2]</TABLE>\n";
>          }
-snip-

I'd suggest that there is a problem with this for loop
> --
> **************************************************
> 
> Australian Music Links
> 
> http://203.38.204.200/
> 
> **************************************************
> Kinglsey Foreman

And I'd ask that you add a space after the two dashes -- when looking
for the sigdash newsreaders look for the something which matches the
regex /\n-- \n/ and leaving it out prevents them from finding it.

-- 
John Moreno


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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