[17536] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4956 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 23 14:05:43 2000

Date: Thu, 23 Nov 2000 11:05:12 -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: <975006312-v9-i4956@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 23 Nov 2000     Volume: 9 Number: 4956

Today's topics:
        ANNOUNCE: HTTP::GHTTP <matt@sergeant.org>
    Re: Any good perl tutorial online? <bart.lateur@skynet.be>
    Re: Any good perl tutorial online? <kip@skiltrip.com>
    Re: CGI.pm upload problems mikhailgee@my-deja.com
    Re: CGI.pm upload problems nobull@mail.com
    Re: CGI.pm upload problems nobull@mail.com
    Re: CGI.pm upload problems nobull@mail.com
    Re: Coloured text in Win32 CMD window <bowman@montana.com>
    Re: Coloured text in Win32 CMD window <nebur@biz-direct.net>
    Re: Coloured text in Win32 CMD window <nebur@biz-direct.net>
        create user <livia74@ctimail3.com>
        getting the line number of the scriptfile (Eric Smith)
    Re: getting the line number of the scriptfile (Tad McClellan)
    Re: I'm confused <replynews@bigfoot.com>
        IO::Socket: bind or listen errors <unformat@my-deja.com>
    Re: IO::Socket: bind or listen errors (Garry Williams)
        Need a fast $150???  Write (or find) me a couple of scr (Al Rosetti)
    Re: newbie question <dvbryan@_nospamplsHotmail.com>
        perl options (Flint Slacker)
    Re: permissions issue...i think <bart.lateur@skynet.be>
    Re: Simple Question :) (Tad McClellan)
    Re: Simple Question :) <geoff-at-farmline-dot-com@127.0.0.1>
    Re: Simple Question :) (Tad McClellan)
    Re: Simple Question :) <uri@sysarch.com>
    Re: Sort runtime 5.005 vs 5.004 (Garry Williams)
    Re: Sort runtime 5.005 vs 5.004 (Garry Williams)
        splitting a string into an array and preserving the "\n (Eric Smith)
    Re: splitting a string into an array and preserving the (Eric Smith)
    Re: splitting a string into an array and preserving the (Rafael Garcia-Suarez)
    Re: splitting a string into an array and preserving the (Tad McClellan)
    Re: splitting a word (Tad McClellan)
    Re: splitting a word <sumus@aut.dk>
    Re: splitting a word <ra@amk.lg.ua>
        Stripping Comma's and Spaces <dvbryan@_nospamplsHotmail.com>
    Re: Stripping Comma's and Spaces (Garry Williams)
    Re: Stripping Comma's and Spaces (Tad McClellan)
    Re: Stripping Comma's and Spaces <brannon@lnc.usc.edu>
    Re: Stripping Comma's and Spaces <jeffp@crusoe.net>
    Re: Stripping Comma's and Spaces nobull@mail.com
    Re: Subroutine Stuff??? nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Nov 2000 10:02:49 +0000
From: Matt Sergeant <matt@sergeant.org>
Subject: ANNOUNCE: HTTP::GHTTP
Message-Id: <t1qk5eqb4jla1c@corp.supernews.com>

HTTP::GHTTP is a lightweight HTTP client library based on the Gnome
project's libghttp library. It is very useful in situations where
loading either LWP::Simple or HTTP::Lite is too much code (such as
mod_perl). It is also significantly faster than both those modules in
my rudimentary tests.

Example usage:

   use HTTP::GHTTP 'get';
   print get("http://axkit.org/");

or using the OO model:

   use HTTP::GHTTP;
   my $r = HTTP::GHTTP->new();
   $r->set_uri("http://axkit.org/");
   $r->set_header(Connection => "close");
   $r->process_request();
   print $r->get_body();

HTTP::GHTTP also supports an asynchronous method of operation, which
is covered in the documentation.

Note: There is a bug that causes corruption of the downloaded content
in version 1.00 of the library, so please try and get at least version
1.01 (with no async support) or 1.02 (with async support).

Matt Sergeant.




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

Date: Thu, 23 Nov 2000 14:42:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Any good perl tutorial online?
Message-Id: <a6bq1tc7nsntu3bh5krkgdpir3nfghja3r@4ax.com>

Paul wrote:

>Any good perl tutorial online?

	<http://www.cs.cf.ac.uk/Dave/PERL/>

This merges intro's to Perl, HTML and CGI.

-- 
	Bart.


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

Date: Thu, 23 Nov 2000 11:37:13 -0500
From: "Kip" <kip@skiltrip.com>
Subject: Re: Any good perl tutorial online?
Message-Id: <8vjh6b$m16$1@news.warwick.net>

www.perl.com has a "Beginner's introduction to Perl" series going on.  Right
now they are on Part Three.  Part One is located at
http://www.perl.com/pub/2000/10/begperl1.html.  There are links to all three
parts there.  Other than that, there is tons of docs all over the net.
www.perl.org and perl.com are both excellent sources of info.




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

