[18319] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 487 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 14 14:06:23 2001

Date: Wed, 14 Mar 2001 11:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984596715-v10-i487@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 14 Mar 2001     Volume: 10 Number: 487

Today's topics:
        [mod_perl] PerlTaintCheck problem <tleffler@u.washington.edu>
    Re: [mod_perl] PerlTaintCheck problem (Abigail)
        AnyDBM_File doesn't define EXISTS method? <jhall@ifxonline.com>
        better way for if structure ... <jens@irs-net.com>
        Copy/Paste using Perl? (LK)
        Echo client one step behind server response? (socket qu <djberge@uswest.com>
    Re: Formatting HTML using Perl <phibeta@newsguy.com>
        Help in understood Perl some slides (Taming of Camel) <cave@pertus.com.pl>
    Re: Help in understood Perl some slides (Taming of Came nobull@mail.com
    Re: Help in understood Perl some slides (Taming of Came (Glyndwr)
    Re: Help in understood Perl some slides (Taming of Came <uri@sysarch.com>
    Re: Help in understood Perl some slides (Taming of Came nobull@mail.com
    Re: HTTP Client Question (Bob Dilworth)
    Re: Is there a shorter way for this? (Anno Siegel)
    Re: Is there a shorter way for this? <mjcarman@home.com>
    Re: Is there a shorter way for this? <mjcarman@home.com>
    Re: Is there a shorter way for this? (Abigail)
    Re: Is there a shorter way for this? (Abigail)
    Re: JUMPING (Peter Scott)
    Re: JUMPING <Waarddebon@chello.nl>
    Re: JUMPING <shanem@ll.mit.edu>
    Re: looking for a script to count downloads (Richard Wilkerson)
    Re: LWP and HTTP Cookies <dsagnell@junglesoft.com>
    Re: LWP and HTTP Cookies nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 14 Mar 2001 09:37:49 -0800
From: Trevor Leffler <tleffler@u.washington.edu>
Subject: [mod_perl] PerlTaintCheck problem
Message-Id: <3AAFAC6D.858FC56A@u.washington.edu>

I've got the following in my httpd.conf:

<Directory "/home/httpd/html">
    Options ExecCGI FollowSymLinks IncludesNoExec Indexes

    AddHandler perl-script cgi
    PerlHandler Apache::Registry
    PerlSendHeader On
    PerlTaintCheck On
</Directory>

But, apache doesn't like the PerlTaintCheck directive:

Starting httpd: Syntax error on line 370 of /etc/httpd/conf/httpd.conf:
PerlTaintCheck not allowed here

Does anyone know why?

Thanks,
-- 
Trevor Leffler, Software Developer
PETTT / Ed-Tech Development Group
University of Washington


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

Date: 14 Mar 2001 18:44:13 GMT
From: abigail@foad.org (Abigail)
Subject: Re: [mod_perl] PerlTaintCheck problem
Message-Id: <slrn9avevt.roj.abigail@tsathoggua.rlyeh.net>

Trevor Leffler (tleffler@u.washington.edu) wrote on MMDCCLII September
MCMXCIII in <URL:news:3AAFAC6D.858FC56A@u.washington.edu>:
\\ I've got the following in my httpd.conf:
\\ 
\\ <Directory "/home/httpd/html">
\\     Options ExecCGI FollowSymLinks IncludesNoExec Indexes
\\ 
\\     AddHandler perl-script cgi
\\     PerlHandler Apache::Registry
\\     PerlSendHeader On
\\     PerlTaintCheck On
\\ </Directory>
\\ 
\\ But, apache doesn't like the PerlTaintCheck directive:
\\ 
\\ Starting httpd: Syntax error on line 370 of /etc/httpd/conf/httpd.conf:
\\ PerlTaintCheck not allowed here
\\ 
\\ Does anyone know why?


Apache configuration has nothing to do with this news group.


Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


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

Date: Wed, 14 Mar 2001 18:49:58 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: AnyDBM_File doesn't define EXISTS method?
Message-Id: <q3Pr6.29991$o7.1136737@news1.rdc1.sdca.home.com>

When I do this:

sub ck_uiddb {

 dbmopen(%db,"$datadir$uiddb", 0644) or die "dbmopen: $!";
 unless (exists $db{$UID} || $new == 1) { &new_UID; }

 $db{$UID} =~ /^[\d+]``[\d+]$/;
 $UN = $1; $PW = $2;
 untie %db;

}

I get this:

AnyDBM_File doesn't define an EXISTS method at
/home/httpd/cgi-bin/adri/login.cgi line 44






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

Date: Wed, 14 Mar 2001 18:38:23 +0100
From: "Jens Luedicke" <jens@irs-net.com>
Subject: better way for if structure ...
Message-Id: <20010314.183815.1139901474.10376@irs-net.com>

Hi there ...

Is there a better way to do that? It works but I'm not happy
with the if-structure ..

$filter_success = &filter_action($i->{action}, $i->{folder}, @$data)
	if $i->{type} eq "From" and $head[$_][0] =~ /$i->{pattern}/
	or $i->{type} eq "Subject" and $head[$_][1] =~ /$i->{pattern}/
	or $i->{type} eq "To" and $head[$_][2] =~ /$i->{pattern}/
	or $i->{type} eq "Cc" and $head[$_][4] =~ /$i->{pattern}/
	or $i->{type} eq "Header" and $headings[$_] =~ /$i->{pattern}/
	or $i->{type} eq "Body" and $messages[$_] =~ /$i->{pattern}/;

-- 
with friendly regards....
	jens luedicke <jens@irs-net.com>

PMC - Perl Mail Client
	http://www.irs-net.com/

perl -le 'use Inline C=>("bool debcheck(){\n#ifdef DEBIAN\n
return TRUE;\n#endif\n}");&debcheck==0||print"This is a Debian System!"'


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

Date: Wed, 14 Mar 2001 17:13:35 GMT
From: lkenny@fisheries.org (LK)
Subject: Copy/Paste using Perl?
Message-Id: <3aafa4eb.12066702@wingate>

I am trying to write a program that will take the information from
selected WordPerfect files and move them into notepad, so I can then
run another program on the info in notepad.  I am working on a windows
machine with ActivePerl installed.
At first I was just copying and pasting the info out of the WP files
and into notepad and running the program, and everything was working
fine.  But I wanted to set up something a little more automated.
I am having some troubles getting it to work the way I want it.  I
wrote the following code to accomplish the task:

#!/usr/local/bin/perl-Tw

chdir("C:\\WINDOWS\\Desktop\\");
$file = "Aug.dat";

open (FILE, $file);
@records = <FILE>;
close(FILE);

$newfile = $file."\.txt";
open (FIEL, ">>$newfile");
foreach $i(@records){
	print FIEL "$i\n";
}

print "All went as planned\n";

But the newfile that is created is pretty garbled and is unables to be
processed properly.

I then went to
http://www.perlfaq.com/faqs/category/files%20and%20directories
to find an answer but all I got was to add in:
binmode FILE;
binmode STDOUT;

So I am not sure where to go.  I want to be able to get the same
results as if I were copying and pasting to notepad.  Can anyone point
me in the right direction -  a FAQ or reference?

Thanks,

LK



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

Date: Wed, 14 Mar 2001 11:20:06 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Echo client one step behind server response? (socket question)
Message-Id: <3AAFA846.CFBE42E8@uswest.com>

Hi all,

I've got a very simple echo client.  Runs fine when I connect to
"echo".  I've got a fairly straightforward fork'ing echo server
running.  It reverses and returns the input from the client (which is
then echo'ed).  Problem is, it seems to be one step behind with the
response.  Here is the output:

 ./echo.pl localhost 8888
hello
Message was:                                        # Oops - where's the
message?

howdy
Message was: olleh                              # Ah - here it is.  But
why was it delayed?

wassup?
Message was: ydwoh

^CBytes out: 20.  Bytes in: 13

Here's the client & server:

>>> START echo.pl <<<

#!/usr/bin/perl -w
# File: echo.pl

# Taken largely from "Network Programming with Perl", p. 107

use strict;
use IO::Socket;

my($bytes_out, $bytes_in) = (0,0);
$SIG{INT} = sub{ print "Bytes out: $bytes_out.  Bytes in: $bytes_in\n";
exit; };

my $host = shift || 'localhost';
my $port = shift || 'echo';

my $socket = IO::Socket::INET->new("$host:$port") or die $@;

while(defined(my $msg_out = STDIN->getline)){
   print $socket $msg_out;
   my $msg_in = <$socket>;
   print "Message was: $msg_in\n";

   $bytes_out += length($msg_out);
   $bytes_in  += length($msg_in);

}

$socket->close or warn $@;

print STDERR "bytes_sent = $bytes_out, bytes_received = $bytes_in\n";

>>> END echo.pl <<<



>>> START echoServer.pl <<<

#!/usr/bin/perl -w

# echoServer.pl

use strict;
use IO::Socket;
use IO::File;
use POSIX qw(setsid WNOHANG);
use English;

# Adjust accordingly
use constant PIDPATH   => '/export/home/myHome/';
use constant LOGPATH   => '/export/home/myHome/';

use constant HOST      => 'localhost';
use constant PORT      => 8888;
use constant PROTO     => 'tcp';
use constant LISTEN    => 10;
use constant REUSE     => 1;
use constant TIMEOUT   => '60*60';

# Global variables
my($pid,$pidFile);
my $quit = 0;

# Set up the server, log files, etc.
$pid = initServer();

$SIG{INT} = $SIG{TERM} = $SIG{HUP} = sub { $quit++ };

my $serverSock = IO::Socket::INET->new(
   LocalPort => PORT,
   Proto => PROTO,
   Listen => LISTEN,
   Reuse => 1,
);
die "Could not create server socket: $ERRNO\n" unless $serverSock;

warn "Echo Server waiting for connections on port: ", PORT;

while(!$quit){
   next unless my $clientSock = $serverSock->accept();

   defined(my $child = fork()) or die "Can't fork: $!";

   if($child == 0){
      $serverSock->close;

      my $peerHost = $clientSock->peerhost;
      my $peerPort = $clientSock->peerport;
      print "Connection from [$peerHost,$peerPort]\n";

      while(my $msg_in = <$clientSock>){
         print "Received $msg_in";
         my $bytes_in += length($msg_in);
         my $msg_out = (scalar reverse $msg_in);
         print $clientSock $msg_out;
         my $bytes_out = length($msg_out);
      }
      print "\nConnection from [$peerHost,$peerPort] finished\n";
      $serverSock->close;
      exit 0;
   }
}

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# initServer()
#
# Initialize the server, create the pid file, start the log file.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub initServer{

   #$SIG{__WARN__} = \&logWarn;  # Set up logging
   #$SIG{__DIE__}  = \&logDie;

   my $pidFile = getPidFile();  # Check for existing server
   my $fh = openPidFile($pidFile);

   becomeDaemon();                      # Begin the daemon

   print $fh $PID;                      # Set server PID
   close $fh;

   return $pid = $PID;
}

sub becomeDaemon{
   die "Can't fork: $ERRNO" unless defined(my $child = fork);

   exit 0 if $child;                                # Parent dies
   POSIX::setsid()                                  # Become the session
leader
      or die "Can't start a new session: $ERRNO";


#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

   # Change the working directory to the root directory.  This
normalizes the
   # environment and avoids problems with unmounting the filesystem from
which
   # the daemon was started (NPWP, p. 312).

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

   chdir '/';
   umask(0);                                   # Forget file mode
creation mask

   # Normalize the PATH environment variable
   my $path =
'/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/sfw/bin';
   $ENV{PATH} = $path;
   $SIG{CHLD} = \&reapChild;

   return $PID;
}

sub reapChild{
   warn "Child process reaped\n";
   do {} while waitpid(-1,WNOHANG) > 0;
}

sub getPidFile{
   my $basename = basename($PROGRAM_NAME, '.pl');
   return PIDPATH . "/$basename.pid";
}

sub openPidFile{
   my $file = shift;
   if(-e $file){
     my $fh = IO::File->new($file) || return;
     my $pid = <$fh>;
     croak "Server already running with PID: $pid\n" if kill 0 => $pid;
     cluck "Removing PID file for defunct server process $pid.\n";
     croak "Can't unlink PID file for $file\n" unless -w $file && unlink
$file;
   }
   return IO::File->new($file,O_WRONLY|O_CREAT|O_EXCL,0644)
      or die "Can't create $file: $ERRNO\n";
}

END{ unlink $pidFile if defined $pid and $PID == $pid }

>>> END echoServer.pl <<<


Any ideas?  Thanks in advance for any help.

Sincerely,

Daniel Berger







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

Date: Wed, 14 Mar 2001 09:25:13 -0800
From: Nuet Lareton <phibeta@newsguy.com>
Subject: Re: Formatting HTML using Perl
Message-Id: <vl9vat4qrc84gjltv4jslhvudic7jakqsp@4ax.com>

On Tue, 13 Mar 2001 08:07:25 -0600, "Michael D. Kirkpatrick"
<wizard@psychodad.com> wrote:
>Nuet Lareton wrote:
<snippy>

>Wow, I personally don't bother with formatting HTML in perl myself.  I
>suppose if I wanted to, I probably could write something that would do it,
>but I don't have the desire to do that.  Since HTML has beginning and
>ending tag markers, you can use that to your advantage for indenting the
>code...   You will have to know all the HTML rules.  Like <P> does not
>necessarily have to have a </P> tag.  Some HTML code editors like Claris
>Home Page gives you the option to omit the </P> in code.  The worse part
>of doing this type of project is trying to come up with all
>contingencies.  I would say start writing the program and ask questions as
>you go along.  When you encounter areas you are not familiar with, ask
>about those areas.  Have patients since it will probably take you several
>days to complete this project.

A couple of days? It took longer for me to get the comments down. :)

This is a working copy of what I had using a crapload of regexps and a
lot of assumptions.

Nuety

# Code that strips all text from a HTML file and only shows the
# skeleton of your HTML. Only minimally useful but a good excercise 
# in futility. =)
# Assumptions: all tags are correctly ended INCLUDING P
# the P is normally not closed but I always close it off in my 
# code. If anyone else wishes to not assume it isn't then it must 
# be true throughout the exent of the document. In fact, the only 
# tags that aren't recursed is BR and IMG SRC. This can be modified 
# and improved. Althought I'd have to wonder why anyone else would 
# bother. Another last second adaption: Since we assume that all 
# tags are properly closed off, we then assume that if we encounter 
# a tag that starts as </...> will be a closing tag and no matching 
# will be involved except the stated No-No's. 

my $html="";
my @nonos=("BR","IMG SRC", "LINK");
my $spacer="  ";

# reads all lines from the file in the cmd line and removes
# whitespace. Mondo inefficient
while (<>)
{ chomp;
  s/(\s{2,}|\t*)//g;
  $html.=$_;
}

$html=&ripper($html);

my @tags=&group($html);

$level=0;
foreach $tag (@tags)
{ foreach $exp (@nonos)
  { if ($tag=~/<$exp/i)		# matches up to the stated No-Nos
    { &printtag($tag,$level);
      goto END;		# I don't like goto statements
    }
  }
  if ($tag =~ /^(<\/)/)		#ending tag
  { &printtag($tag,--$level);
  }
  else				#new occurrance of a tag
  { &printtag($tag,$level++);
  }
  END;			#isn't there a break[2] statement in perl?
}

sub printtag
{ local $tag=shift;
  local $level=shift;
  $whitespace="";
  { for ($i=0; $i<$level; $i++)
    { $whitespace.=$spacer; 
    }
    print $whitespace.$tag."\n";
  }
}

# This conveniently takes out all comment tags and, in turn all text
# within my jscript. I insert the tab because it is a convenient way 
# to split them later
sub ripper
{ local $clean=shift;
  $clean=~s/<!--.*?-->//g;
  $clean=~s/>[^>]*</></g;
  $clean=~s/>/>\t/g;
  return $clean;
}  

# This step is probably not necessary but I would rather work with an 
# array and pop in and out of a stack than work with strings. 
sub group
{ local $list = shift;
  local @fields = split(/\t/,$list); 
  return @fields;
}


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

Date: Wed, 14 Mar 2001 18:24:50 +0100
From: Mirek Rewak <cave@pertus.com.pl>
Subject: Help in understood Perl some slides (Taming of Camel)
Message-Id: <ve8vatcmke48qmpu204vip1nts8sm5kajn@4ax.com>

Hi
I recently get an introduction to Perl "The Taming of the Camel" by
Larry Wall. There is a nice charts: one that summarizes Perl
connnections to other languages on page 7 - "What to take, what to
leave behind" and other on page 4 - "Hatching of an Idea". And the
problem is that I don't understand it all. I'll briefly explain what
it is about. I'll start from the second chart:

              ^
              |
              | C
 Manipulexity |       Perl
              |
              |    sed   awk
              |      shell
              --------------------->
                  Whiputitude

What does it describe? What does axes show ? I know that Perl-power
but what else... :)

And the second chart (wordized :)):
Perl takes from:
- awk - "cycle time" <- ???
Perl leaves from:
- C - "functionitis" <- ???
- sed - "impenetrability" <- ???
      - "limitations" <- ???
- sh - "multiple pass" <- ???
     - "backslashitis" <- ???
     - "compile-as-you-go" <- ???
     - "list-string confusion" <- ???
- awk - "sloth" <- ???
      - "implicit looping" <- ???
Could anyone explain those features?

Thanks for help.

Pozdrowienia
Mirek Rewak
cave@pertus.com.pl


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

Date: 14 Mar 2001 17:48:37 +0000
From: nobull@mail.com
Subject: Re: Help in understood Perl some slides (Taming of Camel)
Message-Id: <u9pufkgs22.fsf@wcl-l.bham.ac.uk>

Mirek Rewak <cave@pertus.com.pl> writes:

> I recently get an introduction to Perl "The Taming of the Camel" by
> Larry Wall. There is a nice charts: one that summarizes Perl
> connnections to other languages on page 7 - "What to take, what to
> leave behind" and other on page 4 - "Hatching of an Idea". And the
> problem is that I don't understand it all. I'll briefly explain what
> it is about. I'll start from the second chart:
> 
>               ^
>               |
>               | C
>  Manipulexity |       Perl
>               |
>               |    sed   awk
>               |      shell
>               --------------------->
>                   Whiputitude
> 
> What does it describe? What does axes show ? I know that Perl-power
> but what else... :)

These are made up words to describe intangible concepts.

"Manipulexity" is (amongst other things) the the ability of efficently
manipulate low level data structures.

"Whiputitude" is (amongst other things) rapid prototyping of text
based processing apps.

> And the second chart (wordized :)):
> Perl takes from:
> - awk - "cycle time" <- ???

