[11341] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4942 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 19 15:07:21 1999

Date: Fri, 19 Feb 99 12:01:41 -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, 19 Feb 1999     Volume: 8 Number: 4942

Today's topics:
        FMTEYEWTK: Switch Statements <tchrist@mox.perl.com>
    Re: Help, needed to create a 3 tier hash/array structur <d-edwards@nospam.uchicago.edu>
    Re: how do I get a date in perl? <dbc@tc.fluke.com>
        Logic problems with dual loops <wmwilson1@go.com>
    Re: MKDIR (Greg Ward)
    Re: perl compiled code cacheing <tchrist@mox.perl.com>
    Re: perl compiled code cacheing (Sam Curren)
    Re: perl compiled code cacheing (brian d foy)
        Perl flock question <smiles@wfubmc.edu>
    Re: Perl flock question (I R A Aggie)
    Re: Printing all environment variables (Andre L.)
    Re: Printing all environment variables (Greg Ward)
    Re: removing HTML tags froma  file <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: removing HTML tags froma file (Clay Irving)
    Re: removing HTML tags froma file (I R A Aggie)
        Search engine <kjcox@vii.com>
    Re: SSI question? <jabbott@dingo.smig.net>
    Re: The Camel? (brian d foy)
    Re: tie complex data in DBM files <tchrist@mox.perl.com>
    Re: tie complex data in DBM files droby@copyright.com
    Re: Using system with going through the shell <tchrist@mox.perl.com>
    Re: WWW:Search nguyen.van@imvi.bls.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 19 Feb 1999 08:57:00 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: FMTEYEWTK: Switch Statements
Message-Id: <36cd89cc@csnews>

(Original posting: 31 August 1998)

In comp.lang.perl.misc, spiegler@cs.uri.edu writes:
:I cannot find a switch statement in Perl. Is there one? 

man perlsyn or perlfaq7, or look at

http://www.perl.com/CPAN/doc/manual/html/pod/perlsyn.html#Basic_BLOCKs_and_Switch_Statemen
http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq7.html#How_do_I_create_a_switch_or_case

:If not, do you know
:why it was not put into the language?

Because it seems unnecessary as is, and because no decision on something
more powerful has even been decided with.

:Also, does Perl provide any mechanism other than if-elsif-else to deal with
:this?