Date: Thu, 23 Nov 2000 17:15:54 GMT
From: mikhailgee@my-deja.com
Subject: Re: CGI.pm upload problems
Message-Id: <8vjjc7$kpq$1@nnrp1.deja.com>

It worked OK if I don't use the CGI.pm module. And if I have two single
quotes, one of them will be unchanged while the other will be changed
to ::. Also, not sure where to check for whether the single quote is
allowed.

Thanks,
Mikhail

> It could be getting hosed in the http encoding. Check to see if the
> single quote is allowed.
>
> Andy
>
> On Thu, 23 Nov 2000 06:37:24 GMT, mikhailgee@my-deja.com wrote:
>
> >I was wondering if anyone knows why my upload script using CGI.pm is
> >changing the uploaded filename whenever there are single quotes in
the
> >filename. For instance a filename like "Billie's Song.mp3" is coming
up
> >as "Billie::s Song.mp3".
> >
> >Thanks,
> >M G
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Before you buy.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 23 Nov 2000 18:32:44 +0000
From: nobull@mail.com
Subject: Re: CGI.pm upload problems
Message-Id: <u97l5usfn7.fsf@wcl-l.bham.ac.uk>

mikhailgee@my-deja.com writes:

> I was wondering if anyone knows why my upload script using CGI.pm is
> changing the uploaded filename whenever there are single quotes in the
> filename. For instance a filename like "Billie's Song.mp3" is coming up
> as "Billie::s Song.mp3".

The return value from  CGI::param() for an upload field is both a
string and at the same time a filehandle.

In older versions of CGI.pm this is achieved using symbolic references
(ugh!).

In more recent versions of CGI.pm this is achieved using hard
references and overloading.  (Still "ugh!", but less so).

In older versions of Perl ' was used in place of :: so if you put ' in
a symbolic reference and then look at the name of the resulting symbol
you'll find that it has been converted to ::.

# Print the name of the symbol who's name is "Billie's Song.mp3";
print *{"Billie's Song.mp3"}; 

I don't have an old version of CGI.pm to hand in order to explain in
any greater detail the exact mechanism of this bug.

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


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

Date: 23 Nov 2000 18:38:31 +0000
From: nobull@mail.com
Subject: Re: CGI.pm upload problems
Message-Id: <u966lesfdk.fsf@wcl-l.bham.ac.uk>

mikhailgee@my-deja.com writes upside-down:

> > >I was wondering if anyone knows why my upload script using CGI.pm is
> > >changing the uploaded filename whenever there are single quotes in
> the
> > >filename. For instance a filename like "Billie's Song.mp3" is coming
> up
> > >as "Billie::s Song.mp3".

> It worked OK if I don't use the CGI.pm module.

Just curious, if you didn't use CGI.pm for upload just what did you use?

[ Oh and in future please quote _relevant_ material _in_ context ]

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


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

Date: 23 Nov 2000 18:41:00 +0000
From: nobull@mail.com
Subject: Re: CGI.pm upload problems
Message-Id: <u94s0ysf9f.fsf@wcl-l.bham.ac.uk>

asmith@hsonline.net (Andy Smith) writes upside down without trimming
the post he's following up.  This behaviour is highly correlated with
inacurate advice.

> It could be getting hosed in the http encoding. Check to see if the
> single quote is allowed.

Yep, the correlation holds.

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


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

Date: Thu, 23 Nov 2000 09:27:10 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: Coloured text in Win32 CMD window
Message-Id: <qubT5.560$iv2.1977@newsfeed.slurp.net>


James <jamesmckay@MailAndNews.com> wrote in message
news:3A27AA14@MailAndNews.com...

> Does anyone know of a way of outputing coloured text to a Dos window
> on  WinNT via ActivePerl?

You might try Term::ANSIColor. It doesn't come with ActiveState, but you can
get it with ppm.
This is just a wrapper on the ANSI escape sequences so you could use them in
your
print strings just as easily. This assumes the Dos window mimics ANSI.





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

Date: Thu, 23 Nov 2000 18:05:56 +0100
From: "nebur" <nebur@biz-direct.net>
Subject: Re: Coloured text in Win32 CMD window
Message-Id: <3a1d4fc5_1@excalibur.gbmtech.net>

You can start by using Term::Ansicolor, don't have an example but it seems
to be the module for you,

nebur

"James" <jamesmckay@MailAndNews.com> wrote in message
news:3A27AA14@MailAndNews.com...
> Hi all,
>       Does anyone know of a way of outputing coloured text to a Dos window
> on
> WinNT via ActivePerl?
> Thanks in advance
> James
>




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

Date: Thu, 23 Nov 2000 18:05:56 +0100
From: "nebur" <nebur@biz-direct.net>
Subject: Re: Coloured text in Win32 CMD window
Message-Id: <3a1d544a_1@excalibur.gbmtech.net>

You can start by using Term::Ansicolor, don't have an example but it seems
to be the module for you,

nebur

"James" <jamesmckay@MailAndNews.com> wrote in message
news:3A27AA14@MailAndNews.com...
> Hi all,
>       Does anyone know of a way of outputing coloured text to a Dos window
> on
> WinNT via ActivePerl?
> Thanks in advance
> James
>




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

