[6533] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 158 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 22 02:07:52 1997

Date: Fri, 21 Mar 97 23: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           Fri, 21 Mar 1997     Volume: 8 Number: 158

Today's topics:
     Re: An interesting socket puzzle <bermingh@concentric.net>
     Re: An interesting socket puzzle (Rachel Polanskis)
     Re: any non-forking server template code? <merlyn@stonehenge.com>
     AnyDBM_File problems <rlj0@pge.com>
     Re: CGI HELP (Tad McClellan)
     File upload (Yinglee)
     Re: Help with [so] called Virtual Classes <kevina@clark.net>
     help with make <grantr@epsc-s2.saicspt.com>
     Re: how do i... <eric@nettown.com>
     Re: interaction between local(), my(), and undef() (Bennett Todd)
     KEDIT .KLD file -Win'95 <rproctor@together.net>
     Re: Looking backwards through a text file (Abigail)
     Matching multiple instances of patterns per line <caplain@znet.com>
     Re: Matching multiple instances of patterns per line (Tad McClellan)
     Perl for win95 <deano@nh.ultranet.com>
     Re: Perl on Windows 95 (Anthony Hardy)
     Re: Please Help With Regular Expression <rootbeer@teleport.com>
     Re: Q: download htm from a perl script? <rootbeer@teleport.com>
     Re: Questions about the System Command <rootbeer@teleport.com>
     Re: Reg: tr command (Gerben Vos)
     Re: regex for UNIX usernames needed! <merlyn@stonehenge.com>
     Re: regex for UNIX usernames needed! <jhi@alpha.hut.fi>
     Re: surrogate for flastmod <rootbeer@teleport.com>
     Re: term 'regular expressions' considered undesirable (Rahul Dhesi)
     Re: Uninitialized "next" with -w ? (Tad McClellan)
     Re: Vanishing string terminators and premature end of s <rootbeer@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 21 Mar 1997 23:20:01 -0600
From: Chuck Bermingham <bermingh@concentric.net>
Subject: Re: An interesting socket puzzle
Message-Id: <Pine.LNX.3.95.970321231428.943B-100000@ccchips.concentric.net>

Well, the Automatic Welcome pointed me in the right direction, so I got
the answer to my question on the Faq.  In case anyone's interested, here's
what I did:

 ...

if($kid) {
  while($line = <SOCK1>) {
    print $line;
  }
} else {
  select((select(SOCK1,), $| = 1)[0]); #Autoflush
  while($line = <STDIN>) {
    print SOCK1 $line;
  }
}

The "select" fixed it.
The faq said sockets are buffered in blocks, not in lines.  Also, I had
fiddled with trying to autoflush before, thinking that might be the
problem, and couldn't get it working.

But I'm sure there are other ways to do it...

--Chuck



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

Date: 22 Mar 1997 03:18:21 GMT
From: rachel@virago.org.au (Rachel Polanskis)
Subject: Re: An interesting socket puzzle
Message-Id: <5gvj1t$l4a@janis.virago.org.au>

In article <Pine.LNX.3.95.970320234918.132C-100000@ccchips.concentric.net>,
	Chuck Bermingham <bermingh@concentric.net> writes:
> Hi, friends!
> 
> I'm new to this newsgroup, so if I'm blowing my nose inappropriately,
> please let me know!

I'm new to perl too,
but I think I can answer this one....

> socket(SOCK1,PF_INET,SOCK_STREAM,$proto) || die "socket: $!";
> connect(SOCK1,$paddr) || die "connect: $!";

$| = 1; select(SOCK1);

> 
> my($line,$kid);
> $kid=fork;
> if($kid) {
>   while($line = <SOCK1>) {
>     print $line;
>   }
> } else {
>   while($line = <STDIN>) {
>     send SOCK1,$line,0;
>   }
> }

 .. 