Dunno.

> Perl leaves from:
> - C - "functionitis" <- ???

Almost everything in C looks like a function call.  In Perl some
things (notably the regex operators) do not.

> - sed - "impenetrability" <- ???

It is not easy to read sed programs.

>       - "limitations" <- ???

Sed can do only one thing well.

> - sh - "multiple pass" <- ???

Shell script lines are subjected to multiple phases of variable
substitution, words splitting and so on.

>      - "backslashitis" <- ???

Because of the above complex shell scripts may have lots of
backslashes - even more so than Perl!

>      - "compile-as-you-go" <- ???

Shell is purely interpreted.

>      - "list-string confusion" <- ???

Comes from the multiple pass issue.  In shell.

BAR="a b"; foo $BAR c

This calls foo with 3 arguments.  The equivalent code in Perl calls
foo with 2 arguments, the first of which contains a space.

> - awk - "sloth" <- ???
>       - "implicit looping" <- ???

I'm not too familar with awk.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 14 Mar 2001 18:16:47 GMT
From: glynFOOdwr@FSCKdeleteEmeD.co.uk (Glyndwr)
Subject: Re: Help in understood Perl some slides (Taming of Camel)
Message-Id: <slrn9avdcu.173.glynFOOdwr@glyndwr.dyndns.org>