Date: Thu, 23 Nov 2000 22:45:21 +0800
From: TomC <livia74@ctimail3.com>
Subject: create user
Message-Id: <3A1D2D81.D3298C05@ctimail3.com>

Hi, can you one teach me to use NetAdmin.pm to add user in NT server?
Any web site talk about it?



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

Date: 23 Nov 2000 15:23:25 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: getting the line number of the scriptfile
Message-Id: <slrn91qdjd.vl.eric@plum.fruitcom.com>

I am writing a logging routine and want to report the line number of the
current line in the script - the line that is producing the outpput to the
log.

How is this possible?


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

Date: Thu, 23 Nov 2000 10:24:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: getting the line number of the scriptfile
Message-Id: <slrn91qdkk.suv.tadmc@magna.metronet.com>

Eric Smith <eric@fruitcom.com> wrote:
>I am writing a logging routine and want to report the line number of the
>current line in the script - the line that is producing the outpput to the
>log.
>
>How is this possible?


See the __LINE__ literal in the "Scalar value constructors" section:

   perldoc perldata


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


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

Date: Thu, 23 Nov 2000 18:09:14 +0100
From: "Ralf Siedow" <replynews@bigfoot.com>
Subject: Re: I'm confused
Message-Id: <8vjivm$4qajt$1@ID-23826.news.dfncis.de>

Thanxs for opening my eyes and giving me self-confidence back ;-)


"Ralf Siedow" <replynews@bigfoot.com> wrote in message
news:8vhenk$4bj4p$1@ID-23826.news.dfncis.de...
> Hello,
>
> I'm just mangling the following trainig course at
> http://www.bjnet.edu.cn/tech/book/perl/ch18.htm
>
> They have an exercise at the end of the chapter that confuses me a little
> bit:
> Why is $b not being set in the following line of code? What do you have to
> do to make it okay?
> sub xxx {
> my ($a, $b) = @_;
> }
>
> Answer:
> Make the line
> my($a,$b)
> look like this:
> my (\$a,\$b)
> Then use @$a and @$b to access these arrays by reference.
>
>
> I just wrote an example according to the excercise and it works perfectly:
> #!/usr/bin/perl
>
> use strict;
>
> my @test = ('1', '2', '3');
>
> &test(@test);
>
> sub test
> {
>         my ($a, $b) = @_;
>         print "a=$a;b=$b";
> }
>
>
> cu Ralf
>
>




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

Date: Thu, 23 Nov 2000 17:42:01 GMT
From: unformat <unformat@my-deja.com>
Subject: IO::Socket: bind or listen errors
Message-Id: <8vjkt9$lkq$1@nnrp1.deja.com>

When using IO::Socket and creating a socket object with ->new, I can
give args to make it listen on a port. I cannot, however, establish an
error condition following failure to bind to port using the ->error
method. How can I find out if the bind or listen failed within ->new() ?

Regards,

UnFormat.
--
unformat@my-deja.com
http://www.bmeworld.com/unformat/  -- tattooed all over!
"Enough love to knock a rhino sideways" - SNUFF


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 23 Nov 2000 19:03:47 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: IO::Socket: bind or listen errors
Message-Id: <nSdT5.1431$xb1.91724@eagle.america.net>

On Thu, 23 Nov 2000 17:42:01 GMT, unformat <unformat@my-deja.com> wrote:
>When using IO::Socket and creating a socket object with ->new, I can
>give args to make it listen on a port. I cannot, however, establish an
>error condition following failure to bind to port using the ->error
>method. How can I find out if the bind or listen failed within ->new() ?

Why not check $!?  

-- 
Garry Williams


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

Date: Thu, 23 Nov 2000 17:44:22 GMT
From: al@maystreet.com (Al Rosetti)
Subject: Need a fast $150???  Write (or find) me a couple of scripts and make em' work!
Message-Id: <3a1d603b.1195670@news>

So who wants to be a hundredaire? <g>  If you'd like some extra
holiday cash for just a few hours of your time (or even less if these
scripts are already lying around somewhere and you can implement them)
I need your help.

 I need two simple scripts for my website.

An invisible counter to be used on multiple pages
A) The results need to be invisible on trigger pages where they're
used.
B) The results for all the counters need to be shown in one
document... counters.htm   Hitting counters.htm can't increment the
counters.  In other words some sort of noincrement feature.
C) I need to be able to use this counter dozens of times and I need
access to the doc or txt file that it writes to so that I can reset
these from time to time.
non-working example
www.maystreet.com/counters.htm

The second thing I need is a pseudo search tool.  I need a plain HTML
text box and a triggering button.  The user will type in  a
"keyword"... hit enter (or the html trigger button) and this will take
him/her to a page linked to that keyword.

On a practical level the information needs to be stored in a doc/txt
file online that I can easily edit. 

How it oughta work...
A) A user will type in Toyota111
B) The script will search the mini database (txt file)
C) In the text file toyota111 will be associated with the document
"toyota111/index.htm"
D) The browser will be forwarded to that page.
E) If the user enters a keyword with no matchup the browser is
automatically forwarded to "error.htm" or whatever.

