[10162] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3755 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 18 21:08:40 1998

Date: Fri, 18 Sep 98 18:00:21 -0700
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, 18 Sep 1998     Volume: 8 Number: 3755

Today's topics:
    Re: any way to encrypt my script? <spamsux-tex@habit.com>
        Can GD.pm make 200 dpi gifs? (N.A.F. McNelly)
        Can you speed up this logfile report??? <aboyd@slip.net>
    Re: Can you speed up this logfile report??? (Larry Rosler)
    Re: Can you speed up this logfile report??? <rick.delaney@shaw.wave.ca>
        Common Module Functions...help please! <splinter@monmouth.com>
    Re: Diff between two text files (Alex Barilo)
    Re: flock error (Charles DeRykus)
        Help With Perl Beautification <baliga@synopsys.com>
    Re: Help With Perl Beautification (Matthew Bafford)
    Re: How large is a scalar? and related declaration ques (Larry Rosler)
    Re: How to access 'main' variables from another package (Matthew Bafford)
    Re: making GIF images (Matthew Bafford)
    Re: passing argument !!!! <garry@america.net>
    Re: Perl & Java - differences and uses <merlyn@stonehenge.com>
    Re: Perl 5 & Linux (Jasmin F. Patry)
    Re: Perl 5 & Linux (Michael Fuhr)
    Re: perl generated pages and frames... (Craig Berry)
    Re: PLESE HELP ME!!! (Hans-Georg Rist)
    Re: PLESE HELP ME!!! (Craig Berry)
    Re: PLESE HELP ME!!! (Matthew Bafford)
    Re: STDERR redirection X 2 ?? <merlyn@stonehenge.com>
        strange DB-problem (Verhoeven)
        Table of Contents Generator <moshez@math.huji.ac.il>
    Re: trying to use print<<END; with CGI.pm (Matthew Bafford)
    Re: where is Date::Parse? <thelma@alpha2.csd.uwm.edu>
    Re: where is Date::Parse? (Michael Fuhr)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 18 Sep 1998 17:10:23 +0000
From: Austin Schutz <spamsux-tex@habit.com>
To: bitnut1@my-dejanews.com
Subject: Re: any way to encrypt my script?
Message-Id: <360293FF.64CE@habit.com>

bitnut1@my-dejanews.com wrote:
> 
> >------------------------------------------
> > Question:
> > if I don't want to show my source code
> > to the world, what should I do with my script?
> >------------------------------------------
> > Replies:
> > - format c:
> > - Delete it.
> > - Do you really want to start a religious argument here?
> > - Don't use it where it can be seen.
> >------------------------------------------
> 
	Here's one more:

ftp://ftp.ox.ac.uk/pub/perl/Compiler-a2.tar.gz

	Read the docs. It may not work especially well and there may
be newer versions and it may not run properly on your platform. You
get what you pay for.


> Now, which is it:
> -- Perl is an immature language and unusable for serious work, or
> -- Perl users are immature and unable to answer a simple question.

	Perl is a reasonably mature language that may not have the
features you are looking for. It is excellent for some work and not
so helpful for others. For the most part the same can be said of the
users.

	A good read, IMO, is "Perl versus ...." at
http://language.perl.com/versus/index.html which compares perl to other
languages. If you are looking for languages that compile to bytecode
you might try java or python.
	
	Austin


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

Date: Fri, 18 Sep 1998 19:27:21 -0500
From: nmcnelly@bu.edu (N.A.F. McNelly)
Subject: Can GD.pm make 200 dpi gifs?
Message-Id: <nmcnelly-1809981927220001@ppp-76-23.bu.edu>

I have written a script which uses GD to combine a number of pre-existing 
gifs into a single image.  It works well, but now I need to create 200 dpi
output gifs.

I have tried running the script using 200 dpi source gifs (with the 
coordinates of copy() adjusted appropriately). GD arranges gifs with no 
problem, but the output gif is 72 dpi.  GD also sticks to the sizes of
the source gifs given in the copy() command, so that the output gif is
200/72 times larger.