On 14 Mar 2001 17:48:37 +0000, nobull@mail.com scribbled:
>> - awk - "sloth" <- ???
>>       - "implicit looping" <- ???
>
>I'm not too familar with awk.

Sloth: it's just not that fast, I'd guess.

Implicit looping: awk scripts are basically a pile of regexps that get
tested on each line of the input, hence it implicitly loops over the
input.

-- 
                                          -=G=-
Web: http://www.fscked.co.uk                           ICQ: 66545073


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

Date: Wed, 14 Mar 2001 18:38:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Help in understood Perl some slides (Taming of Camel)
Message-Id: <x7pufk9ow2.fsf@home.sysarch.com>

>>>>> "G" == Glyndwr  <glynFOOdwr@FSCKdeleteEmeD.co.uk> writes:

  G> On 14 Mar 2001 17:48:37 +0000, nobull@mail.com scribbled:
  >>> - awk - "sloth" <- ???
  >>> - "implicit looping" <- ???
  >> 
  >> I'm not too familar with awk.

  G> Sloth: it's just not that fast, I'd guess.

  G> Implicit looping: awk scripts are basically a pile of regexps that get
  G> tested on each line of the input, hence it implicitly loops over the
  G> input.

think of awk as always having -n enabled. in fact, the -n loop was
created to allow emulation of awk behavior. awk is more (not much) than
regexes. some flavors had a little decent power. not that i would ever
use awk again for anything serious.