Thanks a ton in advance,

Al Rosetti
al@maystreet.com
www.maystreet.com







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

Date: Thu, 23 Nov 2000 15:47:33 -0000
From: "D.B" <dvbryan@_nospamplsHotmail.com>
Subject: Re: newbie question
Message-Id: <qXaT5.5072$ws2.736597@news3.cableinet.net>

Try looking at:
http://www.cgi-resources.com/

DB
"Mark" <m.r.davies@virgin.net> wrote in message
news:Ih7T5.7037$17.107625@stones...
> Hi
>
> I'm after a free form2mail script for a unix server that has about 17
boxes
> for submital (all at the same time)
> it's basically a quotation form but loads of varibles depend the cost of
the
> quote,
>
> all the ones i've found are 3 boxes , name , address, and comments
> a dropdown box would be handy as well but not neccessary,
>
> am i asking too much or are there any ones like this?
>
> Mark
>
>




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

Date: Thu, 23 Nov 2000 19:02:10 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: perl options
Message-Id: <3a1d67da.75077620@news.tcn.net>


I just went through the perl man page and found options like -w to
print warnings etc.... but I don't believe the list is complete.  I
remember seeing a --*-***- string in a cgi script one time.  I'm just
wondering if you can improve performance by turning off certain things
like syntax checking, etc.....  Does anybody have a complete list?

Flint


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

Date: Thu, 23 Nov 2000 14:34:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: permissions issue...i think
Message-Id: <6laq1t4sdk7nj2tu82gu7lkipvnhng3u9t@4ax.com>

akothek@my-deja.com wrote:

>i have written a perl program that is basically a wrapper around a
>bunch of perl and shell scripts. runs fine when i or other users cd to
>the dir and run it. but cant run the program from other dirs...it does
>not find the inner scripts...

You can always do a chdir at the top of your script. Finding out where
to chdir to, that may be another matter.

	$0 =~ m!(.*)/! and chdir $1;

Something like that.

If you happen to rely on where the script is called from, that won't
ever work.

-- 
	Bart.


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

Date: Thu, 23 Nov 2000 10:04:33 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Simple Question :)
Message-Id: <slrn91qcg0.skn.tadmc@magna.metronet.com>

Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:
>"Peter Sundstrom" <peter.sundstrom@eds.com> wrote in message
>news:8vheqp$3jh$1@hermes.nz.eds.com...
>:
>: Ron Hartikka <ronh@iainc.com> wrote in message
>: news:3A1BDD8B.3B9437B0@iainc.com...

>: > ($new = $old) =~ s/^...(.*)/$1/;

>: ($new = $old) =~ s/^...//;

>Why does everyone apparently insist on using regexes for the simplest of
>string manipulations?


Because they are silly :-)

More seriously, regexes spring up unbidden to seasoned Perl programmers.

It often takes a conscious effort to consider the alternatives
before banging out the code.


>Surely this has to be slower than substr($old, 3) ? 


Guessing is unsatisfying. Let's really find out instead of guessing:

--------------------------
#!/usr/bin/perl -w
use Benchmark;

$old = 'tn_shortname.jpg';
$new;

timethese 5_000_000, { 
   copymod   => q( ($new = $old) =~ s/^...//;
                 ),
   copymodR  => q( ($new = $old) =~ s/^...(.*)/$1/;
                 ),
   subst     => q( $new = substr($old, 3);
                 ),
};
--------------------------

(partial) output:

Benchmark: timing 5000000 iterations of copymod, copymodR, subst...
   copymod: 13 wallclock secs (12.20 usr + -0.02 sys = 12.18 CPU) @ 410509.03/s
  copymodR: 88 wallclock secs (86.62 usr +  0.76 sys = 87.38 CPU) @ 57221.33/s
     subst: 10 wallclock secs ( 8.71 usr +  0.01 sys =  8.72 CPU) @ 573394.50/s


>Or am I missing
>something?


It appears you are missing the Benchmark module  :-)


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


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

Date: Thu, 23 Nov 2000 16:12:13 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Simple Question :)
Message-Id: <8vjfkh$cq4$1@soap.pipex.net>

"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn91qcg0.skn.tadmc@magna.metronet.com...
: Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:

: Guessing is unsatisfying. Let's really find out instead of guessing:
:
: Benchmark: timing 5000000 iterations of copymod, copymodR, subst...
:    copymod: 13 wallclock secs (12.20 usr + -0.02 sys = 12.18 CPU) @
410509.03/s
:   copymodR: 88 wallclock secs (86.62 usr +  0.76 sys = 87.38 CPU) @
57221.33/s
:      subst: 10 wallclock secs ( 8.71 usr +  0.01 sys =  8.72 CPU) @
573394.50/s

So not much slower, then. Surprising.

: >Or am I missing something?

: It appears you are missing the Benchmark module  :-)

Heh. Still only just getting there on the journey from shellscript to
perl...

Geoff




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