> This works (believe it or not.  But if you substitute:
> 
>   print SOCK1 $line;
> 
> for the last executable statement (the "send", it hangs.
> 

The symptom sounds the same as for my problem.

Use "$| = 1;" to set autoflush,
and then select();  for the File Descriptor you need to print to.
reset the FD when you need to print to STDOUT after you are finished...

This is not documented in the second ed. of Learning Perl.
All the examples are reading from the socket, not printing to it.

rachel

                 defghijklmnopqrstuvwxyz:  What? No ABC?
--
Rachel Polanskis                 Kingswood, Greater Western Sydney, Australia 
grove@zeta.org.au                http://www.zeta.org.au/~grove/grove.html
r.polanskis@nepean.uws.edu.au    http://www.nepean.uws.edu.au/ccd/
                Witty comment revoked due to funding cuts


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

Date: 21 Mar 1997 19:17:08 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: any non-forking server template code?
Message-Id: <8c3etok6vv.fsf@gadget.cscaper.com>

>>>>> "Rahul" == Rahul Dhesi <c.c.eiftj@42.usenet.us.com> writes:

Rahul> The perl online manual has an example of forking server, but not for a
Rahul> non-forking server.  Are there any available templates for a non-forking
Rahul> server on which one could build a customized one?

Rahul> Ideally such a server would create n processes all at once, and then
Rahul> each process would continue to cycle through incoming connections.

That's not really a non-forking server.  As tom said, that's a
pre-forking server.  Here's a template Web proxy server that forks
like Apache, and then lets the children duke it out over who is going
to take the next incoming connection...

(The code was built up, and actually functions as a proxy correctly,
but I abandoned development on it when I discovered that the latest
Apache does proxies the way I wanted them... :-)

The most important parts for you are the &main, &fork_a_slave, and
&child_does subroutines.

================================================== snip
#!/home/merlyn/bin/perl -Tw
use strict;
$ENV{PATH} = join ":", qw(/usr/ucb /bin /usr/bin);
$|++;

my $VERSION_ID = q$Id: proxy,v 1.18 1996/11/18 03:27:23 merlyn Exp $;
my $VERSION = (qw$Revision: 1.18 $ )[-1];

## Copyright (c) 1996 by Randal L. Schwartz
## This program is free software; you can redistribute it
## and/or modify it under the same terms as Perl itself.

### debug management
sub prefix {
  my $now = localtime;

  join "", map { "[$now] [${$}] $_\n" } split /\n/, join "", @_;
}
$SIG{__WARN__} = sub { warn prefix @_ };
$SIG{__DIE__} = sub { die prefix @_ };
&setup_signals();

### logging flags
my $LOG_PROC = 1;		# begin/end of processes
my $LOG_TRAN = 1;		# begin/end of each transaction
my $LOG_REQ_HEAD = 0;		# detailed header of each request
my $LOG_REQ_BODY = 0;		# header and body of each request
my $LOG_RES_HEAD = 0;		# detailed header of each response
my $LOG_RES_BODY = 0;		# header and body of each response
my $LOG_CACHE = 1;		# cache-related transactions

### configuration
my $HOST = 'www.stonehenge.com';
my $PORT = 0;			# pick next available user-port
my $SLAVE_COUNT = 10;		# how many slaves to fork
my $CACHE_DIR = "cache";	# cache top level directory

### main
warn("running version ", $VERSION);
	       
&main();
exit 0;

### subs
sub main {			# return void
  use HTTP::Daemon;
  my %kids;

  my $master = HTTP::Daemon->new(LocalPort => $PORT, LocalAddr => $HOST)
      or die "Cannot create master: $!";
  warn("master is ", $master->url);
  ## fork the right number of children
  for (1..$SLAVE_COUNT) {
    $kids{&fork_a_slave($master)} = "slave";
  }
  {				# forever:
    my $pid = wait;
    my $was = $kids{$pid} || "?unknown?";
    delete $kids{$pid};
    warn("child $pid ($was) terminated status $?") if $LOG_PROC;
    if ($was eq "slave") {	# oops, lost a slave
      sleep 1;			# don't replace it right away (avoid thrash)
      $kids{&fork_a_slave($master)} = "slave";
    }
    redo;
  }
}

sub setup_signals {		# return void

  setpgrp;		# I *am* the leader
  $SIG{HUP} = $SIG{INT} = $SIG{TERM} = sub {
    my $sig = shift;
    $SIG{$sig} = 'IGNORE';
    kill $sig, 0;		# death to all-comers
    die "killed by $sig";
  };
}

sub fork_a_slave {		# return int (pid)
  my $master = shift;		# HTTP::Daemon

  my $pid;
  defined ($pid = fork) or die "Cannot fork: $!";
  &child_does($master) unless $pid;
  $pid;
}

sub child_does {		# return void
  my $master = shift;		# HTTP::Daemon

  warn("child started") if $LOG_PROC;
  {				# forever:
    flock($master, 2);		# LOCK_EX
    warn("child has lock") if $LOG_TRAN;
    my $slave = $master->accept or die "accept: $!";
    warn("child releasing lock") if $LOG_TRAN;
    flock($master, 8);		# LOCK_UN
    my @start_times = (times, time);
    $slave->autoflush(1);
    warn("connect from ", $slave->peerhost) if $LOG_TRAN;
    &handle_one_connection($slave); # closes $slave at right time
    if ($LOG_TRAN) {
      my @finish_times = (times, time);
      for (@finish_times) {
	$_ -= shift @start_times; # crude, but effective
      }
      warn("times: @finish_times");
    }
    redo;
  }
}

sub handle_one_connection {	# return void
  use HTTP::Request;
  my $handle = shift;		# HTTP::Daemon::ClientConn

  my $request = $handle->get_request;
  defined($request) or die "bad request"; # XXX

  my $response = &fetch_request($request);
  warn("response: <<<\n", $response->headers_as_string, "\n>>>")
    if $LOG_RES_HEAD and not $LOG_RES_BODY;
  warn("response: <<<\n", $response->as_string, "\n>>>")
    if $LOG_RES_BODY;
  $handle->send_response($response);
  close $handle;
  &store_cache($response);
}

sub fetch_request {		# return HTTP::Response
  use HTTP::Response;
  my $request = shift;		# HTTP::Request

  ## XXXX needs policy here
  my $url = $request->url;

  if ($url->scheme !~ /^(http|gopher|ftp)$/) {
    my $res = HTTP::Response->new(403, "Forbidden");
    $res->content("bad scheme: @{[$url->scheme]}\n");
    $res;
  } elsif (not $url->rel->netloc) {
    my $res = HTTP::Response->new(403, "Forbidden");
    $res->content("relative URL not permitted\n");
    $res;
  } else {
    ## validated request, get it!
    warn("processing url is $url") if $LOG_TRAN;
    &fetch_possibly_cached_request($request);
  }
}

{				# local static block
  my $agent;

  sub fetch_possibly_cached_request { # return HTTP::Response
    my $request = shift;		# HTTP::Request

    $agent = new MyAgent unless defined $agent;

    warn("fetch: <<<\n", $request->headers_as_string, "\n>>>")
      if $LOG_REQ_HEAD and not $LOG_REQ_BODY;
    warn("fetch: <<<\n", $request->as_string, "\n>>>")
      if $LOG_REQ_BODY;
    ## eventually, check the cache here
    $agent->request($request);
  }
}

## store an HTTP::Response into the cache, if reasonable
sub store_cache {		# return void
  my $response = shift;		# HTTP::Response

  eval {			# catch errors:
    local ($SIG{__DIE__});

    ## validate the response
    die "response is not successful: [",$response->headers_as_string,"]"
      unless $response->is_success;
    die "response is not fresh: [",$response->headers_as_string,"]"
      unless $response->is_fresh;

    ## validate the request
    my $request = $response->request;
    my $method = $request->method;
    die "method $method not GET" if $method ne "GET";
    my $url = $request->url;
    my ($scheme,$user,$password,$host,$port,$epath,
	$eparams,$equery,$frag) = $url->crack;
    die "scheme $scheme not http" if $scheme ne "http";
    die "non-empty user $user" if defined $user;
    die "non-empty password $password" if defined $password;
    die "missing host" unless defined $host;
    die "missing port" unless defined $port;
    die "missing epath" unless defined $epath;
    die "non-empty eparams $eparams" if defined $eparams;
    die "non-empty equery $equery" if defined $equery;
    die "non-empty frag $frag" if defined $frag;

    ## validate the request headers
    my $authorization = $request->authorization;
    die "non-empty authorization $authorization" if defined $authorization;
    
    ## XXX pretend all is well
    warn("cache written for $url") if $LOG_CACHE;
  };
  warn("cache not written: $@") if $@ and $LOG_CACHE;
}

### additional classes

## MyAgent

BEGIN {
  package MyAgent;
  @MyAgent::ISA = qw(LWP::UserAgent);
  use LWP::UserAgent;

  sub new {			# return MyAgent (like LWP::UserAgent)
    my $self = shift;
    my $ua = SUPER::new $self @_;
    $ua->agent("proxy/$VERSION " . $ua->agent);
    $ua->env_proxy;
    $ua;
  }

  ## do not allow redirects... instead, pass the result through
  sub redirect_ok {
    0;
  }
}
================================================== snip

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 528 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 21 Mar 1997 19:08:19 -0800
From: "Randy Jew;Network Specialist" <rlj0@pge.com>
Subject: AnyDBM_File problems
Message-Id: <33334D23.1E2D@pge.com>

I'm running into a problem using the "use AnyDBM_File;" command so
I can use DBM type files in my script.  With the "use AnyDBM_File"
in my script, I run my script on the command line and it works fine.

However, when I try to run my script from a crontab entry I get an
error:

Your "cron" job

/usr2/epage/buildepagedbs.pl

produced the following output:

AnyDBM_File.pm did not return a true value at
/usr2/epage/buildepagedbs.pl line 55.
BEGIN failed--compilation aborted at /usr2/epage/buildepagedbs.pl line
55.

Line 55 is the "use" command line. Earlier today I was getting the
error message of "can't find AnyDBM_File.pm file".  I don't know
how this went away?

I'm running Perl 5.003 on Solaris 2.5.1:

epage01# /opt/PERL/perl5.003/bin/perl -V
Summary of my perl5 (5.0 patchlevel 3 subversion 0) configuration:
  Platform:
    osname=solaris, osver=2.5.1, archname=sun4-solaris
    uname='sunos epage01 5.5.1 generic_103640-05 sun4u sparc
sunw,ultra-1 '
    hint=recommended, useposix=true, d_sigaction=define
  Compiler:
    cc='cc', optimize='-O', gccversion=
    cppflags=''
    ccflags =''
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, randbits=15
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags='-Kpic', lddlflags='-G'

@INC: /opt/PERL/perl5.003/lib/sun4-solaris/5.003 /opt/PERL/perl5.003/lib
/opt/PERL/perl5.003/lib/site_perl/sun4-solaris
/opt/PERL/perl5.003/lib/site_perl .
epage01# 

Any help that you can give to me would be appreciated.

Thanks!
Randy Jew
Sr. Network Specialist
PG&E


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

Date: Fri, 21 Mar 1997 22:42:53 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: CGI HELP
Message-Id: <d0ovg5.9h4.ln@localhost>

MyStIkAl (mystikal@ilinks.net) wrote:

: Subject: CGI HELP
           ^^^

Oops. Your post ended up in the perl newsgroup.

You probably meant to post it to the CGI newsgroup?

( comp.infosystems.www.authoring.cgi )



: I have a page with some javascript which prompts you for you name and
                          ^^^^^^^^^^

Oh... Well, ... 

comp.lang.javascript 

then?


: enters it in a table with some other things such as the browser type, 
: how many times that the person has been there and some more.
: http://www.ilinks.net/~mystikal/   <--if ya wanna check it out.
: but, I have some CGI script that puts the users name and ip address
: and some other stuff, but I don't know how to make it print it out in 
: the table

: HERE'S THE SCRIPT
: ------------------------------------------------------------------------
: #!/bin/sh
         ^^

Now a _shell_ script?

That would be:

comp.unix.shell



: any help would be appreciated

Any question related to perl would be appreciated in the perl newsgroup.

What is your question? Do you want to rewrite this in perl or something?


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 21 Mar 97 16:49:45 GMT
From: yinglee@hkstar.com (Yinglee)
Subject: File upload
Message-Id: <5guea5$jld@capella.hkstar.com>


I am using WinNT4.0 + Perl 5 + Netscape 3 to upload file(binary) from client 
to server. The size of uploaded file usually > 1Mb. So I can't use cgi-lib.pl
I use the follow code to read from STDIN and write to a file.


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

Date: Fri, 21 Mar 1997 23:11:28 -0600
From: Kevin Atkinson <kevina@clark.net>
Subject: Re: Help with [so] called Virtual Classes
Message-Id: <859000965.23451@dejanews.com>

Sorry about the subject typo.

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


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

Date: Fri, 21 Mar 1997 09:21:03 -0800
From: Russ Grant <grantr@epsc-s2.saicspt.com>
Subject: help with make
Message-Id: <3332C37F.4559@epsc-s2.saicspt.com>

I'm getting the following error while running make:

`sh  cflags libperl.a util.o`  util.c
          CCCMD =  cc -c  -O
util.c: In function `Perl_croak':
util.c:962: number of arguments doesn't match prototype
proto.h:45: prototype declaration
util.c: In function `Perl_warn':
util.c:1017: number of arguments doesn't match prototype
proto.h:466: prototype declaration
util.c: In function `Perl_my_popen':
util.c:1442: warning: return makes pointer from integer without a cast
*** Error code 1
make: Fatal error: Command failed for target `util.o'

and advice would be greatly appreciated.
Russ


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

Date: Fri, 21 Mar 1997 20:04:36 +0000
From: Eric Poindexter <eric@nettown.com>
To: Jon Nathan <jn0729a@cage.cas.american.edu>
Subject: Re: how do i...
Message-Id: <3332E9D4.2939634D@nettown.com>

Jon Nathan wrote:
> 
> hello
> 
> this is what i would like to do:
> have an html page with a list of links.  when a user clicks one of the
> links, it takes him to a template html page with a specific image on it.
> 
> this would be so that i don't have to write 50 simple html pages with an
> image tag.
> 
> sounds like it should be easy, but i'm not sure where to start.  how do i
> pass a variable to the perl script depending on which link in the html
> page is clicked?  any help would be much appreciated - email preferable
> 
> thanks
> 
> Jon Nathan
> jn0729a@american.edu
> www.csis.american.edu/~jn0729a

On the page with the list of links, append "?id" to all links, e.g.
<a href=perlscript?gif1>Gif 1</a>
<a href=perlscript?gif2>Gif 2</a>
and so on.

This is refered to as a GET method.

In the perlscript that these links run the id will be in
$ENV{QUERY_STRING}

So if the link to "Gif 1" is choosen, $ENV{QUERY_STRING} will contain
"gif1".

Note that the id should be url encoded.

You might want to check out
http://nettown.com/site_perl/doc/eg/learn.cgi
for more info.

--
Eric
<mailto:eric@nettown.com>
[http://nettown.com/site_perl/]
have a good day!


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

Date: Fri, 21 Mar 1997 18:53:45 GMT
From: bet@nospam.interactive.net (Bennett Todd)
Subject: Re: interaction between local(), my(), and undef()
Message-Id: <slrn5j5m9n.pbk.bet@onyx.interactive.net>

On Fri, 21 Mar 1997 00:59:03 GMT, Patrick Duff <pduff@airmail.net> wrote:
>[ some interesting observations on my() -vs- undef() ]
>Something else to ponder:  Suppose the above example was complexified
>a bit so that $Variable was tainted sometimes and not others.  Would
>the state of its taintedness survive an "undef"?

It sure shouldn't; taintedness is an attribute of the _contents_ not the name.

-Bennett


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

Date: Fri, 21 Mar 1997 11:28:27 -0500
From: Bob Proctor <rproctor@together.net>
Subject: KEDIT .KLD file -Win'95
Message-Id: <3332B72B.65F7@together.net>

I recently upgraded from a DOS version of Kedit to Kedit 1.5 for
Windows. Does anyone know of or have a KEDIT Language Definition File
for perl5?  

Kedit has always been a powerful DOS/Windows editor that supports a high
function macro language. The Windows version now has syntax coloring,
and for that to work, you need the KLD file. 

Help finding this file would be appreciated!
 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Bob Proctor (Bob-VT-)       rproctor@together.net
                            rproctor@delphi.com  
                            http://together.net/~rproctor/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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

Date: Fri, 21 Mar 1997 22:07:16 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: Looking backwards through a text file
Message-Id: <E7Eys4.qD@nonexistent.com>

On Fri, 21 Mar 1997 22:36:36 +0900, Christopher Wright wrote in comp.lang.perl.misc:
++ Hi Hi
++ 
++ Sorry....  I've looked all over in beginner world and can't seem to
++ figure this one out and I'm sure it's pretty simple.. 
++ 
++ How do I go through a text file backwards rather than forwards without
++ reading it into an array first ?  Everything I've seen uses "while"
++ going from start to finish.
++ 

Assuming you still want to have one line at the time, each line
non-reversed, the following will do:

my $line;
foreach $line (reversed <>) {
   whatever ...
}



Abigail



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

Date: Fri, 21 Mar 1997 18:16:30 -0800
From: Eric Caplain <caplain@znet.com>
Subject: Matching multiple instances of patterns per line
Message-Id: <33334103.3E5C@znet.com>

1. Is there a convenient way to match mulitple instances of a type of
pattern on one line without progressively testing the postmatch? I need
to find instances of tags, zero or more per line.

2. Once this problem is solved, I want to generate a list of all unique
tags as they're found. I know I can do this with an assoiciative array,
but I haven't come up with an efficient algorithm yet, so any
recommendations would be appreciated.

-- 
Eric Caplain
caplain@znet.com
http://sf.znet.com/~caplain


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

Date: Fri, 21 Mar 1997 23:34:28 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Matching multiple instances of patterns per line
Message-Id: <41rvg5.8s4.ln@localhost>

Eric Caplain (caplain@znet.com) wrote:
: 1. Is there a convenient way to match mulitple instances of a type of
: pattern on one line without progressively testing the postmatch? I need
: to find instances of tags, zero or more per line.

m//g
   ^


: 2. Once this problem is solved, I want to generate a list of all unique
: tags as they're found. I know I can do this with an assoiciative array,
: but I haven't come up with an efficient algorithm yet, so any
: recommendations would be appreciated.

--------------
#! /usr/bin/perl -w

$_ = '<a href="znet.com">come <b>here</b></a> <b>NOW</b>';

$tags{$1}++ while (m#(<.*?>)#g);

foreach (sort keys %tags) {
   print "saw '$_' $tags{$_} times\n";
}
--------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 22 Mar 1997 06:09:52 GMT
From: "Dean Ouellette" <deano@nh.ultranet.com>
Subject: Perl for win95
Message-Id: <01bc3687$918db780$0a46a2cd@deano.nh.ultranet.com>

I am leaning Perl,  Is there anywhere I can download a free version of Perl
5??

Thanks in advance
Dean Ouellette


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

Date: Sat, 22 Mar 1997 05:07:38 GMT
From: ahardy@magbelle.com (Anthony Hardy)
Subject: Re: Perl on Windows 95
Message-Id: <333368c1.1380205@newsman.viper.net>

You can get Perl for Windows 95 from Windows95.com   It has it's won
install and auto associates extensions.  I have installed it on
serveral machines with 100% success.  To get it..goto
windows95.com/search.html and search for perl

On Tue, 11 Mar 1997 14:28:04 +0900, Takeshi Tojo <tojo@ird.jri.co.jp>
wrote:

>Try ".pl   c:\perl5\bin\perl.exe %s %s"
>
>> I have Perl5.003 and pws1.0 - and also associated .pl with
>> c:\perl5\bin\perl.exe, and in the registry added an entry
>> ".pl   c:\perl5\bin\perl.exe" (as suggested in one of the dejanews
>> articles) but still no luck...
>
>-- 
>Takeshi Tojo / The Japan Research Institute, Ltd.



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

Date: Fri, 21 Mar 1997 17:56:05 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: quell <quell@xnet.com>
Subject: Re: Please Help With Regular Expression
Message-Id: <Pine.GSO.3.96.970321175414.6418D-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, quell wrote:

> I need a regular expression to replace spaces with underscores.  

I'd use this, but it's not a regular expression. (It's faster.)

    tr/ /_/;

> I tried this and it did not work:
> 
> $attribute1 =~ s/ /_/g;

Really? Good luck!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Fri, 21 Mar 1997 18:07:10 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Wlodzimierz Kaluza <Wlodzimierz.Kaluza@mch.sni.de>
Subject: Re: Q: download htm from a perl script?
Message-Id: <Pine.GSO.3.96.970321180629.6418G-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, Wlodzimierz Kaluza wrote:

> could somebody tell me how can I download a htm file from remote web
> server with a perl script? 

Step one: Get modules from CPAN. Hope this helps!

    http://www.perl.com/CPAN/
    http://www.perl.org/CPAN/

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Fri, 21 Mar 1997 18:05:57 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bruce Bromberek <bromberek@cems.umn.edu>
Subject: Re: Questions about the System Command
Message-Id: <Pine.GSO.3.96.970321175841.6418F-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, Bruce Bromberek wrote:

> My understanding of how the command works based on the Using and
> Learning PERL books.  According to those sources (unfortunatly NOT the
> second editions) the perl script should wait for the system command to
> finish executing before continuing on to the next line. 

Exactly correct.

> My experience has been just the opposite.  For example:  if the
> following two commands are given in a shell
> 
> stage -i		#initialize stage controller
> stage -a 1000 1000	#move to 1000,1000
> 
> everything works just fine.
> 
> In my perl script
> 
> system("stage -i");
> system("stage -a $x $y");
> 
> leads to an error because the device is still busy from the first
> command when the second one is executed.  

Perl is waiting for the stage process to finish before it goes on. But it
sounds as if the stage command starts _another_ process and doesn't wait
for that process to finish. (But when you're entering commands from the
shell, that other process finishes before you can enter the next command.)
Or, it could be that the device isn't ready even though the command has
finished completely. Have you tried this combination command from the
shell? 

    stage -i ; stage -a 1000 1000

Suggestions:

* Check out the stage command. Maybe you can find a way to tell it to wait
for everything to finish.

* See whether you can find a way to easily detect whether the device is
still busy within your script. 

* See whether you can emulate (a better form of) the stage command
entirely from within Perl.

Good luck!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 Mar 1997 20:52:38 GMT
From: gerben@localhost.cs.vu.nl (Gerben Vos)
Subject: Re: Reg: tr command
Message-Id: <5gusem$ar1@star.cs.vu.nl>

Zacharia George <zgeorge@eos.ncsu.edu> writes:

>	Could someone please tell me how to convert from Uppercase to 
>Lowercase in a string EXCEPT for the first letter of each word in the
>string. I assume that the "tr" command (I may be wrong!) can do this but

You need the \L and \u special substitution escapes of the "s" operator.
The \w matches any series of alphanumerics.

$ echo ZACHARIA george |perl -pe 's/\w+/\L\u$&/g'
Zacharia George

See the section on "Quote and Quotelike Operators" in the perlop manual
page, where the "s" operator is also explained.

 . . . . . . . . . . . . . . . . . . . . . . . . . . . G e r b e n   V o s   <><
mailto:gerben@cs.vu.nl                           http://www.cs.vu.nl/%7Egerben/
Phevbfvgl xvyyrq gur png.


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

Date: 21 Mar 1997 19:01:46 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Brian <signal@shreve.net>
Subject: Re: regex for UNIX usernames needed!
Message-Id: <8cvi6k3cs5.fsf@gadget.cscaper.com>

>>>>> "Brian" == Brian  <signal@shreve.net> writes:

Brian> Has anyone written a thourough regular expression that I can use to
Brian> filter valid UNIX usernames with?

Brian> I am using: /^[a-zA-Z]{1,8]$/

Brian> but feel I need more than that.......I want to use this so the user wont
Brian> enter something they shouldn't, and I am sure someone has already done
Brian> this before...........if you have something like that, please email it
Brian> to me.  Thanks.

Well, ignoring the typo for a moment, a valid Unix username is all lowercase
(uppercase confuses /etc/init's login prompt), and not all numeric (which
confuses chown and friends), so that'd be:

	/^(?=.*?\D)[a-z\d]+$/

And there's really no length limit, although most utilities like it to
be under nine characters.  Just change the final + to {1,8} if you
think you want that restriction.

I presume this has *nothing* to do with email addresses, which are
generally much more permissive, since an email address is not
necessarily a user account (such as fred&barney@stonehenge.com).

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 528 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 22 Mar 1997 06:39:37 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: regex for UNIX usernames needed!
Message-Id: <oeeiv2kk0ae.fsf@alpha.hut.fi>


: Well, ignoring the typo for a moment, a valid Unix username is all
: lowercase (uppercase confuses /etc/init's login prompt), and not all
: numeric (which confuses chown and friends), so that'd be:
: 
: 	/^(?=.*?\D)[a-z\d]+$/
: 
: And there's really no length limit, although most utilities like it to
: be under nine characters.  Just change the final + to {1,8} if you
: think you want that restriction.

This is mostly ok. I just feel compelled to ask 'says who?' I have
never seen a standard saying anything about UNIX usernames, anything
about restrictions. It is all a question of how confused would various
UNIX utilities be "if" (read: each utility having to do with usernames
has answered this very question in its own way which normally is
different from any other) This wouldn't be the first time I've been
known to have erred and of there is really such a standard please let
me and other readers of comp.lang.perl.misc know. But even if there
were a Standard about this, it all comes down to the "greatest common
denominator" of all the utilities. Based on my experience I'd suggest

 	/^[a-z][a-z\d_-]{1,7}$/
 
That's pretty restrictive. In some systems even things like '.' work
(j.r.hacker@foo.bar) and in some even eight-bit characters work
(jdger@flip.flop.de). But if you wanna play safe, try the above.

-- 
$jhi++;
# Jarkko Hietaniemi <URL:http://www.iki.fi/~jhi/> <URL:mailto:jhi@iki.fi>
# Lost interest?  It's so bad I've lost apathy.
# Not speaking for any past, present, or future employers.


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

Date: Fri, 21 Mar 1997 17:53:46 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "R. Vince" <rvince@sprynet.com>
Subject: Re: surrogate for flastmod
Message-Id: <Pine.GSO.3.96.970321175246.6418C-100000@kelly.teleport.com>

On 21 Mar 1997, R. Vince wrote:

> IS anyone aware of a public domain script which does the equivalent of
> the SSI <--#flastmod for files on a different server? I am trying to
> create a script which returns the date of the last revision to a file on
> a remote server.

Can't you do that with one of the web modules from CPAN? Hope this helps!

    http://www.perl.org/CPAN/
    http://www.perl.com/CPAN/

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 22 Mar 1997 06:51:22 GMT
From: c.c.eiftj@33.usenet.us.com (Rahul Dhesi)
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <5gvvha$f55@samba.rahul.net>

In <ombu8df1c2.fsf@tees.cs.ualberta.ca> Vladimir Alexiev
<vladimir@cs.ualberta.ca> writes:

>Consider this: DFA
>(deterministic automata) and NFA (non-deterministic ones) have the same
>expressive power, namely that of regular languages.

Therefore to decide whether a perl pattern is a regular expression we
need only ask if we can create either a DFA or an NFA to implement the
search.

In general we cannot implement the search for most perl patterns
with DFAs or NFAs because most of them require backtracking.

Because to implement backtracking you must augment the DFA or NFA with
memory, and once you add memory, it's no longer a DFA or NFA.  A DFA or
NFA has no memory, other than knowing what state it is in.  It does not
remember how it got to that state, so it cannot backtrack.
-- 
Rahul Dhesi <dhesi@spams.r.us.com>
a2i communications, a quality ISP with sophisticated anti-junkmail features
** message body scan immune to fake headers ***   see http://www.rahul.net/
>>> "please ignore Dhesi" -- Mark Crispin <mrc@CAC.Washington.EDU> <<<


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

Date: Fri, 21 Mar 1997 23:28:58 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Uninitialized "next" with -w ?
Message-Id: <qmqvg5.br4.ln@localhost>

Clark Dorman (dorman@lee.s3i.com.anti-spam) wrote:

: I'm rather confused about what -w is complaining about in the following
: code: 


What it is complaining about is $ARGV[0] being undef.

Why it gets confused about the line number, I don't know.


Try invoking it this way:

h.pl -cfoo bar

No complaints when there is an arg past the flags.


: ----------------------------------------------------------------------
: #!/home/dorman/bin/perl -w

: $clean_up = 0;

: while ( $ARGV[0] =~ /^-/ ) {
:    $_ = shift ;


After the last '-c' flag, $ARGV[0] is set to undefined if no
more args (see shift() in perlfunc man page)

When you get back to the top of the loop, you are trying to
match in an 'undef' (uninitialized) string.


:    if ( /-c.*/ ) {
:       $clean_up++;
:       next;
:    }
: }

: &clean_up_sub if $clean_up;
: ----------------------------------------------------------------------

: When I run this, it says:

: blackbird:testdir (7:21pm) 91% h.pl -c
: Use of uninitialized value at h.pl line 9.
: blackbird:testdir (7:21pm) 92% 

: i.e., it doesn't like the "next".  What value is uninitialized?  


So, if it's complaining when $ARGV[0] is undef, check for it
before using it:

while ( defined($ARGV[0]) && ($ARGV[0] =~ /^-/) ) {



: Is the above an acceptable way to do this, or what is the recommended
: way to parse the command options to the perl program if not?
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That would be the Getopt module  ;-)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 21 Mar 1997 18:14:19 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Matt Riggsby <mriggsby@sybex.com>
Subject: Re: Vanishing string terminators and premature end of script headers
Message-Id: <Pine.GSO.3.96.970321181200.6418H-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, Matt Riggsby wrote:

> Can't find string terminator "NXRheader" anywhere before EOF at

> That second instance of "NXRheader" is, so far as I can tell, alone on
> the line without extraneous spaces, tabs, or other invisible characters,
> so I can't understand why it isn't working. 

Me, neither, if everything is as you say. :-)  But just for fun, change
the declared delimiter to "FOObarBAZ", and add a line that says exactly
that, and see whether Perl can find it. 

> access to (the script) failed for (me), reason: Premature end of script
> headers

That sounds like your server, complaining that instead of seeing
"Content-type" it saw "Can't find string terminator". Ignore it until you
get your script working. Good luck!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

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

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