similarly, -p is used to emulate sed's built in line loop with a default
print (which awk doesn't have).

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 14 Mar 2001 18:34:07 +0000
From: nobull@mail.com
Subject: Re: Help in understood Perl some slides (Taming of Camel)
Message-Id: <u9elw0gpy8.fsf@wcl-l.bham.ac.uk>

glynFOOdwr@FSCKdeleteEmeD.co.uk (Glyndwr) writes:

> Implicit looping: awk scripts are basically a pile of regexps that get
> tested on each line of the input, hence it implicitly loops over the
> input.

But I thought this was in a list of features _not_ taken from awk!

awk's implicit looping is available in Perl (as an command line
switch).

BTW: To the OP - do you have the audio file (or transcript thereof)
that goes with the slides?  They make a lot more sense if you do.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 14 Mar 2001 16:55:46 GMT
From: avast@hortonsbay.com (Bob Dilworth)
Subject: Re: HTTP Client Question
Message-Id: <3aafa15d.12498754@news.mco.edu>

On 13 Mar 2001 22:28:10 GMT, abigail@foad.org (Abigail) wrote:

>Al Spohn (spohn@mayo.edu) wrote on MMDCCLI September MCMXCIII in
><URL:news:98m58p$5ie$1@tribune.mayo.edu>:
>.. My apologies, but by posting in this group, coupled with my reference to a
>.. Perl book on http client programming,  I thought people would (correctly)
>.. assume that Perl was the tool in question.  One concievable answer could
>.. have been that an object in, say, the LWP libraries would be useful in
>.. extracting more detailed error information from apache.  So my question may
>.. not have been Perl specific, but the answer could/might well have been.
>.. 
>.. #!/usr/bin/perl
>.. 
>.. There, now I'm no longer "perl free."
>
>
>Instead, you're Jeopardy compliant.
>
>*plonk*