Many, but all can be placed into one of two classes, either multiple
sequential tests (`linear switches') or else a single that does a multiway
branch (`non-linear switches').  The first sort are all variations on
the same theme.  You can affect performance minusculely by putting the
more likely cases first.  You make a slight semantic distinction between
simple if()s and if/elsif()s chains.  And you can make appearance choices
related to how to the tests are represented syntactically.

The short answer is that the switch statement in Perl is spelled for().
Here's a simple demo:

CASE 1:

    for ($where) {
	/In Card Names/     && do { push @flags, '-e'; last; };
	/Anywhere/          && do { push @flags, '-h'; last; };
	/In Rulings/        && do {                    last; };
	die "unknown value for form variable where: `$where'";
    }

But there is no performance gain to be had over here over a more
traditional arrangement.  If you don't like that style, you can use this:

CASE 2:

    SWITCH: for ($where) {
	if (/In Card Names/) { 
	    push @flags, '-e'; 
	    last SWITCH; 
	}
	if (/Anywhere/) { 
	    push @flags, '-h'; 
	    last SWITCH; 
	}
	if (/In Rulings/) { 
	    last SWITCH; 
	}
	die "unknown value for form variable where: `$where'";
    }

or you can use this:

CASE 3:

    SWITCH: for ($where) {
	if (/In Card Names/) { 
	    push @flags, '-e'; 
	}
	elsif (/Anywhere/) { 
	    push @flags, '-h'; 
	}
	elsif (/In Rulings/) { 
	    ;   # nothing needed
	}
	else {
	    die "unknown value for form variable where: `$where'";
	}
    }


Or more concisely as this:

CASE 4:

    SWITCH: for ($where) {
		if    (/In Card Names/) { push @flags, '-e'; }
		elsif (/Anywhere/)      { push @flags, '-h'; }
		elsif (/In Rulings/)    {                    } # do nothing
		else                    { die "unknown whence: `$where'" }
	    }

There's really nothing to terrible with this, and no completely
convincing reason not to just write the elsif()s:

CASE 5:

    chomp($answer = <>);
    if    ("SEND"  =~ /^\Q$answer/i) { print "Action is send\n"  }
    elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is stop\n"  }
    elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is abort\n" }
    elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is list\n"  }
    elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is edit\n"  }

Or as:

CASE 6:

    if    ($visibility == SCREEN_DISPLAY) {
		# do something
    } 
    elsif ($visibility == SCREEN_HIDDEN) {
		# do something
    } 
    elsif ($visibility == SCREEN_CODEGEN) {
		# do something
    } 
    else { 
		# do something drastic
    } 

Many similar, sequential-testing mechanisms are seen in Perl.
You can use "&& ||" combos, but then you have to be very
careful that the RHS of && is always a true value.

CASE 7:

   $dir = 'http://www.wins.uva.nl/~mes/jargon';
   for ($ENV{HTTP_USER_AGENT}) {
       $page  =    /Mac/            && 'm/Macintrash.html'
                || /Win(dows )?NT/  && 'e/evilandrude.html'
                || /Win|MSIE|WebTV/ && 'm/MicroslothWindows.html'
                || /Linux/          && 'l/Linux.html'
                || /HP-UX/          && 'h/HP-SUX.html'
                || /SunOS/          && 's/ScumOS.html'
                ||                     'a/AppendixB.html';
   }

This is actually better written with a bunch of ?: constructs instead
in most cases because the RHS of the && might false out on you
in the more general case:

CASE 8:

    $which_search = $opts{"t"} ?  'title'
		  : $opts{"s"} ?  'subject'
		  : $opts{"a"} ?  'author'
		  :               'title';

Or if you are assigning a list, you could do this:

CASE 9:

    ($msg, $defstyle) = do {
	$i == 1 ? ("First", "Color" )  :
	$i == 2 ? ("Then",  "Rarity")  :
		  ("Then",  "Name"  )
    };

Or even this, amking more use of the do{}'s blockness:

CASE 10:

    ($FORMAT_NAME, $FORMAT_TOP_NAME) = do {
        if    ($long_form)      { qw( Long      Long_Top   ) }
        elsif ($just_inode)     { qw( Inodes    Inodes_Top ) }
        elsif ($sys5)           { qw( SysV      SysV_Top   ) }
        elsif ($bsd)            { qw( BSD       BSD_Top    ) }
        else                    { die " No format?"          } 
    };


Sometimes one has been known to use to do { } superfluously just to make
things look pretty.  Sometimes, aesthetics counts. :-)

CASE 11:

    for ($^O) {
        *struct_flock =                do                           {

                                /bsd/  &&  \&bsd_flock
                                       ||
                            /linux/    &&    \&linux_flock
                                       ||
                          /sunos/      &&      \&sunos_flock
                                       ||
                  die "unknown operating system $^O, bailing out";
        };
    }

The do there is just so the Christmas tree has a star. :-)

Here's another do{} style switch, turned another way:

CASE 12:

   $amode = do {
       if     ($flag & O_RDONLY) { "r" }       # XXX: isn't this 0?
       elsif  ($flag & O_WRONLY) { ($flag & O_APPEND) ? "a" : "w" }
       elsif  ($flag & O_RDWR)   {
           if ($flag & O_CREAT)  { "w+" }
           else                  { ($flag & O_APPEND) ? "a+" : "r+" }
       }
   };

Here's an old example for argument processing:

CASE 13:

    while ($ARGV[0] =~ /^-(.+)/ && (shift, ($_ = $1), 1)) {
	next if /^$/;

	s/a// 	    && (++$autoload,    redo);
	s/p// 	    && (++$postcompile, redo);
	s/f// 	    && do {
			    $FILE = $_ || shift;
			    open(FILE) || die "can't open $FILE: $!";
			    while (<FILE>) {
				push(@required, split(' '));
			    }
			    redo;
		    };

	die "usage $0 [-pa] [-f module_list] [module] ...\n";
    }


And here's another, simpler one:

CASE 14:

    while ($ARGV[0] =~ /^-/) {      
	$ARGV[0] =~ /^-a/ && ($all++,shift,next);
	$ARGV[0] =~ /^-d/ && ($debug++,shift,next);
	$ARGV[0] =~ /^-n/ && ($idle = 0,shift,next);
	$ARGV[0] =~ /^-s/ && ($slumber++,shift,next);
	$ARGV[0] =~ /^-i/ && (shift,$idle=$ARGV[0],shift,next);
	last;
    }

