[7959] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1583 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 5 21:17:30 1998

Date: Mon, 5 Jan 98 14:00:31 -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           Mon, 5 Jan 1998     Volume: 8 Number: 1583

Today's topics:
     Re: **1A Please Help, Perl is harrassing me ** (Matthew Cravit)
     Re: @ARGV variabele looses its contents (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     a documentation of all installed modules (perl/lib) by  <pmp@egnetz.uebemc>
     AIX 3.2.5: perl 5.004 'make test' fails on dlopen (Pat Wilson)
     Beginning Perl Tutorial - Boulder, CO <johnd@xor.com>
     Re: Calling 'require' on an arbitrary module (M.J.T. Guy)
     database <Johncarryl@Sprintmail.com>
     Re: database <rootbeer@teleport.com>
     Form input perl program passing parameters to another b <shulin@wwave.com>
     Re: Hashes - Heres my try, can you help me to tidy it u (Lozano Mosterin, Jesus)
     Re: Help please... <jdporter@min.net>
     Help with passing parameters in URL's please <vfox@nbnet.nb.ca>
     I'm new and apparently I suck, help me please. (S.B.)
     Re: I'm new and apparently I suck, help me please. (S.B.)
     Re: I'm new and apparently I suck, help me please. <Brian.Ewins@gssec.bt.co.uk>
     Re: IIS4, Perl and HTTP headers <rootbeer@teleport.com>
     Re: Integrating perl's regex functionss into other pack <*@qz.to>
     Re: Is there a random function <rootbeer@teleport.com>
     Lexical scope and embedded subroutines. <steveg_nospam@gcg.com>
     Re: Lexical scope and embedded subroutines. <ldanna@hotmail.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 5 Jan 1998 09:21:19 -0800
From: mcravit@best.com (Matthew Cravit)
Subject: Re: **1A Please Help, Perl is harrassing me **
Message-Id: <68r4qf$dh$1@shell3.ba.best.com>
Keywords: just another new york perl hacker

In article <comdog-0501980449090001@news.panix.com>,
brian d foy <comdog@computerdog.com> wrote:

>   s/@/\@/g;

That doesn't quite do it, though, since backslashes are special on both
sides of the regexp. I'm sure what you meant to write was:

    s/@/\\@/;

which behaves as you'd intended.

/MC

-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: Mon, 05 Jan 98 13:12:30 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: @ARGV variabele looses its contents
Message-Id: <34b1244e$1$ofn$mr2ice@speaker>

In <34AEB14F.CEB81E5A@tip.nl>, on 01/03/98 at 10:44 PM,
   Arno den Ridder <a.den.ridder@tip.nl> said:
+-----
| After entering a sub my @ARGV variabele looses its contents.
> ( . . . )
|     #script name.pl
|     sub analyse {
|         print "test2 : $filename\n";
|         while (<>) {
|             $nr_lines++;
|         }
|     }
+--->8

See section "I/O Operators" in "perldoc perlop".  The <> construct removes
filenames from @ARGV as it uses them.

-- 
use 5.004;sub AUTOLOAD{print$_{$_.++$x{$_}}}sub new{my%x;%_=map{++$a%2?$_.++$x{
$_}:$_}split(//,pack('N*',unpack('w*',unpack('u*','M@H*HP\'2"@\C`88+SE/!EA(F!'.
"A'6\$LZV0+(3;C9QRA9NAPG2&D\\G(88:KL=A0\n4AN.5W\"\"&\\[W>;H>3S>0\@A\\N\@PB\$`")
)));bless{}}$b=(new main);map{$b->_}split(//,' Brandon S. Allbery KF8NH') # :-)



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

Date: Mon, 05 Jan 1998 19:34:46 +0100
From: Bernard Weiler <pmp@egnetz.uebemc>
Subject: a documentation of all installed modules (perl/lib) by means of CPAN.pm and manpages
Message-Id: <34B127C6.6929@egnetz.uebemc>

Hi,

I installed PERL5.004_04 on our workstations and 
missed an easy to use overall documentation integration 
(with a list of all installed modules of CPAN, some attributes, their
pod's ...)

As far as I know no such docu system exists apart from 'perldoc' and
CPAN's 'm' command
which allow access to only one module per call.

So, during my christmas holidays I wrote a perl script
for this task.

The script installs within .../perl/doc a dir containing all infos
(running approx. 10min).
Two of its functions aren't yet implemented.
It makes excessive use of the programming interface of CPAN.pm (Vielen
dank an Andreas Koenig !)

I'm waiting for your comments.

I'll be in vacation till 12.1.98

berni
-- 
--------------------
Name:		Bernard Weiler
Org.:		OeN TR HW A, Mch-H, Siemens AG
email: 		pmp@egnetz.uebemc (spamming, sorry
I'll be in vacation till 12.1.98! please add .siemens.de )
PGP:		the public key may be downloaded from
http://trust.sbs.de/html/med.htm
		or from pgp-public-keys@uni-paderborn.de

======================================== PerlLibInfo
#!/usr/local/bin/perl -w

# this script generates an integrated documentation of the local perl
lib.
# it requires a working CPAN module (with access to the CPAN on
internet)
# it is called without arguments.

require 5.004;
use strict;
use CPAN;
use Config;

#-- These vars have to be adapted to local installation.

my $MyName="PerlLibInfo";
my $PerlDocs="$Config{prefix}/doc";
my $MyDocs="$PerlDocs/$MyName";
# usage of 1994 Man-cgi 1.14, Panagiotis Christias
<christia@theseas.ntua.gr> 
#  at http://www.ntua.gr/~christia/man-cgi.html
my $ManpageCGI="http://gina/cgi-bin/manpages_PerlLibInfo"; #warning:
this tool requires uncommon access syntax: see usage line.

#-- start

mkdir($PerlDocs,0777) or die"$!" unless(-d $PerlDocs);
mkdir($MyDocs,0777) or die"$!" unless(-d $MyDocs);

#write table of all modules.
open(FH,">$MyDocs/index_any.html") or die"$!";
print FH GetModTable(GetModInfos(undef));
close(FH);
#write table of all installed modules.
open(FH,">$MyDocs/index_inst.html") or die"$!";
print FH GetModTable(GetModInfos(1));
close(FH);
#write table of all not installed modules.
open(FH,">$MyDocs/index_noinst.html") or die"$!";
print FH GetModTable(GetModInfos(0));
close(FH);
#write entry page.
open(FH,">$MyDocs/index.html") or die"$!";
print FH GetAllInfos();
close(FH);
exit 0;

#----- all subs

sub _PresetGetModInfos(){
  # only for testing purpose.
  my %IP;
  $IP{CGI}={};
  $IP{CGI}{DESCRIPTION}='berni';
  $IP{CGI}{MANPAGE}='gg';
  $IP{_keys}{DESCRIPTION}=0;
  $IP{_keys}{MANPAGE}=1;
  return \%IP;
}

sub GetModInfos($){
  # enlists all infos on all modules.
  # Arg: 0=mod not installed, 1=mod installed, undef=any.
  # Return: ->{modid}{infoname}=infovalue. The special modid=_keys
returns a list of all occured infoname's (for presetting a HTML table).
  my $mode=shift;
  my %ModInfos;
  $ModInfos{'_keys'}={};
  $ModInfos{'_keys'}{'_count'}=0;
  #return;
  foreach my $mod (sort CPAN::Shell->expand("Module","/./")){
    #print "berni -".$mod->id."-\n";
    #last if($mod->id=~/^[E-Z]/);
    next unless(
      (($mod->inst_file) and (defined $mode) and ($mode == 1))or
      ((not $mod->inst_file) and (defined $mode) and ($mode == 0))or
      (not defined $mode)
      );
    $ModInfos{$mod->id}={};
    foreach(split("\n",$mod->as_string)){
      my @il=split(' ',$_,2);
      $ModInfos{$mod->id}{$il[0]}=$il[1];
      $ModInfos{'_keys'}{$il[0]}=$ModInfos{'_keys'}{'_count'}++
        unless(exists $ModInfos{'_keys'}{$il[0]});
      # drop dirty formatting.
      $ModInfos{$mod->id}{Module}=~s|id = ||;
    }
   
$ModInfos{$mod->id}{INST_LAST}=scalar(localtime((stat($mod->inst_file))[9]))
if($mod->inst_file);
  }
  $ModInfos{'_keys'}{INST_LAST}=$ModInfos{'_keys'}{'_count'}++
    unless(exists $ModInfos{'_keys'}{INST_LAST});
  $ModInfos{'_keys'}{MANPAGE}=$ModInfos{'_keys'}{'_count'}++
    unless(exists $ModInfos{'_keys'}{MANPAGE});
  # shift important keys to the beginning.
  PrioKeyEntry($ModInfos{'_keys'},'INST_FILE');
  PrioKeyEntry($ModInfos{'_keys'},'MANPAGE');
  PrioKeyEntry($ModInfos{'_keys'},'DESCRIPTION');
  PrioKeyEntry($ModInfos{'_keys'},'Module');
  return \%ModInfos;
}

sub PrioKeyEntry($$){
  # shifts a key to the start of the key-list.
  # Arg: pointer to ->['_keys'}
  # Return: nothing.
  my $keyptr=shift;
  my $PrioKey=shift;
  my @il;
  my @ill;
  return if($keyptr->{$PrioKey} == 0);
  foreach(keys %{$keyptr}){$il[$keyptr->{$_}]=$_}
  foreach(0 .. ($keyptr->{$PrioKey}-1)){$ill[$_+1]=$il[$_]}
  $ill[0]=$PrioKey;
  foreach(($keyptr->{$PrioKey}+1) .. $#il){$ill[$_]=$il[$_]}
  foreach(0 .. $#ill){$keyptr->{$ill[$_]}=$_}
}

sub GetModTable($){
  # converts GetModInfos into a HTML table
  # Arg: ->{modid}{infoname}=infovalue. The special modid=_keys returns
a list of all occured infoname's (for presetting a HTML table).
  # Return: a string.
  my $ip=shift;
  my $is="<TABLE BORDER=1><TR BGCOLOR=\"yellow\">";
  my @Titles;
  foreach(keys %{$ip->{'_keys'}}){next
if(/^_/);$Titles[$ip->{'_keys'}{$_}]=$_}
  foreach(@Titles){$is.="<TH>$_</TH>"}
  $is.="</TR>";
  foreach my $mod (sort keys %{$ip}){
    next if($mod=~/^_/);
    $ip->{$mod}{MANPAGE}=$ip->{$mod}{Module}
      unless((exists
$ip->{$mod}{MANPAGE})and($ip->{$mod}{MANPAGE}=~/^\s*$/));
    # bug fix, if 03 don't contain a structure available via 02.
    $ip->{$mod}{DESCRIPTION}=$ip->{$mod}{MANPAGE} 
      if((not exists $ip->{$mod}{DESCRIPTION}) and (exists
$ip->{$mod}{MANPAGE}));
    # hook up a hyperlink with a manpage entry
    my @isl=split(' ',$ip->{$mod}{MANPAGE});
    $ip->{$mod}{MANPAGE}='';
    foreach(@isl){$ip->{$mod}{MANPAGE}.="<A
HREF=\"$ManpageCGI?$_\">$_</A> "}
    $is.="<TR>";
    foreach(@Titles){
      $is.=(exists $ip->{$mod}{$_})? "<TD>".$ip->{$mod}{$_}."</TD>":
"<TD>-</TD>"
    }
    $is.="</TR>";
  }
  $is.="</TABLE>";
  return $is;
}

sub GetAddOnDoc(){
  # to be find in lib/... as .html, .pod
  # many make install don't install all available docs, so that they
remain in the cpan_work path.
  return "<BLINK><B>Not yet implemented</B></BLINK>";
}

sub Check(){
  # checks for multiple module installations and inconsistent versions
of architecture dependent modules.
  return "<BLINK><B>Not yet implemented</B></BLINK>";
}

sub GetAllInfos(){
  # generates a complete HTML doc as result of this script.
  # Arg:.
  # Return: a string.
  return "<HTML>
    <HEAD>
      <TITLE>PERL lib documentation</TITLE>
    </HEAD>
    <BODY>
      <H1 ALIGN=\"CENTER\">PERL lib - integrated documentation</H1>
      <H2><A NAME=\"TOC\">Table Of Contents</A></H2>
        <UL>
          <LI><A HREF=\"#ModuleTable\">List of all modules</A></LI>
          <LI><A HREF=\"#AddOnDoc\">Supplementary found
documents</A></LI>
          <LI><A HREF=\"#Check\">Results from some consistency
checks</A></LI>
          <LI><A HREF=\"#Config\">List of PERL setup configs</A></LI>
          <LI><A HREF=\"#Meta\">Meta informations</A></LI>
        </UL>
      <H2><A NAME=\"ModuleTable\">List of all modules</A></H2>
      This table enlistes all CPAN modules. Several of them were
installed into the local lib.
      <P>
      <UL>
        <LI><A HREF=\"./index_any.html\">list of all modules</A></LI>
	<LI><A HREF=\"./index_inst.html\">list of all installed
modules</A></LI>
	<LI><A HREF=\"./index_noinst.html\">list of all not installed
modules</A></LI>
      </UL>
      <P>
      <H2><A NAME=\"AddOnDoc\">Supplementary found documents</A></H2>
      Beneath the regular documents of module following documents were
found that could 
      not be hooked up to a single module:
      <P>
      ".GetAddOnDoc()."
      <P>
      <H2><A NAME=\"Check\">Results from some consistency
checks</A></H2>
      This document was processed with huge help of CPAN.pm.
Supplementary to CPAN.pm the
      following shows results from
      checks for multiple module installations and inconsistent versions
of architecture dependent
      modules.
      <P>
      ".Check()."
      <H2><A NAME=\"Config\">List of PERL setup configs</A></H2>
        <PRE>".Config::myconfig()."</PRE>
        <PRE>".Config::config_sh()."</PRE>
      <H2><A NAME=\"Meta\">Meta informations</A></H2>
      this document was automaticely generated
      <P>
      <TABLE BORDER=1>
        <TR><TD>script that generated this document<TD>$MyName via
$0</TR>
        <TR><TD>script was called
at<TD>".scalar(localtime(time()))."</TR>
        <TR><TD>script was written by<TD><A
HREF=\"mailto:Bernard.Weiler\@oen.siemens.de\">Bernard Weiler</A>, TR HW
A, Siemens AG, 1.98</TR>
        <TR><TD>script version<TD>1.001</TR>
        <TR><TD>Anaysis of lib<TD>$Config{privlib}</TR>
      </TABLE>
      </BODY>
   ";
}
__END__
======================================================


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

Date: 5 Jan 1998 15:10:50 GMT
From: paw@coos.dartmouth.edu (Pat Wilson)
Subject: AIX 3.2.5: perl 5.004 'make test' fails on dlopen
Message-Id: <68qt5q$aj6$1@dartvax.dartmouth.edu>

I've crawled through the archives, but can't find the answer to
this...

System is AIX 3.2.5, using xlc.  perl 5.004 makes fine (using
'Configure -d' settings), but make test fails on the dlopen
calls with errors of the form
	Can't load '../lib/auto/IO/IO.so' for module IO: dlopen: ../lib/auto/IO/IO.so:  at ../lib/DynaLoader.pm line 155.

The .so files appear to be there, and nm shows strings - what
could be wrong, and how do I fix it?

Thanks.




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

Date: Mon, 05 Jan 1998 10:23:10 -0700
From: John Donnelly <johnd@xor.com>
Subject: Beginning Perl Tutorial - Boulder, CO
Message-Id: <34B116FE.6C40@xor.com>

**Upcoming (January '98) Tutorial**
Session is held at our training facility in Boulder, CO.
Class size is limited to 10 people.
Contact me for further information, registration forms.
--John Donnelly, Training Coordinator
  XOR Network Engineering, Inc.
  http://www.xor.com/tt  johnd@xor.com  303-448-4816
                                *****
                     Beginning Perl Programming
                  (Three Day Hands-on Lecture/Lab)
                    Tom Christiansen, Consultant
              Tuesday-Thursday, January 13-15, 1998
                                *****


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

Date: 5 Jan 1998 17:39:47 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Calling 'require' on an arbitrary module
Message-Id: <68r5t3$dps$1@lyra.csx.cam.ac.uk>

Joshua J. Kugler <jkugler@inreach.com> wrote:
>
>You could try having your subroutines after your __END__ statement in
>your Perl code. Then the routines would only be compiled if they are
>called.  I think.  You might have to double check that.

It would save lots of people round the world time if _you_ double
checked before posting incorrect information.

For information on how this can actually be done, see

       perldoc perlsub           - the section on Autoloading
       perldoc SelfLoader
       perldoc AutoLoader
       perldoc AutoSplit


Mike Guy


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

Date: 5 Jan 1998 15:52:30 GMT
From: "John Karr" <Johncarryl@Sprintmail.com>
Subject: database
Message-Id: <01bd19f1$ee706d00$370e85ce@default>


CyberPals:

I am a newbie to Perl.  So far I know how to use this language to do two
things:
* Send email with the form information
* Generate screen output to communicate with user
 
The question that I have is as follows:

How can I include a module in my Perl program to route data (submitted in a
form) to an Access database?  


Thanks,
John



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

Date: Mon, 5 Jan 1998 09:48:41 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: John Karr <Johncarryl@Sprintmail.com>
Subject: Re: database
Message-Id: <Pine.GSO.3.96.980105094757.26455E-100000@user2.teleport.com>

On 5 Jan 1998, John Karr wrote:

> How can I include a module in my Perl program to route data (submitted
> in a form) to an Access database? 

You use 'use', documented in the perlfunc manpage. If you're trying to
find a suitable module, check the modules list from CPAN. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Mon, 05 Jan 1998 16:28:56 -0500
From: Shulin Dave <shulin@wwave.com>
Subject: Form input perl program passing parameters to another background precess?
Message-Id: <34B15098.446B@wwave.com>

Hi guys,
	I have written state engine for an application in perl. Everytime there
is a hit on the website it executes the whole script again. If I can get
the input seperate & pass to the main state engine all the parameters
that would reduce my memory usage as well as time.

I was wondering is there any simple example which I should look for? I
am not using modules. 

Thanks in advance
dave


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

Date: 5 Jan 98 17:09:46 +0100
From: lozano@opalo.etsiig.uniovi.es (Lozano Mosterin, Jesus)
Subject: Re: Hashes - Heres my try, can you help me to tidy it up !
Message-Id: <8N8ATq+Muf9I@opalo.etsiig.uniovi.es>

In article <34AFF579.171E@lonewolf.com>, "Daniel V. Klein" <dvk@lonewolf.com> writes:
> I love Perl - 99.9% of my coding is in Perl nowadays.  And sometimes,
> Perl just isn't the right answer.  Here's a shellish answer - the
> advantage to which is that it will handle *gigantic* files without
> huge amounts of memory:
> 
> tr -cd '[a-zA-Z]' '\012' < file | sort | uniq -c | sort -nr
> 
> -DanJerry Pank wrote:

A)
host# tr -cd '[a-zA-Z]' '\012' < myfich | sort | uniq -c | sort -nr
tr: only one string may be given when deleting without squeezing 
repeats
	What OS are you using?


B)	That perl code was fine to do mayor text analysis. Here's 
how I rewrite it to show word stats. Run with cat fich | wstat
  
#!/usr/bin/perl
use strict;
my (%hash,@orden,@array,$i,$count);
while (<>){
        s/\W/ /g;       
        s/\d//g;        
        $_ = lc;
        push @array, split(/ +/);
}
%hash=();
for (@array){
    $hash{$_}++ if length($_)>0   #;-)
}
# orden preferido: 1 mayor ocurrencia, 2 menor longitud, 3 alfabetico
@orden = sort {$hash{$b} <=> $hash{$a} || length($a) <=> length($b) || $a cmp $b} keys %hash ;
for (@orden) {
        print "$_ $hash{$_}\n";
        $i++;
        $count += $hash{$_};
}
print "$i different words over a total of $count \n";
print "Enrichment ratio: ", $i/$count,"\n";
__END__

	Cheers

---
perl -e 'print reverse(split("",":dionarap gnieb no desaelp era uoy fI")),"\n"'
e=44633196506372806702679568930241016072420372740654104856128065320983176095379
n=63928545982336976981162763955517745038001197960559116381014924921278270406501


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

Date: Mon, 05 Jan 1998 14:46:51 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Help please...
Message-Id: <34B138AB.3AD@min.net>

Eli the Bearded wrote:
> 
>           $ym =~ s'!A;F0@0FER9``'`F($)I<F0';

Brilliant!  

(But take it to comp.lang.intercal.  Or is that teco?)

John Porter
jporter@logicon.com


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

Date: Mon, 5 Jan 1998 12:30:32 -0400
From: "Vaughn Fox" <vfox@nbnet.nb.ca>
Subject: Help with passing parameters in URL's please
Message-Id: <68r29p$rr0$1@usenet76.supernews.com>

Hi

I'm running IIS 3.0 on an NT 4.0 platform using IE 4.0 as a browser.  I'm
having the following problem with a script I've developed.  Any help would
be GREATLY appreciated.

index.pl is a script that will read the contents of any given directory or
subdirectory and spit back hyperlinked results into an HTML page.  Say we
have a directory called "Accounting" and the contents of Accounting include
a few files ("file_one.doc", "file two.doc", and "three.htm") and two
subdirectories called "test" and "another test".

When the script is called from the browser with this URL:

 http://server/bin/index1.pl?%20../Intranet/testarea/Accounting

an HTML page is brought up within the browser displaying the contents of
Accounting as listed above. Each of these listings are directly hyperlinked
in the case of a file and linked back to my perl script, index1.pl, in case
of a directory. Each of the direct linked files open within my browser with
no problem.  The directories are where I have my problem.

If the hyperlink points to a single word directory (like my example called
"test") the contents of test are displayed in another HTML page no problem.
Here is the hyperlink to test I use:

http://server/bin/index1.pl?%20../Intranet/testarea/Accounting/test

But if the directory name is two or more words like in my example "another
test"

http://server/bin/index1.pl?%20../Intranet/testarea/Accounting/another test

my script will read the contents of my bin directory where the script is
stored.  The same thing happens when I substitute the spaces in the
directory names with %20.

If I change the directory name to "another_test" and change the hyper link
to the same all works as planned.

If anyone can point out the problem I'd greatly appreciate it.  Thanks in
advance.

Vaughn



Here is some of the code I use:



print "Content-Type:text/html\n\n";

$count=1;

$dept="0";

&top_dir;

&html_top;

&mainlist;

&filelist;

&html_bottom;

exit;



################################################################
#                     TOP DIR SUBROUTINE
#
# sets the parent directory for the script to run in in
# relation to the bin directory which contains this script
################################################################

sub top_dir
{
  if ($#ARGV >= 0)
    {
      $top_dir = $ARGV[0];
    }
  else
    {
      $top_dir = "../intranet";
    }

  chdir($top_dir);

  $dept = $top_dir;

  @folder = split (/\//, $dept);


  if ($#folder ne $folder[2])
    {
      $folder[3] eq $folder[2];
    }

}
################# End top_dir ################################



#############################################################
#                 MAINLIST SUBROUTINE
#
# - determine if directory contents are a directory and display
#   the assigned directory image with each directory
# - also hide selected directories from web page view
#############################################################

sub mainlist
{
  opendir(DIR, ".") || die "Can't open $dir: $!"; # allows to die gracefully
  @listing = readdir(DIR);
  foreach $list (@listing)
    {

      $stat = $list;    # determines attributes
      stat($stat);

     if (-d _)
       {
         if ($list ne "." && $list ne "..")
         {
           if ($count==1)
      {
        print "<td width=45% valign=top><ul><a
href=\"http://server/bin/index1.pl?%20$top_dir/$list\">
        $list</a>";
        print "</td>";
      }
           if ($count==2)
      {
        print "<td width=45% valign=top><ul><a
href=\"http://server/bin/index1.pl?$top_dir/$list\">
        $list</a>";
        print "</td></tr>\n";
       }

           if ($count==1) {$count++;}
           else {$count--;}
         }
       }
     }
closedir(DIR);
}
############################# End Mainlist #####################




#################################################################
#                FILELIST SUBROUTINE
#
# - determine if directory contents are a file and display the
#   assigned document image with each filename
# - also hide selected files from web page view
#################################################################

sub filelist
{ 
opendir(DIR, ".")|| die "Can't open $dir: $!"; # allows to die gracefully
@listing = readdir(DIR);
foreach $list (@listing) 
  {
  $stat = $list;   # determines attributes
  stat($stat);
  if (-f _) 
    {
    if ($file ne "." && $file ne "..") 
    {
  if ($count==1) 
    {
    print "<td width=45% valign=top><ul<a href=\"$top_dir/$list\">
      $list</a>"; 
    print "</td>";
    }
  if ($count==2) 
    {
    print "<td width=45% valign=top><ul<a href=\"$top_dir/$list\">
       $list</a>"; 
    print "</td></tr>\n";
    } 
  if ($count==1) {$count++;}
  else {$count--;}
   
  }
}
}
closedir(DIR);
}
################# end Filelist ################################
 


###############################################################
#         HTML_TOP SUBROUTINE
#
# prints top of HTML page, 
# sets up the top portion of the table which contains the directory
# index structure
###############################################################

sub html_top 
{
print <<"PAGEHEADER";
<HTML>
<HEAD><TITLE>Intranet</TITLE>


</HEAD>
<BASE HREF="http://server/intranet/">

<BODY BGCOLOR=#FFFFFF >

<TD align=center>
<CENTER>
<TABLE WIDTH=90% border=0>
PAGEHEADER
}

################## End HTML_TOP #################################



#################################################################
#                  HTML_BOTTOM SUBROUTINE
#
# prints bottom of HTML page 
#################################################################

sub html_bottom 
{
print <<"PAGEFOOTER";

</TABLE>
</CENTER>
</BODY>
</HTML>

PAGEFOOTER
}
#################### End HTML_BOTTOM ############################










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

Date: 5 Jan 1998 12:33:00 -0700
From: that1guy@primenet.com (S.B.)
Subject: I'm new and apparently I suck, help me please.
Message-Id: <34b2326d.212964727@news.primenet.com>

I'm trying to make a simple script that will allow a client to enter
an administrative portion of their website and then enter new items
for the site.  A new datafile needs to be made for the item they've
entered so other scripts can access this information to display it as
well as update it.

My problem: I can make it work as a simple script but I can't figure
out what I'm doing wrong when I try to access a modified version with
CGI

I get a server error and have checked the logs, the error is:
Premature end of script.

I am using cgi-lib.pl to parse the incoming data.  Here's what I have.

The name of the script is newitem.cgi

This is the data that's being passed to the script
newitem.cgi?category=abstract&inumber=1234&submit=submit

This is newitem.cgi
#!/usr/bin/perl

require 'cgi-lib.pl';
%in = &ReadParse;

$istatus = "Inactive";
$sstatus = "Unknown";
$lastupdate = "Unknown";
$adminstatus = "UNLOCKED";
$comments = "Unknown";
$price = "Unknown";

open (OUT,">%in{'inumber'}.data");
print OUT "inumber:%in{'inumber'}\n";
print OUT "istatus:$istatus\n";
print OUT "sstatus:$sstatus\n";
print OUT "category:%in{'category'}\n";  
print OUT "lastupdate:$lastupdate\n";
print OUT "adminstatus:$adminstatus\n";
print OUT "comments:$comments\n";
print OUT "price:$price\n";
close (OUT);

This is the subroutine called from cgi-lib.pl

sub ReadParse {
  local (*in) = @_ if @_;
  local ($i, $key, $val);

  # Read in text
  if (&MethGet) {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  }

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Split into key and value.  
    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;

    # Associate key and value
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple
separator
    $in{$key} .= $val;

  }

  return length($in); 
}


Thanks for any help you can offer.




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

Date: 5 Jan 1998 12:40:00 -0700
From: that1guy@primenet.com (S.B.)
Subject: Re: I'm new and apparently I suck, help me please.
Message-Id: <34b33604.213883017@news.primenet.com>

Oh...  the system is BSD/OD running Apache

On 5 Jan 1998 12:33:00 -0700, that1guy@primenet.com (S.B.) wrote:

>I'm trying to make a simple script that will allow a client to enter
>an administrative portion of their website and then enter new items
>for the site.  A new datafile needs to be made for the item they've
>entered so other scripts can access this information to display it as
>well as update it.
>
>My problem: I can make it work as a simple script but I can't figure
>out what I'm doing wrong when I try to access a modified version with
>CGI
>
>I get a server error and have checked the logs, the error is:
>Premature end of script.
>
>I am using cgi-lib.pl to parse the incoming data.  Here's what I have.
>
>The name of the script is newitem.cgi
>
>This is the data that's being passed to the script
>newitem.cgi?category=abstract&inumber=1234&submit=submit
>
>This is newitem.cgi
>#!/usr/bin/perl
>
>require 'cgi-lib.pl';
>%in = &ReadParse;
>
>$istatus = "Inactive";
>$sstatus = "Unknown";
>$lastupdate = "Unknown";
>$adminstatus = "UNLOCKED";
>$comments = "Unknown";
>$price = "Unknown";
>
>open (OUT,">%in{'inumber'}.data");
>print OUT "inumber:%in{'inumber'}\n";
>print OUT "istatus:$istatus\n";
>print OUT "sstatus:$sstatus\n";
>print OUT "category:%in{'category'}\n";  
>print OUT "lastupdate:$lastupdate\n";
>print OUT "adminstatus:$adminstatus\n";
>print OUT "comments:$comments\n";
>print OUT "price:$price\n";
>close (OUT);
>
>This is the subroutine called from cgi-lib.pl
>
>sub ReadParse {
>  local (*in) = @_ if @_;
>  local ($i, $key, $val);
>
>  # Read in text
>  if (&MethGet) {
>    $in = $ENV{'QUERY_STRING'};
>  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
>    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
>  }
>
>  @in = split(/&/,$in);
>
>  foreach $i (0 .. $#in) {
>    # Convert plus's to spaces
>    $in[$i] =~ s/\+/ /g;
>
>    # Split into key and value.  
>    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
>
>    # Convert %XX from hex numbers to alphanumeric
>    $key =~ s/%(..)/pack("c",hex($1))/ge;
>    $val =~ s/%(..)/pack("c",hex($1))/ge;
>
>    # Associate key and value
>    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple
>separator
>    $in{$key} .= $val;
>
>  }
>
>  return length($in); 
>}
>
>
>Thanks for any help you can offer.
>



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

Date: 05 Jan 1998 20:18:56 +0000
From: Brian Ewins <Brian.Ewins@gssec.bt.co.uk>
Subject: Re: I'm new and apparently I suck, help me please.
Message-Id: <y1ug1n2d68f.fsf@gssec.bt.co.uk>

that1guy@primenet.com (S.B.) writes:

> I'm trying to make a simple script that will allow a client to enter
> an administrative portion of their website and then enter new items
> for the site.  A new datafile needs to be made for the item they've
> entered so other scripts can access this information to display it as
> well as update it.
[snip]
> 
> I am using cgi-lib.pl to parse the incoming data.  Here's what I have.
> 
Don't. Use CGI.pm or the LWP modules: see http://www.perl.com/ .
Its also obvious that you haven't tested your script offline. This
is easier with CGI.pm.

> The name of the script is newitem.cgi
> 
> This is the data that's being passed to the script
> newitem.cgi?category=abstract&inumber=1234&submit=submit
> 
> This is newitem.cgi
> #!/usr/bin/perl
> 
> require 'cgi-lib.pl';
> %in = &ReadParse;
This is a problem. ReadParse expects 'in' as its argument and returns
the number of items parsed, not the list.
it should read:
&ReadParse(%in);

> 
> $istatus = "Inactive";
> $sstatus = "Unknown";
> $lastupdate = "Unknown";
> $adminstatus = "UNLOCKED";
> $comments = "Unknown";
> $price = "Unknown";
> 
> open (OUT,">%in{'inumber'}.data");
You should say $in{'foo'} not %in{'foo'}.
You should check the return value of open.
You should also use a here-document instead of all those prints, eg
print OUT <<END_TEXT;
inumber:$in{'inumber'}
 ...
istatus:$istatus
END_TEXT
close OUT;

save yourself some carpal-tunnel syndrome....
[snip]
> 
> Thanks for any help you can offer.
> 

No problem.
Actually, none of the above were the cause of the error in the server
log. You simply didn't return anything in the CGI script. The server
expected *some* response to the user. 
Such as:
print <<END_RESPONSE;
Content-type: text/plain

I did it, boss. Can I have some ice cream now?
Aw, puh-leeese?
END_RESPONSE

Go and get CGI.pm and read the documentation, then try again. It will
be better next time...

	HTH
		Baz


-- 
****====----                                              Brian Ewins. 
Fax: (44) 141 220 6100                          Tel: (44) 141 220 6121
 "It's time we face reality, my friends...
      We're not exactly rocket scientists." --Gary Larson ----====****


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

Date: Mon, 5 Jan 1998 09:51:59 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Freeman <freeman@exti.com>
Subject: Re: IIS4, Perl and HTTP headers
Message-Id: <Pine.GSO.3.96.980105094936.26455F-100000@user2.teleport.com>

On Mon, 5 Jan 1998, Bob Freeman wrote:

> It seems that IIS will process one or the other but not both in the same
> header portion of the same perl script.

If your script is following the protocol specification, it's a bug in IIS. 
If you aren't following the protocol, you should fix your script. If you
aren't sure whether you're following the protocol after you've read the
protocol spec, you should ask in a newsgroup about the protocol (or
perhaps about the server), since the folks there can give you better and
more specific answers than we can here in a newsgroup about Perl. Hope
this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: 5 Jan 1998 20:47:38 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Integrating perl's regex functionss into other packages
Message-Id: <qz$9801051540@qz.little-neck.ny.us>

Robert Waldstein <wald@envy.mh.lucent.com> wrote:
>   I upgraded to Henry Spencer's package without trouble - it is designed/
> documented to be used that way. Went to take the next step and find perl's
> setup much harder to use.
>  
>   Has anyone done it? Can anyone give me any pointers (would love to see a
> grep or sed done using perl's pregcomp)? Is it discouraged 
> (besides in the ease of reusing the code -))?

Well I've used the sample code from perlembed(1) to use perl regular
expressions from C. With a shared libperl it did not increase the
executible size by much, nor the resident memory. Is that good enough?

I'd not trust the raw C interface to remain stable enough for ease of
use in another package, at least not until it is documented that it
will remain stable for such purposes.

Elijah
------
should go back and finish that project


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

Date: Mon, 5 Jan 1998 08:01:33 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Kobe Lenjou <kobe@technologist.com>
Subject: Re: Is there a random function
Message-Id: <Pine.GSO.3.96.980105075926.18360J-100000@user2.teleport.com>

On Mon, 5 Jan 1998, Kobe Lenjou wrote:

> I know it's probably an easy question, but is there a random number
> generator in perl?

Yes. 

(If you look in the docs, you should find it. If you have Perl questions
after you've looked for their answers in the docs, please post again.
Thanks!)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Mon, 05 Jan 1998 11:54:11 -0600
From: Steve Goldstein <steveg_nospam@gcg.com>
Subject: Lexical scope and embedded subroutines.
Message-Id: <34B11E43.167E@gcg.com>

The following script has a call to a subroutine within a subroutine.
A "my" variable declared in the outer subroutine does not have the
scope I had expected.  

#!/usr/local/bin/perl 

foreach my $temp ( 'warm', 'cold')
{
    What_is_the_temp($temp);
}

sub What_is_the_temp
{
    my $param =  shift;
    print "Outside it is $param.\n";

    embeddedsub();
    return;

    sub embeddedsub
    {
        print " Inside it is always $param.\n";
        return;
    }
}

=============
The output of the script is:

Outside it is warm.
 Inside it is always warm.
Outside it is cold.
 Inside it is always warm.
=============

This behavior is the same as that of a closure.  In the documentation
I've read, closures apply to anonymous subroutines.  What is going in
this example?


By the way, using -w and the diagnostics pragma, I learned how to get
the behavior I expected by using a reference to an anonymous
subroutine:

sub What_is_the_temp 
{
    my $param =shift;
    print "Outside it is $param.\n";

    $subref = sub {
        print " Inside it is NOT always $param.\n";
        return;
    };

    embedded_sub();
    return;

    sub embedded_sub 
    {
        &$subref(@_);
    }
}


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

Date: Mon, 05 Jan 1998 15:34:12 -0500
From: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: Lexical scope and embedded subroutines.
Message-Id: <34B143C3.C7B35CB5@hotmail.com>



Steve Goldstein wrote:

> The following script has a call to a subroutine within a subroutine.
> A "my" variable declared in the outer subroutine does not have the
> scope I had expected.
>
> #!/usr/local/bin/perl
>
> foreach my $temp ( 'warm', 'cold')
> {
>     What_is_the_temp($temp);
> }
>
> sub What_is_the_temp
> {
>     my $param =  shift;
>     print "Outside it is $param.\n";
>
>     embeddedsub();
>     return;
>
>     sub embeddedsub
>     {
>         print " Inside it is always $param.\n";
>         return;
>     }
> }
>
> =============
> The output of the script is:
>
> Outside it is warm.
>  Inside it is always warm.
> Outside it is cold.
>  Inside it is always warm.
> =============
>
> This behavior is the same as that of a closure.  In the documentation
> I've read, closures apply to anonymous subroutines.  What is going in
> this example?

I believe that when perl comes across a function call to a undefined
functionit finds the declaration later in the file and then calls the
function.  If this is
the case then the declaration embeddedsub would only be executed in the
first iteration.  The second time it is called, the function is already
defined so
there is no reason to re-evaluate the declaration, so the old version
with
$param=='warm'  is executed.

---------------------------------------------------
|Democracy is the worst system of government. --
|Except for all the others
|               -Winston Churchill
---------------------------------------------------
Larry D'Anna                   "eschew obfuscation"




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

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

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