Al:

The above little worthless commentary from one of the members of the
clpm Taliban indicates that you've violated on of their favorite
"rules" - posting the answer to a message before the part of the
message you're commenting on.  Abigail is indicating that you're now
part of her kill file which means she'll not be reading any of your
postings any more.  My advice is to welcome such "plonking" since
it'll weed out the Taliban and you can concentrate on getting help
from folks who are less concerned with a slavish regard for random
rules.

Bob D.


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

Date: 14 Mar 2001 16:07:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is there a shorter way for this?
Message-Id: <98o50k$9pg$1@mamenchi.zrz.TU-Berlin.DE>

According to Zeljko Vrba <zvrba@inje.iskon.hr>:
> On 14 Mar 2001 14:43:16 GMT, Anno Siegel wrote:
> > 
> > Somehow I don't like to think about what <pattern with 32 parens> might
> > look like.  Perhaps a variant of split can simplify the job.  It's
> > hard to say, since the relevant part of your code is missing.
> > 
> Well, you asked for it :)

[regex snipped, it didn't travel so well]

Here it is again, reformatted (a few blanks may have sneaked in):

m<CALLRECORD-3-MICA_TERSE_CALL_REC:\ DS0
slot/contr/chan=(\d+)/(\d+)/(\d+),   # 1, 2, 3
slot/port=(\d+)/(\d+),               # 4, 5
call_id=([0-9A-F]+),                 # 6
userid=(.+?),                        # ...
ip=(.+?),
calling=(\d+),
called=(\d+),
std=(.+?),
prot=(.+?),
comp=(.+?),
init-rx/tx\ b-rate=(\d+)/(\d+),
finl-rx/tx\ b-rate=(\d+)/(\d+),
rbs=(\d+),
d-pad=(.+?),
retr=(\d+), 
sq=(\d+), 
snr=(\d+), 
rx/tx\ chars=(\d+)/(\d+),
p/w\ info=(.+?),
rx/txec=(\d+)/(\d+),
bad=(\d+),
time=(\d+),
finl-state=(.+?),
disc\(radius\)=(.+?),
disc\(modem\)=(.+)$>x

In the original form, this is a maintenance nightmare.  Even broken
down using the /x modifier and commented the way I indicate it would
be a pain to adjust if the format ever changes.

On the other hand, the format is highly regular: We have (basically)
a comma-separated list of name/value pairs.  This absolutely shouts
for a split into a hash:

    my %h = map split( /=/, $_), split( /,/, $line);

This leaves the multiple values (like "slot/contr/chan") to be dealt
with, which must probably be done individually.

This would leave you with a hash %h containing 32 key/value pairs
which you can arrange via hash-slices in any way you want.  It's
more code than your approach, but it's far more flexible and
maintainable. 

Anno


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

Date: Wed, 14 Mar 2001 10:34:03 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Is there a shorter way for this?
Message-Id: <3AAF9D7B.F3E0044B@home.com>

Zeljko Vrba wrote:
> 
> Anno Siegel wrote:
>>
>> Somehow I don't like to think about what <pattern with 32 parens> might
>> look like.  Perhaps a variant of split can simplify the job.  It's
>> hard to say, since the relevant part of your code is missing.
>>
> Well, you asked for it :)
> 

