[18570] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 738 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 21 21:06:01 2001

Date: Sat, 21 Apr 2001 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <987901506-v10-i738@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 21 Apr 2001     Volume: 10 Number: 738

Today's topics:
    Re: Append <bart.lateur@skynet.be>
    Re: Append (Abigail)
    Re: Command Piping in Perl (Tom Hoffmann)
    Re: File path not getting resolved correctly. (Abigail)
    Re: Getting character codes <abe@ztreet.demon.nl>
    Re: Getting character codes (Logan Shaw)
    Re: Infinate loop (Tad McClellan)
    Re: Mail:Mailer / Net:SMTP speed issue <kilbride@principia-MAPS-ON.edu>
        operators: != vs. ne, strange behaviour <kvlahovi@tiscali.it>
        pointer/reference question <xris@dont.send.spam>
    Re: So what do YOU use Perl for? (David Combs)
    Re: So what do YOU use Perl for? (E.Chang)
        split after a number of charachters? <m9652@abc.se>
    Re: split after a number of charachters? (Logan Shaw)
    Re: split after a number of charachters? <abe@ztreet.demon.nl>
    Re: split after a number of charachters? (Abigail)
    Re: split after a number of charachters? (Steve)
    Re: split after a number of charachters? <krahnj@acm.org>
    Re: Things I'm just not getting in Perl (Abigail)
    Re: US$50 prize for hash failure from 'delete' inside a (Anno Siegel)
    Re: US$50 prize for hash failure from 'delete' inside a <mjd@plover.com>
        Which is faster/better? <xris@dont.send.spam>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 21 Apr 2001 22:17:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Append
Message-Id: <fn14et04254c9570mnb21mn9l65fl8jpci@4ax.com>

Tom Bowes wrote:

>use cgi ':standard';
(Psst! it's "CGI"!)
>open (APPEND, ">>messages.htm") or die "$! error trying to append";
>print APPEND "Name:";
>print APPEND (param('name'));
>print APPEND (param('message'));

What on earth are you printing plain, unescaped text to a "html" file
for?

-- 
	Bart.


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

Date: Sat, 21 Apr 2001 22:49:21 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Append
Message-Id: <slrn9e43jh.rkg.abigail@tsathoggua.rlyeh.net>

Bart Lateur (bart.lateur@skynet.be) wrote on MMDCCXC September MCMXCIII
in <URL:news:fn14et04254c9570mnb21mn9l65fl8jpci@4ax.com>:
[] Tom Bowes wrote:
[] 
[] >use cgi ':standard';
[] (Psst! it's "CGI"!)
[] >open (APPEND, ">>messages.htm") or die "$! error trying to append";
[] >print APPEND "Name:";
[] >print APPEND (param('name'));
[] >print APPEND (param('message'));
[] 
[] What on earth are you printing plain, unescaped text to a "html" file
[] for?


Eh, being of type 'HTML' is a property of the content of a file, not
a property of its filename.


Abigail


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

Date: Sat, 21 Apr 2001 22:30:24 GMT
From: tom.hoffmann@worldnet.att.net (Tom Hoffmann)
Subject: Re: Command Piping in Perl
Message-Id: <slrn9e42aa.lo.tom.hoffmann@localhost.localdomain>

On Sat, 21 Apr 2001 02:44:49 +0000 (UTC), Abigail <abigail@foad.org> wrote:
>Eh, let me guess. Use a quoting style that does allow interpolation?

Of course. My stupidity. I thought the system function *required*
single quotes since all the examples I saw in perldoc for exec and
system used single quotes.

Thanks to all who responded.


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

Date: Sat, 21 Apr 2001 22:54:17 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: File path not getting resolved correctly.
Message-Id: <slrn9e43sp.rkg.abigail@tsathoggua.rlyeh.net>

Alex Farber (farber@cpan.org) wrote on MMDCCXC September MCMXCIII in
<URL:news:3AE20AA8.DAD1D65A@cpan.org>:
\\ tmerenes.dontspam@sybase.com wrote:
\\ > 
\\ > I'm running MKS perl in a WinNT 4.0 SP 6a DOS session.
\\ > 
\\ > The file path in the following statement does not get resolved correctly:
\\ > 
\\ > system ("isql -SDB2SOL -Utmerenes -PCOGRULES
\\ > -iD:\DC\12.00.03\236669\repro.sql");
\\ 
\\ Why do you call isql instead of using DBD::Sybase?


*blink*


I can't imagine why not. Can your write, using DBD::Sybase, a function
that does what the line above does, and is as concise?

You only got one line to do it!



Abigail


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

Date: Sun, 22 Apr 2001 00:12:53 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Getting character codes
Message-Id: <bs04et82nf641eva1depmma8cb750edp86@4ax.com>

On 21 Apr 2001 16:15:37 -0500, logan@cs.utexas.edu (Logan Shaw) wrote:

> In article <slrn9e3mbp.gv7.rpolzer@www42.t-offline.de>,
> echo 'Rudolf Polzer'>/dev/null <null@durchnull.de> wrote:
> >Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> >> According to Peter Reid  <peter.reid2000@ntlworld.com>:
> >> > Does anyone know how to get the character code of a letter (eg X is 88)
> >> > and also how to get a letter from its code ????
> >> 
> >> ord() and chr().
> >
> >Oh no, I always used pack and unpack for this :( 
> 
> That's sort of silly, but not nearly silly enough, I think.  If you do
> this:
> 
> 	$mapping = join ("", map (chr, 0 .. 255));
> 
> Then you can use
> 
> 	$code = index($mapping, $character);
> 
> and
> 
> 	$character = $mapping[$code];

Now were did @mapping spring into existence?
Did you perhaps want:

	my $mapping = join "", my @mapping = map { chr } 0..255;

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: 21 Apr 2001 17:20:53 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Getting character codes
Message-Id: <9bt145$4b7$1@charity.cs.utexas.edu>

In article <bs04et82nf641eva1depmma8cb750edp86@4ax.com>,
Abe Timmerman  <abe@ztreet.demon.nl> wrote:
>On 21 Apr 2001 16:15:37 -0500, logan@cs.utexas.edu (Logan Shaw) wrote:
>> That's sort of silly, but not nearly silly enough, I think.  If you do
>> this:
>> 
>> 	$mapping = join ("", map (chr, 0 .. 255));
>> 
>> Then you can use
>> 
>> 	$code = index($mapping, $character);
>> 
>> and
>> 
>> 	$character = $mapping[$code];
>
>Now were did @mapping spring into existence?

Oops, somehow my brain was telling me to type "substr()" but it
rebelled against itself and caused me to type "[]" instead.  I guess my
code ended up being silly in an unintended sense.  :-(

I meant this:

	$code = index($mapping, $character);

and

	$character = substr($mapping, $code, 1);

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Sat, 21 Apr 2001 18:20:59 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Infinate loop
Message-Id: <slrn9e41ub.9nn.tadmc@tadmc26.august.net>

I myself <tadmc@augustmail.com> wrote:

>>while (($key, $value) = each %dbm_hash)
>                         ^^^^^^^^^^^^^^
>
>>{
>
>>   while (($key2, $value2) = each %dbm_hash)
>                              ^^^^^^^^^^^^^^
>
>Oops. You have "dualing iterators". 


I meant "dueling" of course.


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


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

Date: Sat, 21 Apr 2001 17:14:36 -0700
From: Matthew Kilbride <kilbride@principia-MAPS-ON.edu>
Subject: Re: Mail:Mailer / Net:SMTP speed issue
Message-Id: <3AE2226C.C708DCEA@principia-MAPS-ON.edu>

I was avoiding using sendmail because I know nothing about setting it up, but I guess I'll
give it a try.  Thanks for the help.

"echo 'Rudolf Polzer'>/dev/null" wrote:

> Matthew Kilbride <kilbride@principia-MAPS-ON.edu> wrote:
> > I just started working with the Mail:Mailer module so that I could send form data.   I
> > have found that there is a 25 second pause when I submit the form.  I am using SMTP, and
> > have ttried a number of things, including with/without resolve.conf, bringing down my
> > packet filters, sending via Net:SMTP directly, and sending to various different SMTP
> > servers.  I have had no success with decreasing the processing time for the form.  There
> > is not much data being sent (4 fields).  This seems to point to Net:SMTP, but affects
> > Mail:Mailer, which relies upon Net:SMTP.  The Perl Cookbook suggests using Mail:Mailer,
> > which leads me to believe that this should be a good module to use for this purpose.
> >
> > Is this delay a known issue, or is there some optimization that I should look into?  Any
> > assistance would be greatly appreciated....
>
> Try calling sendmail instead. Then you do not have to wait until the
> server responds.
>
> --
> #!/usr/bin/perl
> eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
> $0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
> ####################### http://learn.to/quote #######################



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

Date: Sun, 22 Apr 2001 02:15:26 +0200
From: "Kristian" <kvlahovi@tiscali.it>
Subject: operators: != vs. ne, strange behaviour
Message-Id: <9bt7n5$njk$1@pegasus.tiscalinet.it>

Hello,

This one is deffinitely one of newbie-ish, but I'm really puzzled by this
behaviour of perl and would really like to understand what is the problem
and in what way are the != and 'ne' operators different...

I have the data file which roughly looks like this:

IDENTIFIER1:IDENTIFIER2 SET_OF_NUMBERS
IDENTIFIER1:IDENTIFIER3 SET_OF_NUMBERS
IDENTIFIER1:IDENTIFIER4 SET_OF_NUMBERS

IDENTIFIERx:IDENTIFIER5 SET_OF_NUMBERS
IDENTIFIERx:IDENTIFIER6 SET_OF_NUMBERS

there is a set of identifier pairs in a variable length record that is
separated by a double newline, and in each record the left-side identifier
should allways be the same, while the right-side one (after colon) changes.
I call them query (left-hand) and subject (right-hand)
the identifiers are in the following format:
LU1A_LYCPN-52-60-293(1-9):D69064-19-294-293(2-10)

I do this (just the important parts shown here):


$/ = "\n\n"; # record delimiter

while (<>) {

 $query_id = "";
   if (/^(\w+-\d+-\d+)-(\d+)\((\d+)-(\d+)\):/) {
          $query_id = $1
  }

 @lines = split "\n";
 foreach $line (@lines) {
  if ($line =~ /(\S+):(\S+)\t(.*)/ ) {
          $query = $1; $subject = $2; $rest = $3;
     ($qry_id, $qry_clus, $qry_frm, $qry_to) = ($1, $2, $3, $4)
           if   $query =~ /(\w+-\d+-\d+)-(\d+)\((\d+)-(\d+)\)/ ;
  }

  if ($qry_id != $query_id) {
      print "$qry_id != $query_id !!!!\n";
      die;
    }

}

and, when i run this on my data I get the following error:

NANA_STRPN-381-392 != NANA_STRPN-381-392 !!!!
Died at ./statistics.pl line 50, <> chunk 798.


so, the program goes on for a while quite happy with != operator using to
compare two identifiers, but after a while decides that the two strings are
not equal any more... if I use 'ne' instead, everything seems to run OK.
this one is not the first record and there is nothing peculiar in data with
respect to other records...


please help me understand what's going on...

thx, Kristian




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

Date: Sat, 21 Apr 2001 19:39:21 -0500
From: xris <xris@dont.send.spam>
Subject: pointer/reference question
Message-Id: <xris-4CAEE0.19392121042001@news.evergo.net>

another silly question that I can't seem to find in my books...  Is 
there any way, OTHER than using globs, to assign two variables to the 
same memory space?

something like:

\$x = \$y;

or

$x = $$y;  (though not COPYING the data, as this does)

I'd love to be able to pass more things to subroutines by reference, but 
don't want to mess with the TONS of dereferencing that would need to be 
done in some larger ones.

Thanks,

Chris



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

Date: 21 Apr 2001 23:56:45 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: So what do YOU use Perl for?
Message-Id: <9bt6nt$39t$1@news.panix.com>

In article <tds7ccn0vdtoa6@corp.supernews.com>,
Chris Stith  <mischief@velma.motion.net> wrote:
>Ilmari Karonen <iltzu@sci.invalid> wrote:

>>  * "rename 's/htm$/html/' *.htm"
>
>I like that a lot.


A little explanation would be helpful as to what that
statement does.




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

Date: Sun, 22 Apr 2001 00:34:25 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: So what do YOU use Perl for?
Message-Id: <Xns908AD0E0378F1echangnetstormnet@207.106.92.86>

dkcombs@panix.com (David Combs) wrote in <9bt6nt$39t$1@news.panix.com>:

>In article <tds7ccn0vdtoa6@corp.supernews.com>,
>Chris Stith  <mischief@velma.motion.net> wrote:
>> Ilmari Karonen <iltzu@sci.invalid> wrote:
>
>>> * "rename 's/htm$/html/' *.htm"
>> 
>> I like that a lot.
>
>
>A little explanation would be helpful as to what that
>statement does.
>

It might be helpful if you really needed to do that in a hurry, but if not, 
you'll learn more by trying to figure it out yourself. (And have a lot more 
fun too.)  Look up the rename and s (substitution) operators (perldoc -f 
rename and perldoc -f s).  (Oh, and a hint:  .html is preferred over .htm 
as an extension for web documents - unless you're running your server on a 
Windows 3.x machine)

-- 
EBC


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

Date: Sun, 22 Apr 2001 00:01:20 +0200
From: kb <m9652@abc.se>
Subject: split after a number of charachters?
Message-Id: <3AE20330.A1B94360@abc.se>

hi
how can i use the split function to split after a number of characters?

lets say i have the string: "0123456789"
i dont have any good separators within the string but i would like to
split it after lets say 8 characters

$string = "0123456789";
($part1, $part2) = split(split after 8 characters, $string);


/konrad



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

Date: 21 Apr 2001 17:18:32 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: split after a number of charachters?
Message-Id: <9bt0vo$4aa$1@charity.cs.utexas.edu>

In article <3AE20330.A1B94360@abc.se>, kb  <m9652@abc.se> wrote:
>hi
>how can i use the split function to split after a number of characters?
>
>lets say i have the string: "0123456789"
>i dont have any good separators within the string but i would like to
>split it after lets say 8 characters
>
>$string = "0123456789";
>($part1, $part2) = split(split after 8 characters, $string);

Using the split operator is the hard way.  It's much easier to do this:

	$string = "0123456789";
	($part1, $part2) = $string =~ /^(.{8})(.*)$/s;

Or this:

	$string = "0123456789";
	$part1 = substr ($string, 0, 8);
	$part2 = substr ($string, 8);

Hope that helps.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Sun, 22 Apr 2001 00:53:41 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: split after a number of charachters?
Message-Id: <fj34et8np5oels82lhndftk278p62te86v@4ax.com>

On Sun, 22 Apr 2001 00:01:20 +0200, kb <m9652@abc.se> wrote:

> hi

Hi,

> how can i use the split function to split after a number of characters?

That is not the task split was designed for.
 
> lets say i have the string: "0123456789"
> i dont have any good separators within the string but i would like to
> split it after lets say 8 characters
> 
> $string = "0123456789";
> ($part1, $part2) = split(split after 8 characters, $string);

	( $part1, $part2 ) = unpack 'A8 A*', $string;

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: Sat, 21 Apr 2001 23:01:28 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: split after a number of charachters?
Message-Id: <slrn9e44a8.rkg.abigail@tsathoggua.rlyeh.net>

kb (m9652@abc.se) wrote on MMDCCXC September MCMXCIII in
<URL:news:3AE20330.A1B94360@abc.se>:
%% hi
%% how can i use the split function to split after a number of characters?
%% 
%% lets say i have the string: "0123456789"
%% i dont have any good separators within the string but i would like to
%% split it after lets say 8 characters
%% 
%% $string = "0123456789";
%% ($part1, $part2) = split(split after 8 characters, $string);


Uhm, uhm, what you want is fairly trivial, and there are several ways
to do so in Perl.

None of them involve split though. Why insist on using split for this?



Abigail


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

Date: 21 Apr 2001 23:23:00 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: split after a number of charachters?
Message-Id: <slrn9e45gp.3qm.steve@zero-pps.localdomain>

On Sun, 22 Apr 2001 00:01:20 +0200, kb wrote:
>hi
>how can i use the split function to split after a number of characters?
>
>lets say i have the string: "0123456789"
>i dont have any good separators within the string but i would like to
>split it after lets say 8 characters
>
>$string = "0123456789";


$firsteight = substr($string,0,8);

Just another way of doing it. 

-- 
Cheers
Steve              email mailto:steve@zeropps.uklinux.net

%HAV-A-NICEDAY Error not enough coffee  0 pps. 

web http://www.zeropps.uklinux.net/

or  http://start.at/zero-pps

 12:17am  up 79 days,  1:02,  2 users,  load average: 1.00, 1.00, 1.06


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

Date: Sun, 22 Apr 2001 00:24:39 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: split after a number of charachters?
Message-Id: <3AE224C7.376CEE46@acm.org>

Abe Timmerman wrote:
> 
> On Sun, 22 Apr 2001 00:01:20 +0200, kb <m9652@abc.se> wrote:
> 
> > hi
> 
> Hi,
> 
> > how can i use the split function to split after a number of characters?
> 
> That is not the task split was designed for.
> 
> > lets say i have the string: "0123456789"
> > i dont have any good separators within the string but i would like to
> > split it after lets say 8 characters
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^

> >
> > $string = "0123456789";
> > ($part1, $part2) = split(split after 8 characters, $string);
> 
>         ( $part1, $part2 ) = unpack 'A8 A*', $string;

        ( $part1, $part2 ) = unpack 'x8 a a', $string;


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 21 Apr 2001 22:47:03 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Things I'm just not getting in Perl
Message-Id: <slrn9e43f7.rkg.abigail@tsathoggua.rlyeh.net>

echo 'Rudolf Polzer'>/dev/null (rpolzer@durchnull.de) wrote on MMDCCXC
September MCMXCIII in <URL:news:slrn9e3uj0.tqp.rpolzer@www42.t-offline.de>:
!! Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
!! > According to echo 'Rudolf Polzer'>/dev/null <null@durchnull.de>:
!! > > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
!! > > > According to Damian Conway <damian@cs.monash.edu.au>:
!! > > > 
!! > > > [...]
!! > > >  
!! > > > > Or just use the special C<< 1-print >> built-in:
!! > > > > 
!! > > > > 	do { print "enter a number: " }
!! > > > > 		until ($response)=<>=~/^(\d+)$/
!! > > > > 		   or 1-print "No, stupid, ";
!! > > > 
!! > > > The 1-print operator has been deemed unsafe.  Use the newer !print.
!! > > 
!! > > Why exactly? Isn't true always returned as 1 in boolean functions?
!! > 
!! > What boolean function?  "print" is part of an arithmetic expression.
!! 
!! OK, the other way round.
!! 
!! 1-print is evaluated in boolean context =>
!! print is evaluated in numeric context =>
!! true for OK is casted to 1 =>
!! 1-1 is calculated =>
!! the result is false (boolean context).


This is certainly not always the case. index(), the boolean function [1]
that returns true if one string doesn't start with the other does not
always return 1 for "true".

Hell, not even '||' returns 1 for "true".


[1] boolean function? In *Perl*?!? There are no flippin' booleans in Perl.
    It just inherits the moronic behaviour of C. Real languages have boolean.



Abigail
-- 
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
   . "\162\1548\110\141\143\153\145\162\0128\177"  and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}


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

Date: 21 Apr 2001 15:18:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: US$50 prize for hash failure from 'delete' inside an 'each' loop
Message-Id: <9bs8bh$dh5$1@mamenchi.zrz.TU-Berlin.DE>

According to Mark-Jason Dominus  <mjd@plover.com>:
> 
> The 'perlfunc' man page says:
> 
>         each   ...
>                
>                If you ... delete elements of a hash while you're
>                iterating over it, you may get entries skipped or
>                duplicated...
> 
> I will give a $50 prize to the first person who can come up with an
> example that demonstrates this.

[...]
 
>   The code should probably have the following form:
> 
>         %hash = ...;
> 
>         while (my ($k, $v) = each %hash) {
>           print "Processed key $k.\n";
>           if (...) {
>             delete $hash{...};
>           }
>         }
> 

This seems to imply there is only one deletion per key processed.  Is
that meant to be a restriction?

Anno


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

Date: Sat, 21 Apr 2001 20:14:05 -0400
From: Mark-Jason Dominus <mjd@plover.com>
Subject: Re: US$50 prize for hash failure from 'delete' inside an 'each' loop
Message-Id: <20010422001405.21362.qmail@plover.com>


Anno Siegel asks:
> >   The code should probably have the following form:
> > 
> >         %hash = ...;
> > 
> >         while (my ($k, $v) = each %hash) {
> >           print "Processed key $k.\n";
> >           if (...) {
> >             delete $hash{...};
> >           }
> >         }
> > 
> 
> This seems to imply there is only one deletion per key processed.  Is
> that meant to be a restriction?

No, it was just intended to be an example.  It's OK to delete as many
keys as you want at any time.  

Of course, you must not add keys, since it's well-known that this
can cause duplications and omissions, and easy to demonstrate.


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

Date: Sat, 21 Apr 2001 19:35:25 -0500
From: xris <xris@dont.send.spam>
Subject: Which is faster/better?
Message-Id: <xris-2EAC61.19352421042001@news.evergo.net>

The perl book talks about using join() instead of a sequence of 
concatenated strings, but doesn't really say much more than that, so my 
question is, which is faster?

a)   $str = join('', $s1, $s2, ..., $sx);

b)   $str = $s1;
     $str .= $s2;
     ...
     $str .= $sx;

c)   $str = $s1 . $s2 . ... $sx;

d)   $str = "$s1$s2...$sx";

??

I'm not only interested in which is faster, but also which performs 
better under large-string circumstances.  I've had join() die on my a 
few times because I was trying to join three VERY large strings.

I'm also particularly interested in the speed differences between b and 
c.  I know that technically c should run faster since it's one command 
as opposed to several, but is the .= command faster than, say, doing 
something like

   $str = $str . $suffix; ??

same goes for something like:

   substr($str, 0, 0) = $prefix;  ??

--

I've been programming in perl for over 6 years now, and tend to use 
whatever looks cleanest, but being an efficiency nut, I'd really like to 
know the differences between all of these ways of doing things.  Plus, 
I'm sure it might help out some novices to learn from my own mistakes.  
:)


-Chris



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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 738
**************************************


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