Date: Thu, 23 Nov 2000 10:52:28 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Simple Question :)
Message-Id: <slrn91qf9s.t1t.tadmc@magna.metronet.com>

Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:
>"Tad McClellan" <tadmc@metronet.com> wrote in message
>news:slrn91qcg0.skn.tadmc@magna.metronet.com...
>: Geoff Winkless <geoff-at-farmline-dot-com@127.0.0.1> wrote:

>:    copymod: 13 wallclock secs (12.20 usr + -0.02 sys = 12.18 CPU) @
>:      subst: 10 wallclock secs ( 8.71 usr +  0.01 sys =  8.72 CPU) @

>
>So not much slower, then. Surprising.


Anchoring to start of string is nearly always a Big Winner speed-wise,
so I was expecting the difference to be relatively close.


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


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

Date: Thu, 23 Nov 2000 17:30:52 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Simple Question :)
Message-Id: <x7k89ud29h.fsf@home.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:


  TM> $old = 'tn_shortname.jpg';
  TM> $new;

  TM> timethese 5_000_000, { 
  TM>    copymod   => q( ($new = $old) =~ s/^...//;
  TM>                  ),
  TM>    copymodR  => q( ($new = $old) =~ s/^...(.*)/$1/;
  TM>                  ),
  TM>    subst     => q( $new = substr($old, 3);
  TM>                  ),
  TM> };
  TM> --------------------------

  TM> (partial) output:

  TM> Benchmark: timing 5000000 iterations of copymod, copymodR, subst...
  TM>    copymod: 13 wallclock secs (12.20 usr + -0.02 sys = 12.18 CPU) @ 410509.03/s
  TM>   copymodR: 88 wallclock secs (86.62 usr +  0.76 sys = 87.38 CPU) @ 57221.33/s
  TM>      subst: 10 wallclock secs ( 8.71 usr +  0.01 sys =  8.72 CPU) @ 573394.50/s


i add some more variants:

use Benchmark;

$old = 'tn_shortname.jpg';
$new;
$count = shift || 500_000 ;