[Horridly wrapped regex snipped]

Actually, your data is quite regular. You just need to do multiple
passes. First split on the commas, then into name/value pairs on the
'=', and then on '/' for fields with multiple values.

Assuming that $time already contains whatever you want, and that $line
contains a line from your logfile:

my @data;
push(@data, $time);
my @fields = split /, / => $line;
foreach (@fields) {
	my (undef, $value) = split /=/ => $_;
	push @data, split '/' => $value;
}

$, = "\n";
print @data;

This breaks down if your data can contain [,=/] as part of the value,
but that doesn't appear to be the case.

-mjc


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

Date: Wed, 14 Mar 2001 10:47:21 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Is there a shorter way for this?
Message-Id: <3AAFA099.36199305@home.com>

Michael Carman wrote:
> 
> my @data;
> push(@data, $time);
> my @fields = split /, / => $line;
> foreach (@fields) {
>         my (undef, $value) = split /=/ => $_;
>         push @data, split '/' => $value;
> }

On second thought, this can be done as a (wrapped) one-liner.

@data = ($time, map {split '/', $_}
                map {(split '=', $_)[1]}
                split ', ', $line);
 
-mjc


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

Date: 14 Mar 2001 18:26:32 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Is there a shorter way for this?
Message-Id: <slrn9avduo.roj.abigail@tsathoggua.rlyeh.net>

Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMDCCLII September
MCMXCIII in <URL:news:m1lmq8jqip.fsf@halfdome.holdit.com>:
:: >>>>> "Zeljko" == Zeljko Vrba <zvrba@inje.iskon.hr> writes:
:: 
:: Zeljko> On 14 Mar 2001 14:43:16 GMT, Anno Siegel wrote:
:: >> 
:: >> Somehow I don't like to think about what <pattern with 32 parens> might
:: >> look like.  Perhaps a variant of split can simplify the job.  It's
:: >> hard to say, since the relevant part of your code is missing.
:: >> 
:: Zeljko> Well, you asked for it :)
:: 
:: Zeljko>         if(m<CALLRECORD-3-MICA_TERSE_CALL_REC: DS0 slot/contr/chan=(\d+)/(\d+)/(
:: Zeljko> \d+), slot/port=(\d+)/(\d+), call_id=([0-9A-F]+), userid=(.+?), ip=(.+?), callin
:: Zeljko> g=(\d+), called=(\d+), std=(.+?), prot=(.+?), comp=(.+?), init-rx/tx b-rate=(\d+
:: Zeljko> )/(\d+), finl-rx/tx b-rate=(\d+)/(\d+), rbs=(\d+), d-pad=(.+?), retr=(\d+), sq=(
:: Zeljko> \d+), snr=(\d+), rx/tx chars=(\d+)/(\d+), p/w info=(.+?), rx/tx ec=(\d+)/(\d+), 
:: Zeljko> bad=(\d+), time=(\d+), finl-state=(.+?), disc\(radius\)=(.+?), disc\(modem\)=(.+
:: Zeljko> )$>)
:: 
:: Zeljko> I'm parsing syslog from access server and inserting it into database.
:: 
:: Looks to me like
:: 
::         @result = /\S+?=(\S+), /g;
:: 
:: gets you 90% of the way there, except you have to split apart a few of
:: the subentries.  Easy enough with splice.