And here's one more.  I used to do this a lot. :-)

CASE 15:

    OPT: while ($ARGV[0] =~ /^-(.*)/ && (shift, $_ = $1, 1)) {

	/^$/        && next OPT;

	/^\d+/      && do {
			$DEPTH = $_;
			next OPT;  
		    };

	s/q//       && do {
			$QUIET = 1;
			redo OPT;
		    }; 

	/d/         && do {
			$debug += s/d//g;
			redo OPT;
		    }; 

	&usage("Unknown option: -$_");
    } 


As you see in the last case, the test doesn't always have to be the
same kind.  There are definite advantages to this approach.  For example:

CASE 16:

    for ( $big->long->hairy->expression ) {
	/pat/i		&& do { ...... };
	$_ >  10	&& do { ...... };
	$_ == 13        && do { ...... };
	lc eq "FRED"    && do { ...... };
	$now > 2*$_     && do { ...... };
	# do default
    } 

In that case, we aren't in each case making the same sort of test (string,
numeric, pattern, etc).  Instead, we pick and choose as we go.  

But all the preceding versions share one critical trait: they all
perform a series of tests sequentially.  That's why we called them
`linear switches' above.  That means that they don't scale well to a
large number of cases.  Of course, this really never matters all that
much, since in the number of different cases we're talking about here
is virtually always too small to fret over.

But any good programmer, when confronted with extremely similar code,
has a nearly irrepressible urge to unify.  As Kernighan has said, one
should capture regularity with data, irregularity with code.  That 
means that seeing repeated instances of a nearly identical thing, 
like this:

    if ($who eq "Fred")   { ... }
    if ($who eq "Barney") { ... }
    if ($who eq "Wilma")  { ... }

makes any programmer worth his salt say, ``That's too much similarity
in code.  It should be in data!''  And indeed, it probably should be,
and like most interesting data structures in Perl, this should likely
be based on a hash.  Here's what you could do instead:

CASE 17:

    %action = (
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
	# add as you will
    );

    if ($verb = $action{$who}) {
	&$verb();
    } else {
	die "unknown character: $who";
    } 

Those of you corrupted into the infinite hunt for a one-liner
to everything might prefer this approach:

CASE 18:

    {
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
    }->{$who}->();

Except that now you haven't managed to catch the null case.

CASE 19:

    ( {
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
    }->{$who} || sub { die: "who's $who?" })->();

But that's getting a bit silly.  Better there to
do it in several steps.

These functions can even be defined right there as closures:

CASE 20:

    %actions = (
        "edit"  => \&invoke_editor,
        "send"  => \&deliver_message,
        "list"  => sub { system($PAGER, $file) },
        "abort" => sub {
                        print "See ya!\n";
                        exit;
                   },
        ""      => sub {
                        print "Unknown command: $cmd\n";
                        $errors++;
                   },
    );

    $href = abbrev(keys %actions);

    local $_;
    for (print "Action: "; <>; print "Action: ") {
        s/^\s+//;       # trim leading  white space
        s/\s+$//;       # trim trailing white space
        next unless $_;
        $actions->{ $href->{ lc($_) } }->();
    }

Imagine where you had a switch with 100 cases in a tight loop.  You'd
definitely want to hash up the cases for instant access rather than
making all the tests each time.  In fact, this would scale to any number
of cases (assuming that the hash keys weren't permutations of each other,
which pessimizes perl's hashing).

Here's an example of a non-linear switch with an in-line hash:

CASE 21:

    my $newop = {
	'==' 	=> 	'eq',
	'!=' 	=> 	'ne',
	'>=' 	=> 	'ge',
	'>'  	=> 	'gt',
	'<=' 	=> 	'le',
	'<'  	=> 	'lt',
	'=~' 	=> 	'=~',
	'!~' 	=> 	'!~',
    }->{$operator} || "MISSING OPERATOR";

It would be marginally better to assign that to a named hash once,
as we did in the previous case.  

Those of you who have coded up finite state machines may be familiar
with one final approach:

CASE 22:

    while ($state = $action_table{$state}->()) {
	print "Moving on to state $state\n";
    } 

Here, each function state in the action table returns the next state to
transition to.  The table would hold as values the function to call at
each state, and those functions would return a string which is the next
state to go to.

So, anybody read this far? :-)

--tom
-- 
    "If ease of use is the highest goal, we should all be driving golf carts."
    	--Larry Wall


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

Date: Fri, 19 Feb 1999 18:14:47 GMT
From: Darrin Edwards <d-edwards@nospam.uchicago.edu>
Subject: Re: Help, needed to create a 3 tier hash/array structure
Message-Id: <tgzp6a6z1k.fsf@noise.bsd.uchicago.edu>

lee.gammell@ctaylor.co.uk writes:

> I would like to create a 3 tier structure using
[snip] 
> #! /usr/bin/perl
> 
> # try to create a 3 tier structure ...
> #
> # create a sample entry for volume v1
> #
> $VOL{"v1"} = 100;
> $VOL{"v1"}{"p1"} = 100;
[snip rest of code]

> However, it produces this
> 
> Volume: v1 size: 100
> 	Plex: p1 size: 100
> 		Subdisk: p1 size: 100
> 		Subdisk: p2 size: 100
> 		Subdisk: s1 size: 25
> 		Subdisk: s2 size: 25
> 		Subdisk: s3 size: 25
> 		Subdisk: s4 size: 25
> 	Plex: p2 size: 100
> 		Subdisk: p1 size: 100
> 		Subdisk: p2 size: 100
> 		Subdisk: s1 size: 25
> 		Subdisk: s2 size: 25
> 		Subdisk: s3 size: 25
> 		Subdisk: s4 size: 25
> 	Plex: s1 size: 25
> 	Plex: s2 size: 25
> 	Plex: s3 size: 25
> 	Plex: s4 size: 25
[snip]
If you run it using "use strict;", it actually produces even less:

Can't use string ("100") as a HASH ref while "strict refs" in use
at -e line 3.

Consider those first 2 lines up above:
> $VOL{"v1"} = 100;
> $VOL{"v1"}{"p1"} = 100;

The first sets the _value_ of $VOL{v1} to be 100, and the next line
immediately tries to dereference this value as if it were a hash
reference.  In other words, you're asking for the {p1} key of a
hash "called" %{"100"}.  This is possible with symbolic references,
and if that's really what you meant to do, then please ignore the
rest of this message.

In general, you can probably accomplish what (I think) you want using
hard references ("use strict;" will make symbolic refs, among other
things, fatal errors).  For example, just make the relevant sizes
additional keys in your hashes:

#!/usr/local/bin/perl -w;
#That -w will help you as much as the next line, if not more!
use strict;

my %VOL;
$VOL{v1}{SIZE} = 100;
$VOL{v1}{p1}{SIZE} = 100;
$VOL{v1}{p1}{s1} = 25;
$VOL{v1}{p1}{s2} = 25;
$VOL{v1}{p1}{s3} = 25;
$VOL{v1}{p1}{s4} = 25;
$VOL{v1}{p2}{SIZE} = 100;
$VOL{v1}{p2}{s1} = 25;
$VOL{v1}{p2}{s2} = 25;
$VOL{v1}{p2}{s3} = 25;
$VOL{v1}{p2}{s4} = 25;

foreach my $vname (sort keys %VOL ) {
  print "Volume: $vname size: $VOL{$vname}{SIZE}\n";

PLEX: foreach my $pname (sort keys %{ $VOL{$vname} }) {
    next PLEX if ($pname eq 'SIZE');
    print "\tPlex: $pname size: $VOL{$vname}{$pname}{SIZE}\n";

SUBDISK: foreach my $sname (keys %{$VOL{$vname}{$pname}}) {
      next SUBDISK if ($sname eq 'SIZE');
      print "\t\tSubdisk: $sname size: $VOL{$vname}{$pname}{$sname}\n"
    }
  }
}

For me this now produces:
Volume: v1 size: 100
        Plex: p1 size: 100
                Subdisk: s1 size: 25
                Subdisk: s2 size: 25
                Subdisk: s3 size: 25
                Subdisk: s4 size: 25
        Plex: p2 size: 100
                Subdisk: s1 size: 25
                Subdisk: s2 size: 25
                Subdisk: s3 size: 25
                Subdisk: s4 size: 25

which you said was your desired output.
Things to note:
1) The labels PLEX and SUBDISK aren't necessary here, since
   next defaults to the innermost enclosing loop.
2) You can get rid of the ugly next trick altogether if you add another
   layer to your data structure, e.g. $VOL{v1} has keys SIZE and PLEXES,
   and $VOL{v1}{PLEXES} points to your list of p1,p2.  Same idea for
   subdisks.
3) You could write subs to calculate the plex size from the contained
   subdisk size, and the volume size from the contained subdisk size,
   instead of manually inserting them.  I didn't want to give an example
   since I don't know how you're actually determining those numbers
   (why v1 size is 100 instead of 200, for example).

Hope this helped,
Darrin


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

Date: Fri, 19 Feb 1999 10:55:06 -0800
From: Dan Carson <dbc@tc.fluke.com>
Subject: Re: how do I get a date in perl?
Message-Id: <Pine.LNX.3.95.990219105138.23115A-100000@dbc-pc>

On Fri, 19 Feb 1999, Ronald J Kimball wrote:

> What does this have to do with getting a date?  Last time I used the
> line about an example of the array of output from localtime(time) at a
> singles bar, I got a drink thrown in my face.
> I think I'll stick with "What's your sign?".

Maybe you should have told the one about the $string that .= into the $bar.

-Dan

-- 

With Perl, there's more than one way to do it!



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

Date: Fri, 19 Feb 1999 18:56:50 GMT
From: wil <wmwilson1@go.com>
Subject: Logic problems with dual loops
Message-Id: <7akc5c$3k4$1@nnrp1.dejanews.com>

I'm having a problem with my logic on this, any help would be great!
I'm creating a program in which I create an infinite loop (cheesy daemon):

while(1) {...
  open(CMD)
  while(<CMD>) {
         loop through, line by line looking for stuff
         If $line != this {
                if $myhash{$line}
                        do stuff
                else
                        add a new hash key => value
                        do stuff
  }

the other thing I have to do is check to see if the old hash keys are no
longer present in the CMD.  Currently I perform both these loops (on the same
command) seperately, the second loop looking something like

foreach $key (sort keys(%myhash)) {

              open(CMD...
              while(<CMD>)
                    if(!/$key/) {
                              delete $myhash{$key};
                  }
}

I can't really think of a decent way to combine these two loops to be more
efficient and cleaner.  Please help!

        Thanks!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 19 Feb 1999 18:31:48 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: MKDIR
Message-Id: <7akamk$2ve$4@news0-alterdial.uu.net>

colin.taylor@ec.gc.ca wrote:
> I am very new to Perl and am trying to create a new directory with a mkdir
> command but it doesn't work. I get a message saying I am missing a parameter.

In reply, Dominik Furger <dominik.furger@bluewin.ch> wrote:
> Things like this should do what you need:
> 
> $TMPDATA="$DATADIR/tmp";
> mkdir ("${TMPDATA}",0755) ;

Why all the extra line noise?  You don't need to put that $TMPDATA
variable into double quotes, and you don't need curlies around it.
This'll work just fine:

  mkdir ($TMPDATA, 0755);

and is more readable.  Come to think of it, ALL UPPER CASE VARIABLE
NAMES aren't very readable either.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: 19 Feb 1999 11:31:08 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl compiled code cacheing
Message-Id: <36cdadec@csnews>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, samc@empirewest.com (Sam Curren) writes:
:If you save on tenth of a second on a script that is run 5,000 times in a 
:day, you would save 8 minutes and 20 seconds of processor time. 

Micro-optimizations are useless but dangerous hobgoblins that
haunt the deluded minds of uncounted programmers of small capability.

--tom
-- 
I have a different view of the world.  --Andrew Hume. Show&Tell '87


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

Date: Fri, 19 Feb 1999 11:23:13 -0800
From: samc@empirewest.com (Sam Curren)
Subject: Re: perl compiled code cacheing
Message-Id: <MPG.113759ffd857e4a79896e3@news.sonic.net>

Well stated. Thanks for the answer.

-Sam

In article <36cdadec@csnews>, tchrist@mox.perl.com says...
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, samc@empirewest.com (Sam Curren) writes:
> :If you save on tenth of a second on a script that is run 5,000 times in a 
> :day, you would save 8 minutes and 20 seconds of processor time. 
> 
> Micro-optimizations are useless but dangerous hobgoblins that
> haunt the deluded minds of uncounted programmers of small capability.
> 
> --tom
> 


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

Date: Fri, 19 Feb 1999 14:50:09 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: perl compiled code cacheing
Message-Id: <comdog-ya02408000R1902991450090001@news.panix.com>

In article <MPG.113744bea91bbd3f9896e1@news.sonic.net>, samc@empirewest.com (Sam Curren) posted:

> In article <m3d836ba7n.fsf@joshua.panix.com>, jdf@pobox.com says...
> > samc@empirewest.com (Sam Curren) writes:

> > > I understand about mod_perl, but it seems as though it's a solution
> > > that avoids the problem.
> > 
> > In what way does it "avoid the problem"?  It seems to do exactly what
> > you want.
> 
> No. To my [possibly incorrect] understanding, you have to make a 
> modification to the web server. While that may be easy for some, I 
> usually run my scripts on servers that I have no controll over. 

that's easy to fix.  use a system or service that provides the 
features that you want.  or make the case to whomever controls the 
server that you need mod_perl.  of course, this requires a little
bit of social engineering, but that's how some programming problems
are best solved :)

> Second, mod_perl requires [I think] the server to hold the script in 
> memory. This only compiles the script once, but it also consumes some 
> resources. This 'avoids the problem' by cacheing the compiled code in 
> temporary memory, consuming resources. 

RAM is cheap.  if you want to be quick, RAM is where you want your
cached script.  the memory used by mod_perl is not really a concern
though.  certainly it takes up more memory to use mod_perl with a 
server, but it's not a prohibitive amount even for hundreds of
scripts.  it's not emacs in that regard ;) (that's a joke.  please
don't bite on a perceived troll.)

> If it were stored in a temporary 
> file on the server, then that compile time could be eliminated (or at 
> least greatly reduced) without the overhead.

but then you lose a bit because you have to interact with the file
system.

> I'm not trying to replace mod_perl. I'm looking for a different 
> optomization method that can benefit more scripts with less trouble.

have you even tried mod_perl?  outside of installation, i have not
had to think about it at all (from an administration perspective). 
it could not be any easier!  the mod_perl installation will even
make the apache source for you.

but, if you don't like any of this, make your own code caching
system and when you have it to a reasonable point, release it 
as open source. no sense continuing to carp over something you 
didn't get with the already free perl, apache, and mod_perl if
you aren't going to help.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: Thu, 18 Feb 1999 13:05:20 -0500
From: Steve Miles <smiles@wfubmc.edu>
Subject: Perl flock question
Message-Id: <36CC5660.5B91D972@wfubmc.edu>

Say you have two single file scripts that call and write to the same
database. If both scripts are frequently used,
you would have to flock your database in each script so they don't
compete with each other and
possibly corrupt the database.

My question is: What if in each script you 'require "otherscript.cgi";'
so that when one script is called it requires the other - in that case
would that solve the database locking problem?

=============================================
Steve Miles (smiles@wfubmc.edu)
----> http://www.groundbreak.com  <----
Wake Forest University School of Medicine
5019 Hanes, Medical Center Blvd.
Winston-Salem, NC 27157
Phone: 336.716.0454     FAX: 336.716.7200
=============================================




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

Date: 19 Feb 1999 19:16:34 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Perl flock question
Message-Id: <slrn7cre9d.qg4.fl_aggie@enso.coaps.fsu.edu>

On Thu, 18 Feb 1999 13:05:20 -0500, Steve Miles <smiles@wfubmc.edu> wrote:

+ My question is: What if in each script you 'require "otherscript.cgi";'
+ so that when one script is called it requires the other - in that case
+ would that solve the database locking problem?

Why do you think this will work?

James



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

Date: Fri, 19 Feb 1999 12:49:26 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Printing all environment variables
Message-Id: <alecler-1902991249260001@dialup-654.hip.cam.org>

In article <36CD98FE.3CE3C41B@giss.nasa.gov>, jglascoe@giss.nasa.gov wrote:

> my @env_keys = keys %ENV;
> @env_keys = sort { $a cmp $b } @env_keys;
> for my $key (@env_keys)
> {
>         my $val = $ENV{$key};
>         print "$key\t$val\n"
> }

Or, if you don't have the budget for superfluous variables :-),

   foreach (sort keys %ENV) {
      print "$_\t$ENV{$_}\n";
   }

sort() does sort {$a cmp $b} by default.

Andre


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

Date: 19 Feb 1999 18:34:16 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: Printing all environment variables
Message-Id: <7akar8$2ve$5@news0-alterdial.uu.net>

Christian M. Aranda <christian.arandaNOSPAM@NOSPAMiiginc.com> wrote:
> Now, I know that I can print %ENV and get all the environment
> variables.  But because it's a hash, it won't print very legibly.  Is
> there any good way to print them all so I can compare them?

Surely this is a FAQ... but what the hell:

  foreach $v (sort keys %ENV) { print "$v=$ENV{$v}\n"; }

Easy enough?  That gives identical output to the shell's 'printenv'
command.

If you want more details, see the Data::Dumper module (standard with
Perl 5.005, or get it from CPAN if you haven't upgraded yet).

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: 19 Feb 1999 19:12:30 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: removing HTML tags froma  file
Message-Id: <83hfsi460h.fsf@vcpc.univie.ac.at>

Re: removing HTML tags froma  file, Cybernetic
<cybear_x> said:

Cybernetic> I want to convert HTML files to simple
Cybernetic> text files. Is there a way to find and
Cybernetic> remove the HTML tags within PERL?

Simple example using those wunnerful modules...

    use HTML::TreeBuilder;
    my $h = HTML::TreeBuilder->new();
    
    $h->parse_file($YOUR_HTML_FILE_GOES_HERE);
     
    use HTML::FormatText;
    my $f = HTML::FormatText->new(rightmargin => 50);
    
    print $f->format($h);

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien.  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


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

Date: 19 Feb 1999 14:08:38 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: removing HTML tags froma file
Message-Id: <7akcrm$rnq$1@panix.com>

In <36cda040.75669693@news.webhart.net> cybear_x[nospam]@geocities.com (Cybernetic Bear) writes:

>I want to convert HTML files to simple text files. Is there a way to
>find and remove the HTML tags within PERL?

Yes! Perl is *real* good at tasks like this.

-- 
Clay Irving
clay@panix.com


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

Date: 19 Feb 1999 19:17:52 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: removing HTML tags froma file
Message-Id: <slrn7crebq.qg4.fl_aggie@enso.coaps.fsu.edu>

On 19 Feb 1999 14:08:38 -0500, Clay Irving <clay@panix.com> wrote:
+ In <36cda040.75669693@news.webhart.net> cybear_x[nospam]@geocities.com (Cybernetic Bear) writes:
+ 
+ >I want to convert HTML files to simple text files. Is there a way to
+ >find and remove the HTML tags within PERL?
+ 
+ Yes! Perl is *real* good at tasks like this.

Gosh, I think there might even be a module that does something like that...

James


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

Date: Fri, 19 Feb 1999 19:55:08 +0000
From: "Kerry J. Cox" <kjcox@vii.com>
Subject: Search engine
Message-Id: <36CDC19C.32584377@vii.com>

Just wondering if anyone could point me to a nice Perl script that
searches out words or keywords.  I have a lot of files located in
multiple directories that I want to put on a CD.  I want to make it
possible so that users could bring up a simple HTML page located on the
CD and execute a search that will look through the CD for the file they
want.
Thanks.
KJ

--
 .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
| Kerry J. Cox          Vyzynz International Inc.       |
| kjcox@vii.com         Systems Administrator           |
| (801) 596-7795        http://vii.com                  |
| All Things Linux      http://quasi.vii.com/linux/     |
`-------------------------------------------------------'





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