timethese  $count, { 
	copymod		=> q( ($new = $old) =~ s/^...//; ),
#	copymodR	=> q( ($new = $old) =~ s/^...(.*)/$1/; ),
	copy		=> q( $new = $old ),
	copysubst	=> q( $new = $old ; $new = substr($new, 3); ),
	subst		=> q( $new = substr($old, 3); ),
	subst2		=> q( substr( $new = $old, 0, 3, '') ),
};

Benchmark: timing 1000000 iterations of copy, copymod, copysubst, subst, subst2...
      copy:  3 wallclock secs ( 2.28 usr +  0.00 sys =  2.28 CPU)
   copymod:  7 wallclock secs ( 6.60 usr +  0.00 sys =  6.60 CPU)
 copysubst:  5 wallclock secs ( 4.50 usr +  0.00 sys =  4.50 CPU)
     subst:  2 wallclock secs ( 3.22 usr +  0.00 sys =  3.22 CPU)
    subst2:  5 wallclock secs ( 4.56 usr +  0.00 sys =  4.56 CPU)


if you subtract the copy overhead from the subst2 method, it is the
fastest. it all depends on whether you want a destructive substr or not.
substr as an LVALUE or 4 arg substr replacing with '' is very fast. it
just modifies the internal pointer to the start of the string. no data
is moved.

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: Thu, 23 Nov 2000 18:39:15 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Sort runtime 5.005 vs 5.004
Message-Id: <nvdT5.1429$xb1.91724@eagle.america.net>

On Wed, 22 Nov 2000 16:03:59 -0600, Jim Harrison
<jimharrison3@home.com> wrote:
>Garry Williams <garry@ifr.zvolve.net> wrote in message
>news:J8VS5.1345$xb1.85927@eagle.america.net...
>> On Wed, 22 Nov 2000 11:51:52 -0600, Jim Harrison
>> <jimharrison3@home.com> wrote:
>>
>> >########################################################
>> ># Read stdin into array
>> >@array = (<STDIN>);
>> >
>> ># sort array using normal sort
>> ># and print to stdout
>> >
>> >print sort(@array);
>> >##########################################################
>> >
>> >We are sorting a file that is 162.5 MB with 638,278 records.
>>
>> That code applied to that file is absurd.  Solaris has a fine sort
>> program already: /bin/sort .  Why not use it?  It would run in a
>> fraction of the time and memory no matter what version of perl you
>> were using.
>>
>1st of all I was trying to find out why qsortsv was choosen over the old
>qsort and was there a way to use the old code or something that would
>produce a better answer.  Our code is more complicated than I showed, but
>this code segment illustrated the problem.  In the case sited, the runtime
>for the sort was 50 times slower using qsortsv vs the qsort. (3360 sec vs 56
>sec).
>
>Now as far as Solaris is concerned.  I ran /bin/sort against the same file
>and the runtime was 591 seconds vs 50 seconds using the perl 5.004 program,
>i.e. 10 TIMES SLOWER.  That is why we wrote the sort in the first place, so
>we could speed up the run time for sorts on large files.

Please accept my apology.  I was wrong about the /bin/sort
performance.  I was remembering some benchmarks I did a few years ago,
but I obviously remembered wrong.  :-(  

I just did what I should have done before posting originally.  I
created a test file to mimic your problem by recording 638,278 records
of random printable ascii data.  Each record is 239 characters long
including the new line character: 

    -rw-rw-r--   1 garry    staff    152548442 Nov 23 13:05 test_file

I then ran /bin/sort against it and ran perl's in-memory sort against
the same file.  Here's the results: 

    $ time sort -T/usr/sort_work <test_file >t.sort

    real    1m47.23s
    user    0m59.17s
    sys     0m6.50s
    $ time perl -we 'print sort <>' <test_file >t.perl

    real    0m30.48s
    user    0m17.06s
    sys     0m5.64s
    $ perl -wle 'print +(60+47.23)/30.48'
    3.51804461942257
    $

This was done on a Sun Ultra 10 that wasn't doing anything else at the
time.  So /bin/sort takes about 3.5 times as long to sort the same
file.  There is only one physical disk drive involved, so /bin/sort
might perform a bit better, if it can have a separate drive for its
work files and its output but the point is that perl will win doing
the sort in memory.  

I observed one anomaly, too.  The files are different sizes when
/bin/sort does the job: 

    -rw-rw-r--   1 garry    staff    152548442 Nov 23 13:15 t.perl
    -rw-rw-r--   1 garry    staff    152548476 Nov 23 13:15 t.sort
    -rw-rw-r--   1 garry    staff    152548442 Nov 23 13:05 test_file

I have no idea what the difference is or why it occurred but it is
repeatable.  

Of course, none of this answers your original question.  

-- 
Garry Williams


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

Date: Thu, 23 Nov 2000 18:47:19 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Sort runtime 5.005 vs 5.004
Message-Id: <XCdT5.1430$xb1.91724@eagle.america.net>

On Thu, 23 Nov 2000 18:39:15 GMT, Garry Williams
<garry@ifr.zvolve.net> wrote:
>On Wed, 22 Nov 2000 16:03:59 -0600, Jim Harrison
><jimharrison3@home.com> wrote:
>>Garry Williams <garry@ifr.zvolve.net> wrote in message
>>news:J8VS5.1345$xb1.85927@eagle.america.net...
>>> On Wed, 22 Nov 2000 11:51:52 -0600, Jim Harrison
>>> <jimharrison3@home.com> wrote:
>

[snip]

>So /bin/sort takes about 3.5 times as long to sort the same
>file.  

Oh, yeah I forgot to mention: 

    $ perl -v

    This is perl, v5.6.0 built for sun4-solaris

-- 
Garry Williams


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

Date: 23 Nov 2000 15:13:50 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91qd1e.vl.eric@plum.fruitcom.com>

I want to split a multi-line scalar into an array.  I want each element of
the array to have a line terminated by a "\n".
Problem is that when I split on "\n", then this newline character is lost.

Of course I can loop through the array and stick it back on again but I
want to do it right when I create the array.


Any suggestions?

Thanx 


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

Date: 23 Nov 2000 15:21:48 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91qdgc.vl.eric@plum.fruitcom.com>

Oh, I just sent off this posting then tried this:
@array=split "(?<=\n)",$string;
Seemed to work just fine :)

Eric Smith posted
 > I want to split a multi-line scalar into an array.  I want each element of
 > the array to have a line terminated by a "\n".
 > Problem is that when I split on "\n", then this newline character is lost.
 > 
 > Of course I can loop through the array and stick it back on again but I
 > want to do it right when I create the array.
 > 
 > 
 > Any suggestions?
 > 
 > Thanx 


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

Date: Thu, 23 Nov 2000 15:26:31 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91qdqd.nks.rgarciasuarez@rafael.kazibao.net>

Eric Smith wrote in comp.lang.perl.misc:
> I want to split a multi-line scalar into an array.  I want each element of
> the array to have a line terminated by a "\n".
> Problem is that when I split on "\n", then this newline character is lost.
> 
> Of course I can loop through the array and stick it back on again but I
> want to do it right when I create the array.


my @array = split /(?<=\n)/, $multi_line_string;

see the perlre manpage for details.

-- 
#!/usr/bin/perl -p
BEGIN { *ARGV=*DATA }
__END__
Just another Perl hacker,


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

Date: Thu, 23 Nov 2000 10:30:16 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91qe08.suv.tadmc@magna.metronet.com>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>Eric Smith wrote in comp.lang.perl.misc:
>> I want to split a multi-line scalar into an array.  I want each element of
>> the array to have a line terminated by a "\n".
>> Problem is that when I split on "\n", then this newline character is lost.
>> 
>> Of course I can loop through the array and stick it back on again but I
>> want to do it right when I create the array.
>
>
>my @array = split /(?<=\n)/, $multi_line_string;


Or use a m///g in list context:

   my @array = $multi_line_string =~ /.*\n/g;


>see the perlre manpage for details.

see the perlop manpage for m///g in list context too.


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


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

Date: Thu, 23 Nov 2000 09:15:59 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: splitting a word
Message-Id: <slrn91q9kv.skn.tadmc@magna.metronet.com>

Jakob Schmidt <sumus@aut.dk> wrote:
>tadmc@metronet.com (Tad McClellan) writes:
>
>> Why generate 3 leading null fields to discard when you need to discard 4?
>
>As I understand the OP he wanted 


Well we had to guess what he wanted, 'cause he didn't say.

He only provided some ambiguous examples, not a specification.

   delete up to the first dot?
   delete the first four characters?
   delete everything before "def"?
   delete all but the last two dot-separated parts?

Any of those could be implied from what we were provided with.

(which, along with the cross-posting that indicated a significant 
 lack of clue, is why I didn't bother trying to help him myself 
 when I saw the original post. 'cause I didn't want to come up
 with 4 answers, only to have him discard 3 (or even 4) of them.
 I figured I'd let others bounce around due to the crappy spec,
 while I moved on to help someone who could at least state
 what it was they wanted  :-)
)