That makes the big assumption every line is valid and needs to be processed.

You could of course extract the parts before the equal signs too, and end
up with even more substrings and check them, but then it becomes unclear
what the gain is.



Abigail


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

Date: 14 Mar 2001 18:35:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Is there a shorter way for this?
Message-Id: <slrn9aveg8.roj.abigail@tsathoggua.rlyeh.net>

Michael Carman (mjcarman@home.com) wrote on MMDCCLII September MCMXCIII
in <URL:news:3AAF9D7B.F3E0044B@home.com>:
[] Zeljko Vrba wrote:
[] > 
[] > Anno Siegel wrote:
[] >>
[] >> Somehow I don't like to think about what <pattern with 32 parens> might
[] >> look like.  Perhaps a variant of split can simplify the job.  It's
[] >> hard to say, since the relevant part of your code is missing.
[] >>
[] > Well, you asked for it :)

Actually, what Anno meant was "since the relevant data is missing".

[] > 
[] 
[] [Horridly wrapped regex snipped]
[] 
[] Actually, your data is quite regular. You just need to do multiple
[] passes. First split on the commas, then into name/value pairs on the
[] '=', and then on '/' for fields with multiple values.

Well, maybe his data is regular, and maybe it isn't. You can't tell
from the posting. You know that what he is *processing* is regular.
But you can't make assumptions of what's in the file and not matched
by the regex.