Date: Fri, 19 Feb 1999 18:35:41 +0000
From: abbott in Northfield <jabbott@dingo.smig.net>
Subject: Re: SSI question?
Message-Id: <36CDAEFD.85F02FA5@dingo.smig.net>

"Guo, Yongping" wrote:

> <!--#exec cgi="http://cs.franklin.edu/class-cgi-bin/guo/count.pl"-->,
> it give me an error for access the directory.(cs.franklin.edu is the
> server)
>
> Any help is appreciated!
>

You don't need to exec cgi this.  Just put it in as an image <img
src="etc.ect/quo/count.pl">

--ja




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

Date: Fri, 19 Feb 1999 14:33:32 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: The Camel?
Message-Id: <comdog-ya02408000R1902991433320001@news.panix.com>

In article <36CD33B3.EE5D3A74@hsr.ch>, " Patrick Rueegg," <prueegg@hsr.ch> posted:

> Who knows why there is always a camel whith Perl?

Because Larry wanted a Camel on the cover of his (and Randal's)
book and convinced the appropriate person at O'Reilly to do it.

O'Reilly books are often referred to by their distinctive covers.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: 19 Feb 1999 11:43:39 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: tie complex data in DBM files
Message-Id: <36cdb0db@csnews>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Steve Miles <smiles@wfubmc.edu> writes:
:if I tie it to a DBM file I just get a "ARRAY(8x80s8x7)" when I reopen
:the database and
: print "@{ $hash{$data}";.

Somehow you appear to have missed the proper answer when you studiously
searched the standard Perl documentation on your very own system.
It was there waiting for you.

% man perlfaq4

   How can I store a multidimensional array in a DBM file?

   Either stringify the structure yourself (no fun), or else get the
   MLDBM (which uses Data::Dumper) module from CPAN and layer it on top
   of either DB_File or GDBM_File.

--tom
-- 
"When you type to Unix, a gnome deep in the system is gathering your
characters and saving them in a secret place."  - Unix 6th edition manual


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

Date: Fri, 19 Feb 1999 18:52:06 GMT
From: droby@copyright.com
Subject: Re: tie complex data in DBM files
Message-Id: <7akbsh$385$1@nnrp1.dejanews.com>

In article <36CC3616.F7E68B13@wfubmc.edu>,
  Steve Miles <smiles@wfubmc.edu> wrote:
> Hi,
>
> I'm been working with fairly complex hashes containing hashes and
> arrays, but I then tried to implement these same structures and store
> them using DBM files and none of the complex structures appear to be
> saved.
>
> While I can :
> push (@{ $hash{$data} }, $newdata);
> and print "@{ $hash{$data}";
>
> if I tie it to a DBM file I just get a "ARRAY(8x80s8x7)" when I reopen
> the database and
>  print "@{ $hash{$data}";.
>
> Any suggestions?

MLDBM, available at a CPAN near you.

Those DBM files can only hold hashes of string scalars, so if you just tie a
complex data structure normally the references get stringified and thereby
turned into useless muck.  MLDBM, using Data::Dumper, sets up a way of
stringifying the structure in a way that encapsulates the actual data.

--
Don Roby

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 19 Feb 1999 08:49:26 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Using system with going through the shell
Message-Id: <36cd8806@csnews>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, wil <wmwilson1@go.com> writes:
:    system("rcp", $arg, $host, $arg2);
:    system("rcp", $arg, $host:$arg2);

system("rcp", $arg, "$host:$arg2");

--tom
-- 
"Premature optimisation is the root of all evil."
    --Knuth


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

Date: Fri, 19 Feb 1999 19:28:40 GMT
From: nguyen.van@imvi.bls.com
Subject: Re: WWW:Search
Message-Id: <7ake0r$5au$1@nnrp1.dejanews.com>

Hi,

I guess that the sccript looks for a module name "path_query.al" in your Perl
Library but couldn't find it. If you want to use this module, you have to put
it in Perl Lib. However this module is not a Perl Module.

Good Luck
Van

In article <36CD7B68.72D6@leeds.ac.uk>,
  CSC6DKF@leeds.ac.uk wrote:
> I,m trying to get WWW:Search up and runing but come accross the
> 	Following error.
>
> 	Error:  500 (Internal Server Error) Can't locate
> 	auto/URI/URL/http/path_query.al in @INC (@INC contains:
> 	/usr/lib/perl5/i386-linux/5.00404 /usr/lib/perl5
> 	/usr/lib/perl5/site_perl/i386-linux /usr/lib/perl5/site_perl .
> 	/usr/tmp/search/lib/perl5/site_perl)
> 	Thu, 18 Feb 1999 15:54:16 GMT
>
> 	It can,t seem to find the file path_query.al,  am not sure if this is
> part of
> 	WWW:Search or in LWP can anyone Help
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

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


Administrivia:

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

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

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 4942
**************************************

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