[17872] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 32 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 10 14:25:51 2001

Date: Wed, 10 Jan 2001 11:25:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979154717-v10-i32@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 10 Jan 2001     Volume: 10 Number: 32

Today's topics:
        Newbie needs help <blnukem@hotmail.com>
    Re: Newbie needs help nobull@mail.com
    Re: Newbie needs help <peb@bms.umist.ac.uk>
        Pb with cgi script written in perl <jlbeaudet@pathe.fr.kodak.com>
        Perl code to convert C++ strings to unidode strings? <RyanT@ap.com>
        Please Recommed Encryption Module <grichard@uci.edu>
        Problem install modules <ian.mcgilloway@multimap.com>
    Re: Problem w/ hash of references to hashes (or maybe s <ren.maddox@tivoli.com>
    Re: Problem w/ hash of references to hashes (or maybe s (Weston Cann)
    Re: Problem w/ hash of references to hashes (or maybe s <uri@sysarch.com>
    Re: Problem w/ hash of references to hashes (or maybe s nobull@mail.com
        Problem with inserting data <edd@texscene.com>
        RE: problems perl odbc SQL-Server 7.0: no records with  <claudio.militello@infos.es>
        RegEx question ericr@yankthechain.com
    Re: RegEx question ericr@yankthechain.com
    Re: RegEx question mike_solomon@lineone.net
    Re: RegEx question <uri@sysarch.com>
    Re: RegEx question (Richard Zilavec)
    Re: RegEx question <uri@sysarch.com>
    Re: require (Anno Siegel)
    Re: require (Tad McClellan)
    Re: system() method won't change directories! <uri@sysarch.com>
    Re: Taking control <schneider@xtewa.de>
    Re: Taking control (Tad McClellan)
    Re: Taking control (Anno Siegel)
    Re: Taking control (hymie!)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Jan 2001 16:37:53 GMT
From: "blnukem" <blnukem@hotmail.com>
Subject: Newbie needs help
Message-Id: <Bd076.51781$9C.4667612@news02.optonline.net>

Hi
I need an answer to this question I wrote this script that automatically
produces a web page with a link on it, That all works fine. But when I click
on the link it should produce my second page but all it does is refreshes
the first please help.

Here's the script:

#!/usr/bin/perl

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/\&/, $buffer);
foreach $pair (@pairs) {

        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $FORM{$name} = $value;
}



&page_one;


sub page_one {

print "Content-type: text/html\n\n";
print qq~<html><head>
<title>Test</title>
</head><body>
</form>
<table width="25%">
<tr>
<td width="100%"><ol>
<li><a href="../cgibin/test.pl&page_two">Show page two</a> </li>
</ol>
</td>
</tr>
</table>
</form>
</body>
</html>~;

}


sub page_two {

print "Content-type: text/html\n\n";
print qq~<html><head>
</head>
<body>
<h1>Page Two</h1>
</body>
</html>~;

}


Thanks in advance




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

Date: 10 Jan 2001 17:48:28 +0000
From: nobull@mail.com
Subject: Re: Newbie needs help
Message-Id: <u9lmsjl2mr.fsf@wcl-l.bham.ac.uk>

"blnukem" <blnukem@hotmail.com> writes:

> Subject: Newbie needs help

We read this as "person too lazy read manuals is too lazy to describe
problem in subject line".

Note: "newbie" does not actully mean "person too lazy read manuals"
but in this newsgroup there's a >95% correlation between people who
put "newbie" in the subject line and people too lazy read manuals.

> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

You are attempting to roll your own CGI implmentation that implements
POST-method CGI only.  Since you are using the GET method this is not
going to work.

It is evident you barely know enough about CGI to even use the
stantard implementations - you definitely should not consider rolling
your own.

> I need an answer to this question

Statements like this only serve to antogonise us.

> I wrote this script that automatically
> produces a web page with a link on it, That all works fine. But when I click
> on the link it should produce my second page but all it does is refreshes
> the first

This probably means the link points back to the first page.

> Here's the script:

[snip a lot of code that doesn't anywhere call page_two() ]

> <li><a href="../cgibin/test.pl&page_two">Show page two</a> </li>

I don't think you understand the format of a URL that wants to pass
arguments to a CGI script.  You probably mean something like:

<li><a href="../cgibin/test.pl?page=two">Show page two</a> </li>

This would call the CGI script test.pl with a paramter called 'page'
with the value 'two'.

> sub page_two {

[ snip code to print second page ] 

> }

Nothing in your script calls the subroutine page_two.  You probably
should insert code into your script that calls the subroutine
page_two() if some condition is met by the CGI paramters, for example,
if the parameter 'page' has the value 'two'.

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


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

Date: Wed, 10 Jan 2001 17:14:51 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Newbie needs help
Message-Id: <3A5C988B.DD7B86EC@bms.umist.ac.uk>

blnukem wrote:
> 
> Hi
> I need an answer to this question I wrote this script that automatically
> produces a web page with a link on it, That all works fine. But when I click
> on the link it should produce my second page but all it does is refreshes
> the first please help.
> 
> Here's the script:

<snip>

At no point do you call &page_two

You need to test your input for the key 'page_two' and use this as a
signal to print the second page.

e.g.

if ($pair[0] eq "page_two"){
	page_two();
}else{
	page_one();
}

also you are only supplying a single key without a value to the script
:-

><a href="../cgibin/test.pl&page_two">Show page two</a>

so this line doesn't do anything:-

>@pairs = split(/\&/, $buffer);

and neither does this one :-

>($name, $value) = split(/=/, $pair);


Paul


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

Date: Wed, 10 Jan 2001 19:20:33 +0000
From: Jean-Luc BEAUDET <jlbeaudet@pathe.fr.kodak.com>
Subject: Pb with cgi script written in perl
Message-Id: <3A5CB601.562BCE20@pathe.fr.kodak.com>


Hi every body

Currently:
SOLARIS 7 on SUN Ultra5 station
Apache 1.3.14 installed dynamically (all DSO)
Perl 5.6.0

I want CGI scripts written with perl running under Apache.
Each time i try a real script perl ( "!/usr/local/bin/perl)
I get a big Internal Server Error
And the log file give me lines below:

ld.so.1: /usr/local/bin/perl5: fatal: libgdbm.so: open failed: No such
file or directory
[Thu Jan  4 19:30:22 2001] [error] [client 150.248.8.211] Premature end
of script headers: /home/jlbeaudet/cgi-bin/ListEnv.cgi

My script ListEnv.cgi runs good in a shell (sh/ksh)

The libgdbm.so stays in /usr/local/lib , my LD_LIBRARY_PATH feels OK
and looks like this
LD_LIBRARY_PATH=/usr/lib/sparcv9:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH

Someone help to find out wath's goin' on ???

Best regards.

JLB :O(





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

Date: Wed, 10 Jan 2001 09:16:26 -0800
From: "Ryan Tanner" <RyanT@ap.com>
Subject: Perl code to convert C++ strings to unidode strings?
Message-Id: <t5p67lrvrspia5@corp.supernews.com>

Anybody got some perl code to convert c++ characters and strings to unicode?
The C++ code runs on MS-Windows and was developed using Visual C++.

Thanks!





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

Date: Wed, 10 Jan 2001 09:37:09 -0800
From: "Gabe" <grichard@uci.edu>
Subject: Please Recommed Encryption Module
Message-Id: <93i6sn$5ea$1@news.service.uci.edu>

I want to encrypt credit card data and store it in a MySQL data. Is there a
de facto standard Perl module for this sort of thing?

Thanks!
Gabe




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

Date: Wed, 10 Jan 2001 17:26:40 -0000
From: "ian mcg" <ian.mcgilloway@multimap.com>
Subject: Problem install modules
Message-Id: <3a5c9c13_2@nnrp1.news.uk.psi.net>

Hi,

I'm having trouble installing Digest::MD5 and XML::Parser. I've installed
both modules before on a Linux machine without any trouble, but trying to
install them on a Solaris machine isn't working.

This is an extract of the output from 'make' for Digest::MD5 (the output
from XML::Parser is essentially the same)
---
gcc -c  -I/export/apps/sfio97/include -O     -DVERSION=\"1.01\"  -DXS_VERSIO
N=\"1.01\" -fpic -I/usr/local/lib/perl5/sun4-solaris/5.c
In file included from
/usr/local/lib/perl5/sun4-solaris/5.00404/CORE/perlio.h:27,
                 from
/usr/local/lib/perl5/sun4-solaris/5.00404/CORE/perl.h:181,
                 from MD2.xs:36:
/usr/local/lib/perl5/sun4-solaris/5.00404/CORE/perlsfio.h:3: sfio.h: No such
file or directory
*** Error code 1
make: Fatal error: Command failed for target `MD2.o'
Current working directory /PATH/.cpan/build/Digest-MD5-2.12/MD2
*** Error code 1
make: Fatal error: Command failed for target `subdirs'
  /usr/ccs/bin/make  -- NOT OK
---
All the prerequisites for the modules have been installed.

I can't figure out why this shouldn't work.

Thanks,
Ian




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

Date: 10 Jan 2001 09:26:49 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Problem w/ hash of references to hashes (or maybe scoping?)
Message-Id: <m33dere8cm.fsf@dhcp11-177.support.tivoli.com>

iowa_song88.remove_eights_and_this@hotmail.com (Weston Cann) writes:

> The only two things I can think of are that 1) I'm doing the
> referencing/dereferencing wrong or 2) I have a scoping problem
> so that the data I think I'm referencing is actually getting 
> scrapped before I look at it.

A third possibility is that something is wrong with your data.  In
particular, the functionality of this code seems fine, and if I
initialize %fileHash with known values, and then test with those
values, it works fine.

So, I do not think your problem is in this code.  That being said, I
am going to make a few comments about the code.

> #!/usr/bin/perl

You really need to enable warnings and use strict.  Possibly you
already are and just didn't include them in this post -- if so, don't
do that, always include them in the post.

> $filename = $ARGV[0];
> $label    = $ARGV[1];
> 
> print "\nfetchKey: |$filename| |$label|\n\n";
> $str = &fetchKeyFromFile($filename,$label);

Unnecessary use of & to call a function is stylistically frowned upon.

> print "\nFetched Key: \n",$str,"End Fetched Key\n\n";
> exit;
> 
> %fileHash;

Not sure why you have this here... but if it had a "my" on it then it
would make a bit more sense.

> sub fetchKeyFromFile
> {
>         my($filename,$label) = @_;

[omitted some code]

>                         if($line =~ m/^###@\s*(.*?)$/)

Minor point, but using a non-greedy quantifier and then forcing it to
match the rest of the string (by anchoring the pattern to the end of
the string) is silly, and possibly less efficient than just using a
regular greedy quantifier.

[omitted some more]

>         return $fileHash{$filename}->{$label};

As I said, this syntax is fine, but the intervening arrow is
unnecessary.  You can just use:

          return $fileHash{$filename}{$label};

HTH,

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 10 Jan 2001 16:48:40 GMT
From: iowa88_song88.remove_eights@hotmail.com (Weston Cann)
Subject: Re: Problem w/ hash of references to hashes (or maybe scoping?)
Message-Id: <iowa88_song88.remove_eights-1001010956040001@172.salt-lake-city-05-10rs.ut.dial-access.att.net>

In article <m33dere8cm.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox
<ren.maddox@tivoli.com> wrote:

> In particular, the functionality of this code seems fine, and if I
> initialize %fileHash with known values, and then test with those
> values, it works fine.

It works this morning. :| I don't recall changing anything, even 
test data (although I was a bit fried when I stopped coding 
yesterday, so anything is possible), so I'm a bit wary. But this 
may be the best argument yet for taking breaks when you get stuck.

I do have a couple of questions about your commentary on my code,
though. 


> > print "\nfetchKey: |$filename| |$label|\n\n";
> > $str = &fetchKeyFromFile($filename,$label);
> 
> Unnecessary use of & to call a function is stylistically frowned upon.

Hmmmm. This was the syntax I recall from the pink (Perl 4, I think)
camel book. Is it deprecated? Or are there times to use it and times not
to use it?

> >                         if($line =~ m/^###@\s*(.*?)$/)
> 
> Minor point, but using a non-greedy quantifier and then forcing it to
> match the rest of the string (by anchoring the pattern to the end of
> the string) is silly, and possibly less efficient than just using a
> regular greedy quantifier.

Truly. Another sign I needed a break. Don't know exactly what I was thinking.


> 
> >         return $fileHash{$filename}->{$label};
> 
> As I said, this syntax is fine, but the intervening arrow is
> unnecessary.  You can just use:
> 
>           return $fileHash{$filename}{$label};

Ahh. I don't understand this. If $fileHash{$filename} contains a reference
to a hash, don't I have to dereference before I refer to a key in the hash?

Or is this one of those cases where Perl is syntactically smart, and rather
than hold you to a strict syntax, just recognizes this as an idiom for the
same thing?

Weston

=================================================================
"The best laid plans of mice and men are about equal."
iowa_so8ng@hot8mail.com 
Address is spam repelant. Remove eights to reach me.


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

Date: Wed, 10 Jan 2001 17:32:03 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Problem w/ hash of references to hashes (or maybe scoping?)
Message-Id: <x74rz75n58.fsf@home.sysarch.com>

>>>>> "WC" == Weston Cann <iowa88_song88.remove_eights@hotmail.com> writes:

  >> Unnecessary use of & to call a function is stylistically frowned upon.

  WC> Hmmmm. This was the syntax I recall from the pink (Perl 4, I
  WC> think) camel book. Is it deprecated? Or are there times to use it
  WC> and times not to use it?

you are using the pink camel? burn it or put it in a museum. always use
the online docs for a reference anyway. read perlsub and learn about &,
why it is not needed in basic sub calling and why is still is around
(for a few special cases).

uri

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


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

Date: 10 Jan 2001 18:04:55 +0000
From: nobull@mail.com
Subject: Re: Problem w/ hash of references to hashes (or maybe scoping?)
Message-Id: <u9hf37l1vc.fsf@wcl-l.bham.ac.uk>

iowa88_song88.remove_eights@hotmail.com (Weston Cann) writes:

> In article <m33dere8cm.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox
> <ren.maddox@tivoli.com> wrote:

> > Unnecessary use of & to call a function is stylistically frowned upon.
> 
> Hmmmm. This was the syntax I recall from the pink (Perl 4, I think)
> camel book. Is it deprecated? Or are there times to use it and times not
> to use it?

Both.  In normal usage it is deprecated.  However it does actaully
have a use and that is to say "disregard prototype".

> > >         return $fileHash{$filename}->{$label};
> > 
> > As I said, this syntax is fine, but the intervening arrow is
> > unnecessary.  You can just use:
> > 
> >           return $fileHash{$filename}{$label};
> 
> Ahh. I don't understand this. If $fileHash{$filename} contains a reference
> to a hash, don't I have to dereference before I refer to a key in the hash?
> 
> Or is this one of those cases where Perl is syntactically smart, and rather
> than hold you to a strict syntax, just recognizes this as an idiom for the
> same thing?

Yep it's one of those cases.

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


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

Date: Fri, 5 Jan 2001 19:44:33 -0000
From: "Edd" <edd@texscene.com>
Subject: Problem with inserting data
Message-Id: <3a5621e0@news-uk.onetel.net.uk>

I am using the below section of a code to insert data into an MySQL table. I
copied this from DBI documentation available at www.perldoc.com/DBI

------------CODE----------------------

Shebank line, use DBI;, use strict etc...
 ...
 ...
my $coname = "tex";
my $address = "tex";
my $second = "30 Tosson terrace";
my $town = "EW";my $country = "UK";
my $code = "GHG";
my $title = "Mr.";


my $sth = $dbh->prepare("INSERT INTO
f1(coname,address,second,town,country,code,title) VALUES (?,?,?,?,?,?,?)");
while(<>) {
chop;
($coname,$address,$second,$town,$country,$code,$title) = split/,/;
$sth->execute($coname,$address,$second,$town,$country,$code,$title);
}

 ... CODE continues....




When the code runs, it gets into a loop and enters alot of 'NULL's into the
fields concerned.
I don't quite understand 'while (<>)' what does that do. Another version
from perldoc is
'while (<CVS>). What on earth is CVS. There is no explanation about it
whatsoever. Can somebody enlighten me about this.

What is the easiest way of enetering data froma cgi-code into a remote
server MySQL database.

Cheers.






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

Date: Wed, 10 Jan 2001 16:25:17 +0100
From: "claudio militello" <claudio.militello@infos.es>
Subject: RE: problems perl odbc SQL-Server 7.0: no records with tinyint
Message-Id: <93huun$ipb$1@lola.ctv.es>


Jeff Helman <jhelman@wsb.com> escribió en el mensaje de noticias
4doo5tgbc0l1q64i0iei4j57hntmamlhsq@4ax.com...
> On Wed, 10 Jan 2001 14:06:37 +0100, "claudio militello"
> <claudio.militello@infos.es> wrote:
>
>
> >$SGC = new Win32::ODBC($DSN);
> >if ($SGC) {
> > print "Conexion SGC OK.\n";
> >} else {
> > print " ERROR Abertura conexion: $DSN\n";
> > exit;
> >}
> >$sql =  "SELECT TE_ID from TELEFONOS";
> >$SGC->Sql($sql);
>
> You check to make sure that your server connection opened, but you
> don't check to see if your query executed?
>
> if ($SGC->Sql($sql)) {
>     my $error = $SGC->Error();
>     print "Error executing query: $error\n";
> } else {
>     ## PARSE YOUR DATA HERE
> }
>
> Change both of your queries to this format and see if your second
> query is returning an error.
>
> JH

I changed the code to check for error: no error returns from the Sql call

>




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

Date: Wed, 10 Jan 2001 16:26:21 GMT
From: ericr@yankthechain.com
Subject: RegEx question
Message-Id: <93i2eu$vvc$1@nnrp1.deja.com>

How would I make a RegExp to eliminate all space on either side of
letters in a string, but preserve any spaces within (ie turn "  Blah
blah  " into "Blah blah")?


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 16:43:32 GMT
From: ericr@yankthechain.com
Subject: Re: RegEx question
Message-Id: <93i3fi$128$1@nnrp1.deja.com>

Works great, thanks!

In article <93i393$ut$1@nnrp1.deja.com>,
  mike_solomon@lineone.net wrote:
> In article <93i2eu$vvc$1@nnrp1.deja.com>,
>   ericr@yankthechain.com wrote:
> > How would I make a RegExp to eliminate all space on either side of
> > letters in a string, but preserve any spaces within (ie turn "  Blah
> > blah  " into "Blah blah")?
> >
> > Sent via Deja.com
> > http://www.deja.com/
> >
> Eric
>
> This will do it
>
> $output = "   Blah blah   ";
> $output =~ s/^\s*|\s*$//g;
>
> Regards
>
> Mike Solomon
>
> Sent via Deja.com
> http://www.deja.com/
>


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 16:40:05 GMT
From: mike_solomon@lineone.net
Subject: Re: RegEx question
Message-Id: <93i393$ut$1@nnrp1.deja.com>

In article <93i2eu$vvc$1@nnrp1.deja.com>,
  ericr@yankthechain.com wrote:
> How would I make a RegExp to eliminate all space on either side of
> letters in a string, but preserve any spaces within (ie turn "  Blah
> blah  " into "Blah blah")?
>
> Sent via Deja.com
> http://www.deja.com/
>
Eric

This will do it

$output = "   Blah blah   ";
$output =~ s/^\s*|\s*$//g;

Regards

Mike Solomon




Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 17:33:51 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: RegEx question
Message-Id: <x71yub5n28.fsf@home.sysarch.com>

>>>>> "ms" == mike solomon <mike_solomon@lineone.net> writes:

  ms> In article <93i2eu$vvc$1@nnrp1.deja.com>,
  ms>   ericr@yankthechain.com wrote:
  >> How would I make a RegExp to eliminate all space on either side of
  >> letters in a string, but preserve any spaces within (ie turn "  Blah
  >> blah  " into "Blah blah")?
  >> 
  >> Sent via Deja.com
  >> http://www.deja.com/
  >> 

  ms> $output = "   Blah blah   ";
  ms> $output =~ s/^\s*|\s*$//g;

as always, the FAQ answer is better and faster. please don't answer
these with your own versions, use the FAQ.

in the above case you should use + instead of *. why always substitute a
null string with a null string? second, it is faster to do it in 2
regexes as the FAQ shows.

uri

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


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

Date: Wed, 10 Jan 2001 17:29:45 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: RegEx question
Message-Id: <3a5d9a91.183355956@news.tcn.net>

On Wed, 10 Jan 2001 16:40:05 GMT, mike_solomon@lineone.net wrote:

>
>This will do it
>
>$output = "   Blah blah   ";
>$output =~ s/^\s*|\s*$//g;

I stuck the above in a loop, and used time to get a ball park on how
fast \s* compared to \s+:

$output =~ s/^\s*|\s*$//g; # 25.52

$output =~ s/^\s+|\s+$//g; # 14.75

$output =~ s/^\s+(.+?)\s+$/$1/; # 8.56


--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Wed, 10 Jan 2001 18:40:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: RegEx question
Message-Id: <x7wvc345ec.fsf@home.sysarch.com>

>>>>> "RZ" == Richard Zilavec <rzilavec@tcn.net> writes:

  RZ> On Wed, 10 Jan 2001 16:40:05 GMT, mike_solomon@lineone.net wrote:

  >> 
  >> This will do it
  >> 
  >> $output = "   Blah blah   ";
  >> $output =~ s/^\s*|\s*$//g;

  RZ> I stuck the above in a loop, and used time to get a ball park on how
  RZ> fast \s* compared to \s+:

ever heard of Benchmark.pm?

  RZ> $output =~ s/^\s*|\s*$//g; # 25.52

  RZ> $output =~ s/^\s+|\s+$//g; # 14.75

  RZ> $output =~ s/^\s+(.+?)\s+$/$1/; # 8.56

try that last one on 'zzz  zzz  '. it fails. there, you need * instead
of +.

also you don't show resetting the data or anything else. your results
are therefore suspect.

use Benchmark;
$line = '   Foo  Bar  ' ;

timethese +( shift || -5 ), { 
	'null' => q{ my $trimmed = $line },
	'star' => q{ my $trimmed = $line ; $trimmed =~ s/^\s*|\s*$//g  },
	'plus' => q{ my $trimmed = $line ; $trimmed =~ s/^\s+|\s+$//g  },
	'grab' => q{ my $trimmed = $line ; $trimmed =~ s/^\s*(.+?)\s*$/$1/ },
	'FAQ' => q{ my $trimmed = $line ; $trimmed =~ s/^\s+// ;
					  $trimmed =~ s/\s+$// },
	'FAQ2' => q{ my $trimmed = $line ; s/^\s+//, s/\s+$// for $trimmed },
} ;

Benchmark: running FAQ, FAQ2, grab, null, plus, star, each for at least 5 CPU seconds...
      null:  6 wallclock secs ( 5.25 usr +  0.00 sys =  5.25 CPU) @ 367148.19/s (n=1927528)
       FAQ:  5 wallclock secs ( 5.01 usr +  0.00 sys =  5.01 CPU) @ 71070.06/s (n=356061)
      plus:  4 wallclock secs ( 5.02 usr +  0.00 sys =  5.02 CPU) @ 46900.80/s (n=235442)
      FAQ2:  4 wallclock secs ( 5.04 usr +  0.01 sys =  5.05 CPU) @ 39564.95/s (n=199803)
      star:  6 wallclock secs ( 5.00 usr +  0.00 sys =  5.00 CPU) @ 39532.40/s (n=197662)
      grab:  5 wallclock secs ( 5.01 usr +  0.00 sys =  5.01 CPU) @ 30963.27/s (n=155126)


so the FAQ is the fastest as it should be. so why don't you refer to it?
and your (fixed) grab is the slowest.

uri

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


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

Date: 10 Jan 2001 14:32:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: require
Message-Id: <93hrqp$rgr$1@mamenchi.zrz.TU-Berlin.DE>

Enrico Ng <ng@fnmail.com> wrote in comp.lang.perl.misc:
>I have a bunch of subroutines that I have organized in different files.
>I use require in the main program to call a subroutine in a different file.
>this works fine, but when that subroutine calls a subroutine thats in
>another file, I get errors
>"Malformed prototype"
>
>Any Ideas?

Since you didn't include any code (neither here not in an earlier
version of your post) it's hard to have any.

A prototype is something enclosed in parentheses '()' between
the name of a sub and the opening "{" of the sub block.  Apparently
you have put something in this position that doesn't belong there.
See perldoc perlsub for what prototypes are and what you can legally
put there.  Then look though your source for /\)\s*{/ and correct
what you find.

Anno


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

Date: Wed, 10 Jan 2001 07:36:36 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: require
Message-Id: <slrn95olqk.4h7.tadmc@tadmc26.august.net>

Enrico Ng <ng@fnmail.com> wrote:

>I use require in the main program to call a subroutine in a different file.
                                      ^^^^


No you don't (or you probably "shouldn't").

You use require in the main program to _define_ a subroutine in a 
different file.

"Defining a subroutine" and "calling a subroutine" are very
different things, best to not confuse them.


>this works fine, but when that subroutine calls a subroutine thats in
>another file, I get errors
>"Malformed prototype"
>
>Any Ideas?


Look up the message in the standard docs:

   perldoc perldiag

or, ask perl to look it up for you by putting this near the top
of the file:

   use diagnostics;


Also, of course, examine the prototypes of your subroutines :-)

If you do not know what a subroutine prototype is, then find out:

   perldoc perlsub


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 10 Jan 2001 16:25:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: system() method won't change directories!
Message-Id: <x77l435q8n.fsf@home.sysarch.com>

>>>>> "RH" == Reto Hersiczky <fight_against_spam_cut_here_retoh@dplanet.ch> writes:

  RH> Each system() call creates its own environment.
  RH> The cheapiest way to get your wanted effect
  RH> is to code something like this:

  RH> system("cd YOUR_PATH; ./YOUR_SCRIPT) && die $!;

  RH> This will work.

ugly as sin too. if that is what you really want, do this:

	chdir $path ;
	exec $script ;
	die "can't exec $script $!" ;

uri

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


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

Date: Wed, 10 Jan 2001 14:25:36 GMT
From: SimBean <schneider@xtewa.de>
Subject: Re: Taking control
Message-Id: <93hrcl$orh$1@nnrp1.deja.com>


> [lots of crap]
Can't you see he's bullshitting you?

What's the point in answering postings like that???

--
Ciao,
SimBean.


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 07:56:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Taking control
Message-Id: <slrn95on0p.4h7.tadmc@tadmc26.august.net>

Wyzelli <wyzelli@yahoo.com> wrote:

>How come programmers who get paid big bucks only ever want to give their
>'2 cents' to a discussion?


Because we are greedy by default.


If, OTOH, someone asks a $64,000 question, they can get it
answered by using non-greedy programmers instead.

This, as are most questions relating to Perl (even related
in "Seven Steps Removed From Kevin Bacon" fashion), is
addressed in the standard Perl docs:


   perldoc perlie

------------------------
NAME
       perlie - Perl irregular expressions
 ...
------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 10 Jan 2001 15:15:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Taking control
Message-Id: <93huaa$36t$1@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:

>   perldoc perlie
>
>------------------------
>NAME
>       perlie - Perl irregular expressions
>...

And for a horrible moment I thought "ie" meant....  Never mind.

Anno


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

Date: Wed, 10 Jan 2001 15:15:18 -0000
From: hymie@lactose.smart.net (hymie!)
Subject: Re: Taking control
Message-Id: <t5ov464nns7t02@corp.supernews.com>

In our last episode, the evil Dr. Lacto had captured our hero,
  "Wyzelli" <wyzelli@yahoo.com>, who said:

>How come programmers who get paid big bucks only ever want to give their
>'2 cents' to a discussion?

This is how I plan to get rich:

I offer you a penny for your thoughts, and you give me your two cents' worth.
I just made a penny.

Now, my company has 200 employees, so I could make $2 a day just at
work.  Then I start talking to my friends and family...

hymie!          http://www.smart.net/~hymowitz          hymie@lactose.smart.net
===============================================================================


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 32
*************************************


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