Is there any workaround that enables GD to not convert gifs to 72 dpi?
If not, is there any other perl module for combining gifs?  (I've
checked CPAN, but can't locate any).

 ......................................................................
Nancy McNelly
http://halfmoon.org   Rabbit in the Moon: Mayan Glyphs and Architecture
http://halfmoon.org/borden/   Virtual Lizzie Borden House


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

Date: 18 Sep 1998 23:21:07 GMT
From: Tony Boyd <aboyd@slip.net>
Subject: Can you speed up this logfile report???
Message-Id: <6tupt4$5lr$1@owl.slip.net>

The company I work for generally sees 1-2 million hits/day.  Our log files
are 200-400 megs each day.  My manager wants to see who clicks which links
on our homepage.  So I wrote a Perl script that looks at the referrer, and
if the referrer is the homepage, then it tallies up the requested file.

The problem is that it gets slow.  5 megs?  Does that under a minute.  50
megs?  Takes 30 minutes.  So I'm hoping the masters here can critique this
code and clue me in to ways that will hyper-optimize the execution:

#!/usr/local/bin/perl

open (FILE, "<log.txt");

foreach $line (<FILE>) {
	chop($line);
	if ($line =~ m!GET (/[^ ]+) HTTP!i) {  #This grabs the file requested
		$match = $1;
		if ($match =~ m![l/]$!i) {  #This makes sure the file is an .html file
			@earls = ($match,@earls);  #This adds it to the array
		}
	}
}

close (FILE);

foreach $result (@earls) {
	$tally{$result} += 1;  #This counts how many times each file is in the array
}

foreach $key (keys(%tally)) {
   print "$tally{$key} for $key\n";  #This prints the results
}

Any advice on better regex checking or maybe a way to skip the earls array
and just drop the tally right into the tally array directly?  Other ideas?

-Tony



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

Date: Fri, 18 Sep 1998 17:07:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can you speed up this logfile report???
Message-Id: <MPG.106c95b43ccc6acc9897b0@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <6tupt4$5lr$1@owl.slip.net> on 18 Sep 1998 23:21:07 GMT, Tony 
Boyd <aboyd@slip.net> says...
> The company I work for generally sees 1-2 million hits/day.  Our log files
> are 200-400 megs each day.  My manager wants to see who clicks which links
> on our homepage.  So I wrote a Perl script that looks at the referrer, and
> if the referrer is the homepage, then it tallies up the requested file.
> 
> The problem is that it gets slow.  5 megs?  Does that under a minute.  50
> megs?  Takes 30 minutes.  So I'm hoping the masters here can critique this
> code and clue me in to ways that will hyper-optimize the execution:

WARNING:  Suggestions not tested (but probably reliable).

> #!/usr/local/bin/perl

Where is the -w flag?

> open (FILE, "<log.txt");

Where is the test for failure to open the file?
 
> foreach $line (<FILE>) {

This grabs all of the file into memory before processing it.  You either 
have tons of RAM or are giving the virtual memory a real thrashing.

  while (<FILE>) {

and process the lines out of $_, or

  while (defined($line = <FILE>)) {

> 	chop($line);

This is a wasted step, because you don't care if there is a newline at 
the end of your data.

> 	if ($line =~ m!GET (/[^ ]+) HTTP!i) {  #This grabs the file requested

If you are sure the 'GET' and 'HTTP' are always upper-case, leave off the 
'/i' modifier, which slows things down.  You can save a small amount of 
space later by moving the capturing left parenthesis not to include the 
slash, which is redundant because it is in every match.

> 		$match = $1;
> 		if ($match =~ m![l/]$!i) {  #This makes sure the file is an .html file

Does it?  How about '.htm' files (omitted) or any other file type that 
happens to end in 'l' (included).  Of course, these are your own files, 
so you probably know what their names are. ;-)  But if not, try this:

  m!(?:\.html?|/)$!i

> 			@earls = ($match,@earls);  #This adds it to the array

 ++$tally{$match};  #This counts how many times each file is in the array

As you mention later, you don't need that array at all.

> 		}
> 	}
> }
> 
> close (FILE);
> 
> foreach $result (@earls) {
> 	$tally{$result} += 1;  #This counts how many times each file is in the array
> }

Not needed.  As you mention later, you don't need that array at all.

> foreach $key (keys(%tally)) {
>    print "$tally{$key} for $key\n";  #This prints the results
> }

If you're not going to sort them, use

  while ($key = each keys %tally) {

so you don't need them all in memory at once.  Why don't you want to sort 
them, though?  Your manager will be happier if you do.

Please let us know how this ends up.  It should go *much* faster.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 19 Sep 1998 00:43:55 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Can you speed up this logfile report???
Message-Id: <3602FFD0.25A69797@shaw.wave.ca>

Larry Rosler wrote:
> 
> [Posted to comp.lang.perl.misc and a copy mailed.]
> 
> In article <6tupt4$5lr$1@owl.slip.net> on 18 Sep 1998 23:21:07 GMT, 
> Tony Boyd <aboyd@slip.net> says...
> > foreach $key (keys(%tally)) {
> >    print "$tally{$key} for $key\n";  #This prints the results
> > }
> 
> If you're not going to sort them, use
> 
>   while ($key = each keys %tally) {
> 
> so you don't need them all in memory at once.

Oops, I think you mean

    while ($key = each %tally) {

but -w will tell you to use something like

    while ( defined($key = each %tally) ) {

in case you have 0 or "" for a key.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Fri, 18 Sep 1998 19:27:27 -0400
From: "Matt" <splinter@monmouth.com>
Subject: Common Module Functions...help please!
Message-Id: <6tuqqc$j96$1@news.monmouth.com>

Hi,

I'm building a shopping cart and I'd like to create it very modular from the
start so I was wondering if anyone could point out some of the useful ones
so I don't have to pick through the docs and read them all.

I need the one which will parse form input.
I need credit card verification one if there is one in any of them.
I need anything else that would be required for secure pages.

If you could also point out the format to use them it would be great.

use CGI;
blah blah blah?   help me out here

I know how to call sub routines but not from .pm files.

-Matt




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

Date: Wed, 16 Sep 1998 22:15:30 GMT
From: hash@email.infotrade.co.uk (Alex Barilo)
Subject: Re: Diff between two text files
Message-Id: <36012356.1923313@news.force9.net>

> and on NT may be the command comp.  But comp expects
> an input from the user after diffing and I am not sure
You might want to try fc.

Cheers,
Alex
---------
All you need is Perl


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

Date: Fri, 18 Sep 1998 22:24:20 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: flock error
Message-Id: <EzI3KK.1tq@news.boeing.com>

In article <35FE91CA.32D064EC@nabu.isg.mot.com>,
David Capredoni  <ldc023@nabu.isg.mot.com> wrote:
>
>I'm trying to lock a file using the flock command,  It works on hpux,
>however it
>won't work on Sun Microsystems Inc. SunOS 5.5.1.  Do any of you know how
>to make the flock command work for the Sun system.  The code is below:
>
>sub ReqNumber {
>
>    my($dLock) = "/tmp/file1.lock";
>    my($LOCK_SH) = 1;
>    my($LOCK_EX) = 2;
>    my($LOCK_NB) = 4;
>    my($LOCK_UN) = 8;
>
>    print "<pre>\n" if $verbose;
>
>    # see if need to wait on semaphore (lock file)
>    open ( DLOCK, ">>$dLock" )  or die "Can't open lockfile, $dLock:
>$!\n";
>
>    # lock semaphore or wait
>    unless (flock (DLOCK, ($LOCK_SH | $LOCK_NB)) ) {
>        print "$$: CONTENTION; waiting for lock ($!) ..." if $verbose;
>        unless (flock (DLOCK, $LOCK_SH)) { die "flock($LOCK_SH): $!\n" }
>
>    }
>     print "$$: lock granted\n" if $verbose;
>
>    #perform code here
>
>
>    flock(DLOCK, $LOCK_UN);        # unlock semaphore
>    close DLOCK;
>    print "</pre>\n" if $verbose;
>}
>

Change flock's $LOCK_SH to $LOCK_EX. 

Writing to a file requires an exclusive rather than a shared
lock. 


hth,
--
Charles DeRykus


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

Date: Fri, 18 Sep 1998 15:53:11 -0700
From: Yogish Baliga <baliga@synopsys.com>
Subject: Help With Perl Beautification
Message-Id: <3602E457.8655479@synopsys.com>

Hi All,

   Does anybody know where to find the perl beautifiers?

   Any kind of help is appreciated.

ThanX in Advance,
Baliga




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

Date: Fri, 18 Sep 1998 20:17:28 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Help With Perl Beautification
Message-Id: <MPG.106cc22791bf1ea59896aa@news.south-carolina.net>

In article <3602E457.8655479@synopsys.com> on Fri, 18 Sep 1998 
15:53:11 -0700, Yogish Baliga (baliga@synopsys.com) pounded in 
the following text:
=> Hi All,
=> 
=>    Does anybody know where to find the perl beautifiers?
=> 
=>    Any kind of help is appreciated.
=> 

Search www.dejanews.com.

This was covered _very_ recently.

Or, cut right to:

http://www.consultix.wa.com/yumpy/

=> ThanX in Advance,

Hope This Helps!

=> Baliga

--Matthew


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

Date: Fri, 18 Sep 1998 16:20:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How large is a scalar? and related declaration question. (clarification)
Message-Id: <MPG.106c8aa02fbfd7509897af@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <MPG.106c66b1258087489896a3@news.south-carolina.net> on Fri, 
18 Sep 1998 17:49:31 -0400, Matthew Bafford <dragons@scescape.net> 
says...
 .> In article <36027AA1.3A48@DejahsPrivateIce.com> on Fri, 18 Sep 
 .> 1998 10:22:11 -0500, Mary E Tyler (dejah@DejahsPrivateIce.com) 
 .> pounded in the following text:
 ...
 .> => $Foo=&FooInt ($This, $That);
 .> 
 .> If predeclared, the & is not needed.

The & is not needed.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 18 Sep 1998 20:12:35 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: How to access 'main' variables from another package
Message-Id: <MPG.106cc0fba73223409896a9@news.south-carolina.net>

In article <6tumg2$qhk$1@nnrp1.dejanews.com> on Fri, 18 Sep 1998 
22:22:58 GMT, spark_1998@my-dejanews.com (spark_1998@my-
dejanews.com) pounded in the following text:
=> I've looked in various books about this, but I find the descriptions
=> very confusing. I want to access variables from the 'main' package from
=> another package. It's clear enough for scalars:
=> 
=> $main::{var}

Close:

$main::var

=> I'm confused about the syntax here, though. The '$' sign is bound to 'main',
=> right? So, %main:: is an hash of all the symbols in main. So how does perl
=> know I want the scalar. I need to be able to access hashes and filehandles in
=> main, not just scalars.
=> 
=> If I create a filehandle and a hash in main:
=> 
=>   $phone{'steve'} = "1234";
=>   open LOG ">filename";
=> 
=> how do I access these symbols from another package?
=> 

Don't know enough about it to not stick my foot in my mouth. :)

=> Thanks

Hope This Helped!

=> Steve

--Matthew


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

Date: Fri, 18 Sep 1998 20:30:58 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: making GIF images
Message-Id: <MPG.106cc50c8cf9d0669896ac@news.south-carolina.net>

In article <6tur1v$jd6$1@news.monmouth.com> on Fri, 18 Sep 1998 
19:31:31 -0400, Matt (splinter@monmouth.com) pounded in the 
following text:
=> Hi,
=> 
=> Anyone like to point out a place to learn how to make GIF images with PERL?
=> 
=> Please don't point me to perldoc on UNIX...its a pain in the ass to navigate
=> through my crap telnet.
=> 
=> thanks,
=> 
=> -Matt
=> 

Visit: http://reference.perl.com/query.cgi?graphics

Find what you need and get your SysAdmin to install it. :)

--Matthew


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

Date: Fri, 18 Sep 1998 22:54:53 GMT
From: Garry Williams <garry@america.net>
Subject: Re: passing argument !!!!
Message-Id: <3602E509.DC7A3DE3@america.net>

What you need to do is post your code, state what you thought would
happen, and show what happened instead.  This guessing what's wrong
without any real data is not going to get it any time soon.  

-Garry Williams

nguyen.van@imvi.bls.com wrote:
> 
> Hi guys,
> 
> none of this is working
> 
> any better other way?
> 
> Thanks
> Van
> 
> In article <MPG.106c3216f54be1989897ac@nntp.hpl.hp.com>,
>   lr@hpl.hp.com (Larry Rosler) wrote:
> > [Posted to comp.lang.perl.misc and a copy mailed.]
> >
> > In article <6ttrl5$qbq$1@nnrp1.dejanews.com> on Fri, 18 Sep 1998 14:44:53
> > GMT, dave@mag-sol.com <dave@mag-sol.com> says...
> > > In article <360253EC.9175A8E2@america.net>,
> > >   Garry Williams <garry@america.net> wrote:
> > ...
> > > >     system("browser_crno.ksh '$DATE' > $DOCS_DIR/$out_put");
> > >
> > > I think you'll need
> > >
> > >     system("browser_crno.ksh \'$DATE\' > $DOCS_DIR/$out_put");
> > >
> > > otherwise the variable $DATE won't get interpolated. Might be even better
> > > to use the generic quoting operators.
> > >
> > >     system(qq[browser_crno.ksh "$DATE" > $DOCS_DIR/$out_put]);
> >
> > Not at all.  The function of the single quotes is to bind the value of
> > $DATE into a single argument for the shell and to prevent further
> > evaluation.  As far as the double-quoted argument for 'system' is
> > concerned, they are just characters in the string, and don't affect the
> > interpolation of $DATE at all.
> >
> > People really should test their assertions, instead of just posting: "I
> > think you'll need...".
> >
> > #!/usr/local/bin/perl -w
> > use strict;
> >
> > my $foo = 'bar';
> > print "'$foo'\n";
> > __END__
> >
> > is all it takes!
> >
> > --
> > (Just Another Larry) Rosler
> > Hewlett-Packard Laboratories
> > http://www.hpl.hp.com/personal/Larry_Rosler/
> > lr@hpl.hp.com
> >
> 
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Fri, 18 Sep 1998 23:00:50 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <8cogsdf2lu.fsf@gadget.cscaper.com>

>>>>> "Larry" == Larry Wall <larry@kiev.wall.org> writes:
[something apropos, as always]

Funny thing.  Dejanews has nearly precisely a two year gap for
any postings to comp.lang.perl.* by this "Larry Wall" guy.

Welcome back.

-- 
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@teleport.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, 18 Sep 1998 21:31:35 GMT
From: jfpatry@undergrad.math.uwaterloo.ca (Jasmin F. Patry)
Subject: Re: Perl 5 & Linux
Message-Id: <EzI14n.o2z@undergrad.math.uwaterloo.ca>

Steve Linberg <linberg@literacy.upenn.edu> wrote:
>"Lee" <lee@mula.demon.co.uk> wrote:
>> #!/usr/bin/perl
>> $inputline = <STDIN>;
>> print( $inputline );
>> 
>> But when I type prog to run it I get a linux error saying file not found
>
>...your path is not set to include the directory your script resides in.
>Force it by referring to it as ./prog (when you are in that directory).  Make

While that may be true, you should also check that perl is actually in
/usr/bin, and change the shebang line if it's not (or add a link to perl in
/usr/bin).

Jasmin


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

Date: Sat, 19 Sep 1998 00:44:59 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Perl 5 & Linux
Message-Id: <6tuuq0$7u4@flatland.dimensional.com>

"Lee" <lee@mula.demon.co.uk> writes:

> I'm running Linux redhat 5.1 and I've started to dabble in perl 5.0
>
> I've done a small prog as follows :
>
> #!/usr/bin/perl
> $inputline = <STDIN>;
> print( $inputline );
>
> saved as file : prog
>
> I set it to be executable using : chmon +x  prog

I assume you mean "chmod +x prog".

> But when I type prog to run it I get a linux error saying file not found

Is prog in your path?  If not, either add its directory to your path
or specify the path when you run it (e.g., /path/to/prog or ./prog).

Is perl really installed as /usr/bin/perl?  If not, find out where
it lives and change the shebang line accordingly.

-- 
Michael Fuhr
http://www.fuhr.net/~mfuhr/


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

Date: 18 Sep 1998 22:54:10 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: perl generated pages and frames...
Message-Id: <6tuoai$lk8$1@marina.cinenet.net>

GaRgL (gargl@worldnet.net) wrote:
: how can i print to different frames using perl ?

The same way you would in any other language.

: i'm currently reading the faq...

The Perl FAQ isn't likely to help you (much, with this specific problem).
Try CGI FAQs instead.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Fri, 18 Sep 1998 22:53:10 GMT
From: hans-georg.rist@zkrd.de (Hans-Georg Rist)
Subject: Re: PLESE HELP ME!!!
Message-Id: <3602e431.2479642@news.uni-ulm.de>

cim@online.ee wrote:

>I have the following problem with Perl:
>
>The code below will return the first 180 chars from $INPUT{'update'},
>but i need it to return all chars before this appears: </P>
>How could i do it?
>I'm using perl5.
>$blaa = substr($INPUT{'update'}, 0, 180);

$blaa = $1 if $INPUT{'update'} =~ /^(.*)<\/P>/;

HG

-- 
| Hans-Georg Rist     ZKRD, Zentrales Knochenmarkspender-Register
| Helmholtzstr. 10    Deutschland, gGmbH
| P.O.B. 4244         German National Registry of Bone Marrow Donors
| D-89032 Ulm         http://www.zkrd.uni-ulm.de
| Phone: +49 731 1507-46, Fax: -50, email: hans-georg.rist@zkrd.de


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

Date: 18 Sep 1998 22:57:13 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: PLESE HELP ME!!!
Message-Id: <6tuog9$lk8$2@marina.cinenet.net>

cim@online.ee wrote:
: The code below will return the first 180 chars from $INPUT{'update'},
: but i need it to return all chars before this appears: </P>
: How could i do it?
: I'm using perl5.
: $blaa = substr($INPUT{'update'}, 0, 180);

  ($blaa = $INPUT{update}) =~ s!</P>.*!!;

That is, copy the entire contents of $INPUT{update} to $blaa, then replace
everything in $blaa from </P> onward with an empty string.

HTH!

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Fri, 18 Sep 1998 20:09:29 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: PLESE HELP ME!!!
Message-Id: <MPG.106cbfd2a966d1cf9896a7@news.south-carolina.net>

In article <3602e431.2479642@news.uni-ulm.de> on Fri, 18 Sep 1998 
22:53:10 GMT, Hans-Georg Rist (hans-georg.rist@zkrd.de) pounded 
in the following text:
=> cim@online.ee wrote:
=> 
=> >I have the following problem with Perl:
=> >
=> >The code below will return the first 180 chars from $INPUT{'update'},
=> >but i need it to return all chars before this appears: </P>
=> >How could i do it?
=> >I'm using perl5.
=> >$blaa = substr($INPUT{'update'}, 0, 180);
=> 
=> $blaa = $1 if $INPUT{'update'} =~ /^(.*)<\/P>/;
=> 
=> HG


Or, if you want:

$_ = (split /<\/[pP]>/, $Text)[0];

Or:

$_ = substr $Text, index($Text, "</P>");


Benchmark:

#!/usr/bin/perl -w

use Benchmark;

$Text = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ</P>';

timethese ( 100_000,
{
    "RegEx" => sub { $Text =~ /^(.*)<\/P>/; $_ = $1 || $Text; },
    "Split" => sub { $_ = (split /^(.*)<\/P>/, $_)[0] },
    "Index" => sub { $_ = substr $Text, 0, index($Text, "</P>"); 
}
}
);

__END__

Benchmark: timing 100000 iterations of Index, RegEx, Split...
     Index:  1 secs ( 1.99 usr  0.00 sys =  1.99 cpu)
     RegEx:  3 secs ( 4.41 usr  0.00 sys =  4.41 cpu)
     Split:  3 secs ( 4.28 usr  0.00 sys =  4.28 cpu)


--Matthew


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

Date: Fri, 18 Sep 1998 23:14:47 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: STDERR redirection X 2 ??
Message-Id: <8ck931f1ym.fsf@gadget.cscaper.com>

>>>>> "Tom" == Tom Turton <tturton@cowboys.anet-dfw.com> writes:

Tom> I'm still struggling with this - basically want to start off with STDERR
Tom> going to the screen normally.  Then at some point in my script, I want
Tom> to redirect it to a file (no problem here), but then I want to switch it
Tom> back to the screen.

Tom> # Start with STDERR going to screen
Tom>     (any warning/error msgs go to screen --- OK)

Tom> # Switch STDERR to a file
Tom>   open (STDERR, ">error.log");
Tom>    (any warning/error msgs go to error.log --- works OK)

Tom> # Now switch back to screen output of STDERR
Tom>   open (STDERR, ">-");
Tom>        (this is how I thought it was supposed to work, but msgs
Tom>         still going to error.log -- HELP?)

Tom> Any and all clues will be greatly appreciated!

Here's one technique with limitations:

    print STDERR "goes to stderr\n";
    {
      local *STDERR;
      open STDERR, '|while read a; do echo "saw: $a"; done';
      print STDERR "goes down that funny pipe\n";
      print STDERR "this does too\n";
    }
    print STDERR "back to original stderr\n";

It doesn't actually rewire file descriptor 2, however, so any child
processes will still use the outer STDERR.

-- 
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@teleport.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: 16 Sep 1998 10:52:06 GMT
From: TOURONLIN@t-online.de (Verhoeven)
Subject: strange DB-problem
Message-Id: <6to58m$ujo$1@news02.btx.dtag.de>

Hiya!

I have a really weird DB-problem here: On our webserver there is an
ODBC-database (dsn=Artikel). When I use an ASP page with PerlScript to read
from that DSN via ADODB.Connection then there is always an error in the
first row of the resultset: The entry for "Beschreibung" is missing.

Here is the Script:

<%@ LANGUAGE = PerlScript %>
<HTML><HEAD> <TITLE>DB-Test</TITLE></HEAD><BODY>

<%
 $Conn = $Server->CreateObject("ADODB.Connection");
 $Conn->Open( "Artikel" );
 $RS = $Conn->Execute( "SELECT * FROM Artikel" );
%>

<P>
<TABLE BORDER=1>
<TR>

<%
 $count = $RS->Fields->Count;
 for ( $i = 0; $i < $count; $i++ ) {
  %><TD><B><%= $RS->Fields($i)->Name %></B></TD><%
 }; %> </TR> <%
 while ( ! $RS->EOF ) {
  %> <TR> <%
  for ( $i = 0; $i < $count; $i++ ) {
   %><TD VALIGN=TOP>
   <%= $RS->Fields($i)->Value %></TD><%
  };
  %> </TR> <%
  $RS->MoveNext;
 };
 $RS->Close;
 $Conn->Close;
%>

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

And the output:

ID, Name, Beschreibung, Preis
1, Mousepad,, 10
2, T-Shirts, T-Shirts in versch. Farben mit individuell wdhlbarem Motiv, 20
3, Kugelschreiber, Kugelschreiber, bedruckbar mit Slogan oder kleinem Logo,
2
4, Kaffeemaschine, Kaffeemschine mit gro_er, individuell bedruckbarer
Werbefldche, 150
5, Mouse, Grosse tolle Maus, 55

Look at the first row: it should read:
1, Mousepad, Mousepad mit individuell wdhlbarem Motiv, 10

The problem is not due to the DSN: I ran a script written in VBScript with
"identical" code which produced the correct output!

The script is:

<HTML>
<TITLE>/learn/test/dbtable.asp</TITLE>
<body bgcolor="#FFFFFF">
<%
' ASP program that displays a database in table form
set conntemp=server.createobject("adodb.connection")
conntemp.open "Artikel"
set rstemp=conntemp.execute("select * from Artikel'")
howmanyfields=rstemp.fields.count -1
%>
<table border=1>
<tr>
<% 'Put Headings On The Table of Field Names
for i=0 to howmanyfields %>
       <td><b><%=rstemp(i).name %></B></TD>
<% next %>
</tr>
<% ' Now lets grab all the records
do  while not rstemp.eof %>
<tr>
<% for i = 0 to howmanyfields%>
       <td valign=top><%=rstemp(i)%></td>
<% next %>
</tr>
<%rstemp.movenext
loop%>
</table>
<%rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing%>
</body></html>

Hope someone can make something out of that!

Thanks,

Timo Verhoeven


P.S.: The Server is a IIS 4 running ActivePerl (5.004x).




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

Date: Fri, 18 Sep 1998 11:20:30 +0200
From: Moshe Zadka <moshez@math.huji.ac.il>
Subject: Table of Contents Generator
Message-Id: <Pine.SUN.3.95-heb-2.07.980918111433.1827A-100000@sunset.ma.huji.ac.il>

Hi all! 

I wrote a small HTML table of contents generator, and I'd be happy
to get some criticism on it.

For an example of it's output, see
http://www.ma.huji.ac.il/~moshez/anafazim/
(Yes, that's something I wrote).

----------- Cut Here ----------------
#!/usr/bin/perl -w
use strict;

my $curr_level=0;
my $head_text;
my $now=localtime;

print <<"EOHTML"
<HTML>
<HEAD>
	<TITLE>Table of Contents</TITLE>
	<META NAME="GENERATOR" 
	      CONTENT="TOC -- Automatic Table of Contents Generator">
</HEAD>
<BODY>
<H1>Table of Contents</H1>
EOHTML
;

while(<>) {
	if(/<H([1-6])>(.*)<\/H\1>/) {
		print "<UL>\n" x ($1-$curr_level), "</UL>\n" x ($curr_level-$1);
		$curr_level=$1;
		($head_text = $2) =~ s/NAME="/HREF="$ARGV#/;
		print "<LI>", $head_text, "\n";
	}
	if(/<TITLE>(.*)<\/TITLE>/) {
		print "</UL>\n" x $curr_level;
		$curr_level=0;
		print '<H2><A HREF="', $ARGV, '">', $1, '</A></H2>', "\n";
	}
}
print "</UL>\n" x $curr_level;
print <<"EOHTML"
<HR>
Created by TOC, The Automatic Table Of Contents Generator<BR>
At $now
</BODY>
</HTML>
EOHTML
;
----------------- Cut Here --------------------------
It assumes a header look like <Hn><A NAME="some_name">Some header</A></Hn>
all on a single line, with n=1,..,6.

The program is in the public domain.
--
Moshe Zadka <moshez@math.huji.ac.il>       |    (\_/)   
What's Yellow and Complete?A Bananach Space|(  =(^Y^)= 
Being smart means being able to count to 20| \_(m___m)
without taking off your shoes - Micky Mouse|(originally by jgs)



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

Date: Fri, 18 Sep 1998 20:09:33 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: trying to use print<<END; with CGI.pm
Message-Id: <MPG.106cc01bb1010fff9896a8@news.south-carolina.net>

In article <6tullp$9of@ssbunews.ih.lucent.com> on 18 Sep 1998 
22:08:57 GMT, Harold Bamford (hbamford@marconi.ih.lucent.com) 
pounded in the following text:
=> >print<<END;
=> >
=> >Al,
=> >  What is it doing?  Just saying that
=> >  it is not working _without_ a code 
=> >  sample doesn't help us troubleshoot
=> >  the problem.
=> >
=> >Brent
=> >
=> >END
=> 
=> Well, it works OK for me.  However, since 'END' has special
=> significance to Perl, you might want to try a different token:
=> 
=> #!perl -w
=> use strict;
=> 
=> print<<"EOF";
=> 
=> Al,
=>   What is it doing?  Just saying that
=>   it is not working _without_ a code
=>   sample doesn't help us troubleshoot
=>   the problem.
=> 
=> Brent
=> 
=> END
   ^^^

s/END/EOF/;

:)

--Matthew


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

Date: 19 Sep 1998 00:33:04 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: where is Date::Parse?
Message-Id: <6tuu40$87s$1@uwm.edu>

    Try  perldoc Date::Manip.
    There isn't a simple Parse function in there, but there are
    ParseDate and ParseRecur and perhaps one or two others.
                       --thelma

nguyen.van@imvi.bls.com wrote:
: I couldn't find Date::Parse. Do you know where it is located?

: Thanks
: Van Nguyen


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

Date: Sat, 19 Sep 1998 00:52:26 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: where is Date::Parse?
Message-Id: <6tuv82$82f@flatland.dimensional.com>

nguyen.van@imvi.bls.com writes:

> I couldn't find Date::Parse. Do you know where it is located?

Look at little closer -- it's part of another module:

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

You could also do a search on the Perl Reference Page:

    http://reference.perl.com/

-- 
Michael Fuhr
http://www.fuhr.net/~mfuhr/


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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