>to split on the first dot:

>    ( undef, $temp ) = split /\./, $_, 2;
                               ^
                               ^
The split() I was commenting on didn't have that backslash there,
hence my question above. 


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


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

Date: 23 Nov 2000 18:28:31 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: splitting a word
Message-Id: <1yw2egxs.fsf@macforce.sumus.dk>

tadmc@metronet.com (Tad McClellan) writes:

> Jakob Schmidt <sumus@aut.dk> wrote:
> >As I understand the OP he wanted 
> 
> Well we had to guess what he wanted, 'cause he didn't say.

I agree. Couldn't resist the temptation to try to guess it ;-)

> (which, along with the cross-posting that indicated a significant 
>  lack of clue, is why I didn't bother trying to help him myself 
>  when I saw the original post. 'cause I didn't want to come up
>  with 4 answers, only to have him discard 3 (or even 4) of them.
>  I figured I'd let others bounce around due to the crappy spec,
>  while I moved on to help someone who could at least state
>  what it was they wanted  :-)
> )

That sounds reasonable.

> The split() I was commenting on didn't have that backslash there,
> hence my question above. 

I know. It was just an absurd way of cutting the first few chars.

-- 
Jakob Schmidt
http://aut.dk/orqwood
etc.


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

Date: Thu, 23 Nov 2000 17:56:04 +0000
From: Roman Kosenko <ra@amk.lg.ua>
Subject: Re: splitting a word
Message-Id: <Pine.LNX.3.96.SK.1001123175401.2016A-100000@amk.al.lg.ua>

On Wed, 22 Nov 2000, Thanh Q Lam wrote:


s/^[^.]+\.//;


> Hi,
> 
> Can you help to split a word into two parts?
> 
> inputs:
> abc.def.h
> txt.def.hh
> 
> output should look like this:
> def.h
> def.hh
> 
> thanks in advance!
> 
> -Thanh
> 
> 




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

Date: Thu, 23 Nov 2000 15:45:38 -0000
From: "D.B" <dvbryan@_nospamplsHotmail.com>
Subject: Stripping Comma's and Spaces
Message-Id: <DVaT5.5070$ws2.736279@news3.cableinet.net>

I have several $trings passed from a form (around 100+):

$Salutation = $input->param('Salutation');
$Surname = $input->param('Surname');
$Name = $input->param('Name');
$Middlename = $input->param('Middlename');
 .
 .
 .
$Lastfield = $input->param('Lastfield');

I'd like to check if any of the field's contain:
1)a comma, if so I'd like to remove the comma.
2)two spaces together, if so I like to substitute for one space

Any recommedations/pointers to implement a routine greatly appreciated.

DB


 ....?would it be better if the String Names were similar in order to use
some array function?




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

Date: Thu, 23 Nov 2000 16:39:05 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Stripping Comma's and Spaces
Message-Id: <JKbT5.1425$xb1.91419@eagle.america.net>

On Thu, 23 Nov 2000 15:45:38 -0000, D.B <dvbryan@_nospamplsHotmail.com> wrote:
>I have several $trings passed from a form (around 100+):
>
>$Salutation = $input->param('Salutation');
>$Surname = $input->param('Surname');
>$Name = $input->param('Name');
>$Middlename = $input->param('Middlename');
>.
>.
>.
>$Lastfield = $input->param('Lastfield');
>
>I'd like to check if any of the field's contain:
>1)a comma, if so I'd like to remove the comma.
>2)two spaces together, if so I like to substitute for one space
>
>Any recommedations/pointers to implement a routine greatly appreciated.

Here's a recommendation and pointer: 

Read the perlop manual page with special attention to the s/// and
tr/// operators in the section "Regexp Quote-Like Operators".  

    tr/,//d;
    s/  / /g;

-- 
Garry Williams


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

Date: Thu, 23 Nov 2000 10:37:32 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Stripping Comma's and Spaces
Message-Id: <slrn91qeds.suv.tadmc@magna.metronet.com>