Your solution works only by making a bold assumption about data you
don't know anything about. You are doing Zeljko a disservice by not
mentioning that assumption.



Abigail
-- 
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
      v80.101.114.108.32, v72.97.99.107.101.114.10;


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

Date: Wed, 14 Mar 2001 16:18:02 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: JUMPING
Message-Id: <_QMr6.29880$V6.116601@news1.gvcl1.bc.home.com>

In article <p4Mr6.2004176$%C1.26239451@Flipper>,
 "Waarddebon" <Waarddebon@chello.nl> writes:
>In my script I use a check on a variable. If this variable contains a
>certain value an other cgi-script must be loaded. How can I accomplish this
>?
>
>for example:
>if ($xx eq '2') {
>#### Load the other script ####

perldoc -f do
perldoc -f require
perldoc -f exec
perldoc -f system
perldoc perlop, look for 'bacticks'

Which one is right for you depends on what you mean by 'load'.

-- 
Peter Scott


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

Date: Wed, 14 Mar 2001 16:32:37 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: Re: JUMPING
Message-Id: <F2Nr6.2004955$%C1.26259744@Flipper>

The web browser needs to be redirected to another CGI

> By load do you mean that the web browser needs to be redirected to
> another CGI or that another perl script needs to be run on the server
> from the current script?





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

Date: Wed, 14 Mar 2001 13:27:51 -0500
From: Shane McDaniel <shanem@ll.mit.edu>
Subject: Re: JUMPING
Message-Id: <3AAFB827.6DC49891@ll.mit.edu>

You would then need to print a redirection HTML statement.  This is an
HTML issue.

Waarddebon wrote:
> 
> The web browser needs to be redirected to another CGI
> 
> > By load do you mean that the web browser needs to be redirected to
> > another CGI or that another perl script needs to be run on the server
> > from the current script?


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

Date: Wed, 14 Mar 2001 18:54:46 GMT
From: rw@dreamgate.com (Richard Wilkerson)
Subject: Re: looking for a script to count downloads
Message-Id: <3aafbd84.10316931@news.telocity.com>

On 13 Mar 2001 17:41:31 +0000, nobull@mail.com wrote:
Hi,
 
 Yes, this sounds more like what I need to do!

  Do you have any examples or a way to lead me a little further
towards this design?  I am ok with the perl/cgi  incrementing and
logging, but the connection to web stuff I am very weak. 

thanks

>
>Alternative approach is to have a CGI script increments the counter
>file then does an _internal_ redirect to the true, secret URL of the
>PDF file.

Original question:   How to get a log file going that counts the use
of a particular download link on a page of many links? 


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

Date: Wed, 14 Mar 2001 11:16:48 -0500
From: "D. Sagnella" <dsagnell@junglesoft.com>
Subject: Re: LWP and HTTP Cookies
Message-Id: <3AAF996F.5A012E30@junglesoft.com>

Someone has kindly pointed out a typo in my script.

stupid stupid stupid!

Well, now I no-longer get that error.

but stay tuned I am sure I will have more
questions!

ds


>
>     my $cookie_jar=>HTTP::Cookies->new;

should be '=' not '=>'




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

Date: 14 Mar 2001 17:49:14 +0000
From: nobull@mail.com
Subject: Re: LWP and HTTP Cookies
Message-Id: <u9ofv4gs11.fsf@wcl-l.bham.ac.uk>

"D. Sagnella" <dsagnell@junglesoft.com> writes:

> Subject: LWP and HTTP Cookies

Your problem has nothing to do with any of that.

>     my $cookie_jar=>HTTP::Cookies->new;

There is a typo in that line. (=> where you meant =).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V10 Issue 487
**************************************


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