D.B <dvbryan@_nospamplsHotmail.com> wrote:

>$Salutation = $input->param('Salutation');
>$Surname = $input->param('Surname');
>$Name = $input->param('Name');

>1)a comma, if so I'd like to remove the comma.
>2)two spaces together, if so I like to substitute for one space


So three spaces together should become two spaces?

And four spaces together should become two spaces?

I'll assume you meant "runs of consecutive spaces replaced with
a single space" instead.


>Any recommedations/pointers to implement a routine greatly appreciated.


   tr/,//d, tr/ //s foreach $Salutation, $Surname, $Name;


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


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

Date: Thu, 23 Nov 2000 16:51:34 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: Stripping Comma's and Spaces
Message-Id: <lblmuafx7u.fsf@lnc.usc.edu>

"D.B" <dvbryan@_nospamplsHotmail.com> writes:

> I have several $trings passed from a form (around 100+):
> 
> $Salutation = $input->param('Salutation');
> $Surname = $input->param('Surname');
> $Name = $input->param('Name');
> $Middlename = $input->param('Middlename');
> .
> .
> .
> $Lastfield = $input->param('Lastfield');
> 
> I'd like to check if any of the field's contain:
> 1)a comma, if so I'd like to remove the comma.

$string = $input('string'); $string =~ s/,//g;

> 2)two spaces together, if so I like to substitute for one space

$string = $input('string'); $string =~ s/[ ]{2}/ /g;

> 
> Any recommedations/pointers to implement a routine greatly appreciated.

Pickup "Mastering Regular Expressions" by Jeffrey Freidl
or type perldoc perlre

> 
> DB
> 
> 
> ....?would it be better if the String Names were similar in order to use
> some array function?
> 
> 

-- 
Terrence Brannon


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

Date: Thu, 23 Nov 2000 13:01:25 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Stripping Comma's and Spaces
Message-Id: <Pine.GSO.4.21.0011231300240.714-100000@crusoe.crusoe.net>

On Nov 23, Tad McClellan said:

>   tr/,//d, tr/ //s foreach $Salutation, $Surname, $Name;

It's (pedantically) faster to make one run through the string, than two:

  tr/ ,/ /ds;

-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/





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

Date: 23 Nov 2000 17:54:04 +0000
From: nobull@mail.com
Subject: Re: Stripping Comma's and Spaces
Message-Id: <u9d7fmshfn.fsf@wcl-l.bham.ac.uk>

"D.B" <dvbryan@_nospamplsHotmail.com> writes:

> I have several $trings passed from a form (around 100+):
> 
> $Salutation = $input->param('Salutation');
> $Surname = $input->param('Surname');
> $Name = $input->param('Name');
> $Middlename = $input->param('Middlename');
> .
> .
> .
> $Lastfield = $input->param('Lastfield');

Ouch!  You seriously need a hash not 100 separate scalar variables.

> I'd like to check if any of the field's contain:
> 1)a comma, if so I'd like to remove the comma.
> 2)two spaces together, if so I like to substitute for one space

tr/ ,/ /sd;

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


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

Date: 23 Nov 2000 17:56:33 +0000
From: nobull@mail.com
Subject: Re: Subroutine Stuff???
Message-Id: <u9bsv6shbi.fsf@wcl-l.bham.ac.uk>

<vidulats@yahoo.co.uk> writes:

> Subject: Subroutine Stuff???

perldoc perlsub

> Hi PerlExperts,

Saying "Hi" is not the way to endear yourself to the experts.

If you want the experts to treat you favourably then make sure your
code uses strict.  Also make sure you have read the manuals and makes
sure this is made clear by your post.

> My question is:
> I want to write one subroutine like
> Receive ($Val1, %Elements, $Time);

By default Perl treats the arguments of a subroutine as a simple list.
If you put a hash in a list context it gets unrolled into a list.  You
do not want this.  You want to pass a reference to the %Elements hash
to Receive().  You _either_ need pass to put a \ in front of %Elements
_or_ give Receive() an appropriate prototype.  See perlsub and perlref
for details.

> Inside the Receive function :
> sub Receive
> {
>    ($myv, %mye, $myt) = @_;

You are missing my() - this is not the cause of your current problem
but will cause your program to fail sooner or later.  The missing
my() would have been detected by "use strict".

Since what is actually passed to the subroutine is a reference to a
hash you need to change %mye to $mye.

> I tried in the following way:

> $Status = Receive1(%Message);

Since you have not defined a prototype for Receive1() you need a \ in
there.

> sub Receive1
> {	$i = 1;
> 	foreach $val (sort keys %$_)
> 	{	$$_{$val} = $i;
> 		$i++;
> 	}
> 	return 0;
> }

You are confusing $_ with $_[0].  They are completely different things
(see perlvar). 

Change $_ to {$_[0]} above and it should work - but it would look
messy - probably better to copy $_[0] to another variable.

Also you've forgotten to my() $i, once again "use strict" would have
caught this for you before you wasted many hours looking for a bug
somewhere else in your program.

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


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 4956
**************************************


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