[17990] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 150 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 14:21:15 2001

Date: Fri, 26 Jan 2001 11:05:21 -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: <980535921-v10-i150@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 26 Jan 2001     Volume: 10 Number: 150

Today's topics:
        Basic string question  <nesta@psi.com.mx>
    Re: Basic string question  <juex@deja.com>
    Re: Basic string question <jdf@pobox.com>
    Re: Basic string question <godzilla@stomp.stomp.tokyo>
    Re: Basic string question nobull@mail.com
    Re: Comparing multiple values (Nick Condon)
    Re: Comparing multiple values <joe+usenet@sunstarsys.com>
    Re: Dealing with x1b character hparks@my-deja.com
    Re: Dealing with x1b character hparks@my-deja.com
    Re: Dealing with x1b character (Mark Jason Dominus)
        FAQ Bug? split problems <cmg@uab.edu>
        Finding unused variables ? (Jan Willamowius)
        First time user needs database help. <johnm@acadiacom.net>
    Re: First time user needs database help. (Garry Williams)
    Re: Form Processing - newbie question <paul_wasilkoff@ucg.org>
    Re: HELP WANTED: perl ans oracle database (Mark Jason Dominus)
    Re: How to close a socket on inactivity ? <jdf@pobox.com>
    Re: How valid is $ {$foo} ? (Mark Jason Dominus)
    Re: How valid is $ {$foo} ? <ddunham@redwood.taos.com>
        html link on perl created dynamic webpage davidmonroe@my-deja.com
    Re: Internal counter required: was" Counting elements i (Anno Siegel)
    Re: Is Number of Params Limited? *Warning Newbie* <jamas@mindspring.com>
    Re: Is Number of Params Limited? *Warning Newbie* <callgirl@la.znet.com>
        More efficient than split? whubley@my-deja.com
    Re: More efficient than split? (Mark Jason Dominus)
        Perl 5.6 - line oriented quoting with "print" function? <dennis.moreno@pop.safetran.com>
    Re: perl editors <kperrier@blkbox.com>
    Re: perl editors <jdf@pobox.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 26 Jan 2001 11:38:02 -0600
From: "nesta" <nesta@psi.com.mx>
Subject: Basic string question 
Message-Id: <t73d7agp5g0f61@corp.supernews.com>

Hi Everybody

Is there a way to divide a string in letters and put each element into an
array ?

I know there is, but i wan to do it in a single line or maybe using built-in
functions.

I'm tried the next:

$string = "something "
@array = split (/\w/,$string);

but @array always is empty.

Any tip will be helpful, thanks in advance !!!





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

Date: Fri, 26 Jan 2001 10:21:51 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Basic string question 
Message-Id: <3a71c03f$1@news.microsoft.com>

"nesta" <nesta@psi.com.mx> wrote in message
news:t73d7agp5g0f61@corp.supernews.com...
> Hi Everybody
>
> Is there a way to divide a string in letters and put each element into an
> array ?
>
> I know there is, but i wan to do it in a single line or maybe using
built-in
> functions.
>
> I'm tried the next:
>
> $string = "something "
> @array = split (/\w/,$string);
>
> but @array always is empty.

Right idea, wrong parameter.
\w splits at each character (and of course the separator (=character) is
removed, too)
You want to split at nothing:
    split(//,$string);

jue




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

Date: 26 Jan 2001 13:10:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Basic string question
Message-Id: <ofwuqj4o.fsf@pobox.com>

"nesta" <nesta@psi.com.mx> writes:

> Is there a way to divide a string in letters and put each element
> into an array ?

If you look again at the documentation for split(), you will find your
question answered there.  Read it carefully.  HTH.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Fri, 26 Jan 2001 10:13:02 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Basic string question
Message-Id: <3A71BE2E.54DE5970@stomp.stomp.tokyo>

nesta wrote:

> Is there a way to divide a string in letters and 
> put each element into an array ?

> I'm tried the next:
 
> $string = "something "
> @array = split (/\w/,$string);
 
> but @array always is empty.
 
Remove your '\w' from your split.

@Array = split (//, $string);

You may test this in two ways.
Issue a print command and enclose
your @Array in quotes, to maintain
spaces between elements:

print "@Array";

This will print:

s o m e t h i n g  <-- two trailing spaces

A print command for an array without
quotes will not have spaces, unless
spaces are included in your elements:

print @Array;

This will print:

something <-- one trailing space

You will have a trailing space for
each print because your string
includes this trailing space.

You will enjoy better luck with splits
if you are precise and exact with your
split delimiter. In this case, odd as
this sounds, you are splitting on nothing.
This should raise a few eyebrows.

Do work at avoiding regex like expressions
for a split and focus on exacting delimiters
for better reliability and fewer failures.

Godzilla!


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

Date: 26 Jan 2001 18:14:41 +0000
From: nobull@mail.com
Subject: Re: Basic string question
Message-Id: <u9vgr2faem.fsf@wcl-l.bham.ac.uk>

"nesta" <nesta@psi.com.mx> writes:

> Subject: Basic string question

Before you post always ask youself this question: "If I came to this
newgroup and saw a thread with the subject line I'm about to post
would I know it was the same question?".  If the answer is "no" then
revise your subject line.  Repeat until you can answer the question
"yes" or until you are _sure_ it is beyond your capabilities to make
the answer yes. 

Subject: Split string into array of characters

There you see?  How much work would that have been?  Are you really
claiming you could not have come up with that?

> Hi Everybody

Grrr....  you probably should avoid this.  Saying "Hi Everybody" adds
to the impression that an idea just poped into your head and you and
decided to share it with us without giving the matter any thought.

> Is there a way to divide a string in letters and put each element into an
> array ?

Yes.
 
> I know there is, but i wan to do it in a single line or maybe using built-in
> functions.

Take a guess at which builtin function may do it.  Read the manual
entry for that function.  If you guessed right one of the examples
will show you how to do it.

> I'm tried the next:
> 
> $string = "something "
> @array = split (/\w/,$string);

That's not what the example in the manpage says to do, now, is it?

> but @array always is empty.

No it is not.  @array = ( '','','','','','','','','',' ' ) which are
the bits that appear _between_ the word characters in $string.  That's
what you asked for!  For details RTFM.

> Any tip will be helpful,

Read manuals.
Make sure of your facts.
Put a lot of effort into your subject lines.

> thanks in advance !!!

If you are going to do anything "in advance" it should be RTFM.

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


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

Date: 26 Jan 2001 17:00:08 GMT
From: nickco3@yahoo.co.uk (Nick Condon)
Subject: Re: Comparing multiple values
Message-Id: <9035AF12FNickCondon@132.146.16.23>

abigail@foad.org (Abigail) wrote in
<slrn972idl.q5.abigail@tsathoggua.rlyeh.net>: 

>Craig Berry (cberry@cinenet.net) wrote on MMDCCIV September MCMXCIII in
><URL:news:t719n74kcfuv79@corp.supernews.com>:
>'' datastar@my-deja.com wrote:
>'' : I can say:
>'' : 
>'' :   if ($somevar==3) {  } # do something
>'' : 
>'' : ...but what if I want to test if $somevar equals 3,4,8 or 9?
>'' 
>''   if (grep { $_ == $somevar } qw(3 4 8 9)) {
>'' 
>
>    unless ($x ** 4 - 24 * $x ** 3 + 203 * $x ** 2 - 708 * $x + 864) {
>    ... } 
>
>which can be optimized to:
>
>    unless (((($x - 24) * $x + 203) * $x - 708) * $x + 864) { ... }

LOL!

You've got way too much time on your hands.


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

Date: 26 Jan 2001 12:12:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Comparing multiple values
Message-Id: <m3ofwunsoi.fsf@mumonkan.sunstarsys.com>

nickco3@yahoo.co.uk (Nick Condon) writes:

> abigail@foad.org (Abigail) wrote in
> <slrn972idl.q5.abigail@tsathoggua.rlyeh.net>: 
> 
> >Craig Berry (cberry@cinenet.net) wrote on MMDCCIV September MCMXCIII in
> ><URL:news:t719n74kcfuv79@corp.supernews.com>:
> >'' datastar@my-deja.com wrote:
> >'' : I can say:
> >'' : 
> >'' :   if ($somevar==3) {  } # do something
> >'' : 
> >'' : ...but what if I want to test if $somevar equals 3,4,8 or 9?
> >'' 
> >''   if (grep { $_ == $somevar } qw(3 4 8 9)) {
> >'' 
> >
> >    unless ($x ** 4 - 24 * $x ** 3 + 203 * $x ** 2 - 708 * $x + 864) {
> >    ... } 
> >
> >which can be optimized to:
> >
> >    unless (((($x - 24) * $x + 203) * $x - 708) * $x + 864) { ... }
> 
> LOL!
> 
> You've got way too much time on your hands.

Is it really that hard to factor (x-3)(x-4)(x-8)(x-9) ?

Besides, the more relevant issue is the optimized version,
since that displays the standard technique for evaluating 
polynomials efficiently via computer.

See section 5.3 of _Numerical Recipes in C_ for details.

-- 
Joe Schaefer


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

Date: Fri, 26 Jan 2001 15:26:14 GMT
From: hparks@my-deja.com
Subject: Re: Dealing with x1b character
Message-Id: <94s4u8$qjj$1@nnrp1.deja.com>

One important correction: the character that is causing me trouble is a
hex 1A, not 1B, which explains why the file read stops, I think. But
the problem remains.


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


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

Date: Fri, 26 Jan 2001 15:35:33 GMT
From: hparks@my-deja.com
Subject: Re: Dealing with x1b character
Message-Id: <94s5g5$r5a$1@nnrp1.deja.com>

In article <3a70e03e.2509$3e5@news.op.net>,
  mjd@plover.com (Mark Jason Dominus) wrote:
>
> In article <94q8le$952$1@nnrp1.deja.com>,  <hparks@my-deja.com> wrote:
>
> >Some debugging showed the program was exiting when an escape
> >character (hex 1B) was encountered.
>
> Are you sure the character was 1B?   Windows file reads normally exit
> when they encounter character 1A, not 1B.

You are exactly right.  It's not a 1B but a 1A in the file...I need to
go back to school and relearn hex arithmetic.  And that does explain
why the file read stops.  Can I tell perl to keep reading past a 1A?


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


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

Date: Fri, 26 Jan 2001 16:08:35 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Dealing with x1b character
Message-Id: <3a71a102.3b2b$2b6@news.op.net>
Keywords: Berlioz, heritable, salmon, wakeup


In article <94s5g5$r5a$1@nnrp1.deja.com>,  <hparks@my-deja.com> wrote:
>
>You are exactly right.  It's not a 1B but a 1A in the file...I need to
>go back to school and relearn hex arithmetic.  And that does explain
>why the file read stops.  Can I tell perl to keep reading past a 1A?

Great stars, didn't you read my message?  And having asked which part
of the manual to read, didn't you read the part I suggested that you read?

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 26 Jan 2001 10:14:16 -0600
From: Chris Green <cmg@uab.edu>
Subject: FAQ Bug? split problems
Message-Id: <m2u26mffzb.fsf@phosphorus.tucc.uab.edu>

I'm interested in splitting a string like

$text = 'this, is, a, pain, to, "parse ,correctly"';

Using the code from perldoc -q split, I get:
This is the regex output:
this
 is
 a
 pain
 to
 "parse 
correctly"

This is the ParseWords output:
this
 is
 a
 pain
 to
 parse ,correctly

I Can live with the ParseWords Output but I believe the re from the
FAQ has a bug. $text = 'a, "parse, correctly"; doesn't

Here's the code I'm using under perl 5.6.0

$text = 'this, is, a, pain, to, "parse ,correctly"';
my @new = ();
# comment removed for newsgroup posting.
push(@new, $+) while $text =~ m{
				"([^\"\\]*(?:\\.[^\"\\]*)*)",?
				| ([^,]+),?
				| ,
			       }gx;
push(@new, undef) if substr($text,-1,1) eq ',';
print "This is the regex output:\n";
foreach $i (@new) {
    print "$i\n";
}

@new = quotewords(",",0,$text);

print "\n\nThis is the ParseWords output:\n";
foreach $i (@new) {
    print "$i\n";
}

-- 
Chris Green <cmg@uab.edu>


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

Date: 26 Jan 2001 17:05:41 +0100
From: jan@willamowius.de (Jan Willamowius)
Subject: Finding unused variables ?
Message-Id: <94s78l$7ub$1@janhh.willamowius.de>

I'm looking for a tool that finds unused variables.

I have to maintain some old code where sombody put in
a number of variables that are only used in my declarations
and others that are only written to, but never read from.

Is there a tool that can detect any of those 2 categories ?

Thanks,
	Jan

-- 
Jan Willamowius, jan@willamowius.de, http://www.willamowius.de/
Caution: Penguin Inside !


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

Date: 26 Jan 2001 14:09:28 GMT
From: "John Michael" <johnm@acadiacom.net>
Subject: First time user needs database help.
Message-Id: <94s0eo$9uj@dispatch.concentric.net>

I am attempting to create and work with my first database.  I have the book:
Programming the Perl DBI.
They give an example of how to open a database and get a lock under locking
strategies on page 34.
Here is part of the code:
use strict;
use Fcntl;
use AnyDBM_File;
############################################################
sub work_database {
my $flags = O_CREAT | O_RDWR;
my $ex_lock = "LOCK_EX";
my $file_name = "data/collected";
my %addy;
my $db = tie(%addy, 'AnyDBM_File', $file_name , $flags, 0666) ||
&error('database_initialize_error',$file_name);
my $fd = $db->fd();
## THIS IS LINE 128
OPEN DATAFILE, "+<&=$fd" || &error('database_open_error',$file_name);
flock(DATAFILE, $ex_lock);
if ($addy{$VAR{'address'}}){
        &error('already_exist');
}else{
        my $time_ends = $VAR{'expire'}*24*60*60 + $VAR{'time_now'};
        $addy{$VAR{'address'}} =
"$VAR{'address'}|VAR{'username'}|VAR{'password'}|$VAR{'time_now'}|$time_ends
";
}
undef $db;
untie(%addy);
close DATAFILE;
} ##End Sub
#############################################################
I'm getting this error
Can't locate object method "fd" via package "AnyDBM_File" at
/home/usr2/johnm/realtimescripts/cgi-bin/work/addco/free.pl line 128.
Thanks in advance.
John Michael






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

Date: Fri, 26 Jan 2001 16:30:00 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: First time user needs database help.
Message-Id: <cChc6.795$GF2.26450@eagle.america.net>

On 26 Jan 2001 14:09:28 GMT, John Michael <johnm@acadiacom.net> wrote:
>I am attempting to create and work with my first database.  I have
>the book: Programming the Perl DBI.
>
>They give an example of how to open a database and get a lock under
>locking strategies on page 34.
>Here is part of the code:
>use strict;
>use Fcntl;
>use AnyDBM_File;
     ^^^^^^^^^^^
It seems you took some liberties with the example.  See below.  

[snip]

>I'm getting this error
>Can't locate object method "fd" via package "AnyDBM_File" at
>/home/usr2/johnm/realtimescripts/cgi-bin/work/addco/free.pl line 128.

The fd() method is defined in the DB_File module -- not in whatever is
being used with AnyDBM_File (probably NDBM_File).  You need to install
DB_File and use it instead.  The example you cite does *not* use
AnyDBM_File; it uses DB_File.  

After you do that, you should also read the warning in the DB_File
manual page about why this method does *not* effectively lock a
DB_File database and use one of the alternatives that the DB_File
manual page recommends to avoid the race condition.  The example you
cite mentions this problem and gives reference to the work-around that
is documented in the DB_File manual page.  

If you want to lock an NDBM_File database, the easiest way to do it
would be to use another (empty) file to represent the database and
lock it before opening (tie'ing) the NDBM file and unlock it after
closing (untie'ing).  

-- 
Garry Williams


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

Date: Fri, 26 Jan 2001 09:23:05 -0500
From: "PaAnWa" <paul_wasilkoff@ucg.org>
Subject: Re: Form Processing - newbie question
Message-Id: <t7326i6m8inr0c@corp.supernews.com>

> >print FILE "\"$in{'check1'}\",";
> >print FILE "\"$in{'check2'}\",";
> >print FILE "\"$in{'check3'}\",";
> >print FILE "\"\","; #blank field
> >print FILE "\"\","; #blank field - this makes a total of 5 entries.
>
> for ($i = 1; $i < 6; $i++) {
>     print FILE '"', ($in{'check'.$i}) ? $in{'check'.$i} : '', '",';
> }

Thank you David.  This answers part of my question but I am still int he
dark as to how I should put the values into the counter in the first place.
The user has the choice of over 25 checkboxes but can choose up to 5 - any
5.

PAW




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

Date: Fri, 26 Jan 2001 17:05:43 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: HELP WANTED: perl ans oracle database
Message-Id: <3a71ae66.3cb7$5d@news.op.net>
Keywords: TWA, dummy, illusory, stubble


In article <3A700879.BED84139@enssat.fr>,
Millet Regis  <rmillet@enssat.fr> wrote:
>i'm trying to control an oracle database with perl under unix, but the
>execution gives me the the error message:
>
> install_driver(Oracle) failed: Can't load
>'/usr/local/lib/perl5/site_perl/5.005/alpha-dec_osf/auto/DBD/Oracle/Oracle.so'
>for module DBD::Oracle: dlopen: cannot load

You need to install the DBD::Oracle module.


Your program wants to talk to Oracle through DBI.  But DBI does not
know how to talk to Oracle.  DBI expecets to talk to DBD::Oracle, and
DBD::Oracle will talk to Oracle.  But you have not installed
DBD::Oracle.

See http://www.perl.com/pub/1999/10/DBI.html for more details.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 26 Jan 2001 10:13:11 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: How to close a socket on inactivity ?
Message-Id: <7l3is5x4.fsf@pobox.com>

jfn@dassic.com writes:

> How do I tell Perl to close a (open) socket after a given time of
> inactivity ?

The FAQ that comes up when you do 

   perldoc -q timeout

might be exactly what you're looking for.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Fri, 26 Jan 2001 16:19:43 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <3a71a39e.3b7b$249@news.op.net>
Keywords: Madonna, amide, ball, compunction


In article <slrn972p01.q5.abigail@tsathoggua.rlyeh.net>,
Abigail <abigail@foad.org> wrote:
>It's an old, undocumented relic from ancient times.

That's what I thought, but I looked, and wasn't able to find anything
analogous even as recently as perl 4.0.  Perhaps I missed something?

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 26 Jan 2001 17:50:36 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: How valid is $ {$foo} ?
Message-Id: <MNic6.16$bB4.16527@news.pacbell.net>

Roel de Cock <rdecock@kub.nl.spam.spam.spam> wrote:
> Hi,

> The indirect-construction

>   print ${$foo};

> confuses indentation and brace matching in the perl-mode of Emacs,
> obviously because it thinks ${ is a variable. I therefore tried an
> extra space:

Have you tried cperl-mode?  It's much better at guessing perl syntax
than perl-mode.

I tried your example and it appeared to understand it properly (where
perl-mode did not).

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >


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

Date: Fri, 26 Jan 2001 18:30:53 GMT
From: davidmonroe@my-deja.com
Subject: html link on perl created dynamic webpage
Message-Id: <94sfou$5dn$1@nnrp1.deja.com>

I'm new to Perl and am having difficulty putting a link in a page that was
generated by a Perl script.  This is what I have and it does not work.

print "\n<a href="http://www.atgl.spear.navy.mil/feedback/trnofmod.htm">View
your submission here</a><br>";

Any help would be greatly appreciated.

Dave



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


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

Date: 26 Jan 2001 15:13:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Internal counter required: was" Counting elements in an array (foreach)"
Message-Id: <94s466$ncm$1@mamenchi.zrz.TU-Berlin.DE>

Jerry Pank <me@jp1.co.uk> wrote in comp.lang.perl.misc:
>>                                                            ...or you
>> want to know whether there's an internal counter which you could access
>> to find out which element of an array a loop is currently on. So which
>> is it?
>
>Doh. Number three please!

Okay... it really wasn't quite clear.

This has been discussed before, and it is generally agreed this would
occasionally be useful.  There is even a Perl variable whose name, $#,
fits just fine.  In its former function it was used to contain the
output format for numbers, but AFAIK it doesn't even work these days.
In any case it has been deprecated for ages in favor of printf.

$# is a perfect candidate to hold (read-only) the index to the current
element in a foreach over a list.  While it is not really needed
(we can all count ourselves, can't we), it would allow the "Perlish"
foreach more freely in situations where you also want an index, for
peeking ahead, or to access a parallel array, for instance.

While this was pretty much agreed upon (I will be corrected if I'm
wrong), all that remains to do is convince Larry and the Guys that
it's a good thing and write the patch.  Or propose it for Perl 6,
which, I'm sure, has been done.

Anno


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

Date: Fri, 26 Jan 2001 10:47:17 -0500
From: Max <jamas@mindspring.com>
Subject: Re: Is Number of Params Limited? *Warning Newbie*
Message-Id: <3A719C05.F34DE47D@mindspring.com>



Kira wrote:

> Max wrote:
>
> (some snippage)
>
> > After read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> > And spliting $buffer into %pairs
>
> > Is there a limit to the number of  elements in %pairs ?
>
> > My form is suppose to return 9 products, but only returns 7
>
> Do yourself a favor and post your home-grown
> read and parse routine. Either you have a
> problem with your routine or you are only
> receiving seven key/value pairs from your
> form action. It would help, as well, to give
> a * brief * description of your form action.
>
> Post your code so people can look it over.
>
> Godzilla!

Let me digress,

There are four Html forms that would call the script.
Each of these Html pages are created by a WinBatch program
so except for the spelling of name/values, and the number of
name/values, the html scripts are identical.

Each form has x number of products, range (2 - 9).

Both the Chemical and the Equipment have nine products.

The Chemical page returns 7 pairs of products, the Equipment 9.
The other pages return the correct number of product pairs.

To see what is happening, goto:

"http://www.thepoolcompany.net"

Click Product, then one of the catalog tabs.
(chemicals is the big B.)

Use the "Check Out" button to see script test results.
 .........................
misc. info:

HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Fri, 26 Jan 2001 14:59:28 GMT
Content-type: text/html

Begin Script- - - - - - - - - -  - - - |

#!/usr/bin/perl -w
use CGI   qw/:standard :html3/;
use diagnostics;

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;
        $NewUser{$name} = $value;
        }

$addcheck="";
$trash="";
while ( ($key, $value) = each(%NewUser) ) {
      $trash=$key;
      if ( $value eq "Check Out"  ) {  $addcheck="CO" ; }
      if ( $value eq "Add to Cart") {  $addcheck="AD" ; }
      }

if ( $addcheck eq "AD") {  addtocart(); }
if ( $addcheck eq "CO") {  checkout() ; }
exit;

sub checkout
{
$itm="";
@tpid = () ;
@pid = () ;
$trash="";

while (($tkey, $tvalue) =  each(%NewUser))  {
       $trash=$tkey;
       $itm=$trash;
       $test="";
       $test= substr($tkey, 0, 8);
       push(@tpid, "$tvalue $tkey") ;
       if ( $test eq "Prod_id_") { push(@pid, "$tvalue $tkey"); }
       }

print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>WWW_CLUB</TITLE></HEAD>\n";
print "<BODY>\n";
print "<h2>Check Out</h2>";
print "$#pid \n<br>";
for( $i= 0; $i <= $#pid; $i++){
    print " $i = $pid[$i]\n<br>";
   }

print "$#pid \n<br>";
for( $i= 0; $i <= $#tpid; $i++){
    print " $i = $tpid[$i]\n<br>";
   }

print "</BODY></HTML>\n";
exit;
}

sub addtocart
{
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>WWW_CLUB</TITLE></HEAD>\n";
print "<BODY>\n";
print "<h2>Add To Cart</h2>";
print "</BODY></HTML>\n";
exit;
}
exit;
END SCRIPT- - - - - - - - - - - - -  - -


--
CGI, ASP,  PHP, Oh' my,
CGI, ASP,  PHP, Oh' my
John M. Smith




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

Date: Fri, 26 Jan 2001 08:41:18 -0800
From: Kira <callgirl@la.znet.com>
Subject: Re: Is Number of Params Limited? *Warning Newbie*
Message-Id: <3A71A8AE.7814AE82@la.znet.com>

Max wrote:
 
> Kira wrote:
> > Max wrote:

> > (some snippage)

(more various snippage)

> > > After read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> > > And spliting $buffer into %pairs

> > > Is there a limit to the number of  elements in %pairs ?

> > > My form is suppose to return 9 products, but only returns 7

> > Do yourself a favor and post your home-grown
> > read and parse routine. Either you have a
> > problem with your routine or you are only
> > receiving seven key/value pairs from your
> > form action. It would help, as well, to give
> > a * brief * description of your form action.

> There are four Html forms that would call the script.
 
> Each form has x number of products, range (2 - 9).
 
> Both the Chemical and the Equipment have nine products.
 
> The Chemical page returns 7 pairs of products, the Equipment 9.
> The other pages return the correct number of product pairs.

> To see what is happening, goto:
 
> "http://www.thepoolcompany.net"
 
I will treat this issue as html, not Perl. Your
document source for chemicals, the only page I 
examined, is a mess and barely readable. You have
nine products listed but two products are each,
duplicated in your html coding. You actually only
have seven products, not nine, thus seven key/value
pairs would be returned, not nine as you expect.

More technical, nine potential returns, but
two pairs of key/value pairs are duplicated
thus your program 'sees' only seven products
which are 'different' from each other.

Your html code is consistently in error as
well, noted by this snippet:

"$75.<u><sup>.99</sup></u>">

Look at your code following that snippet
and you will note your error.

So, you have a product page which is not coded
correctly for actual number of products and,
your html code contains syntax errors.

My suggestion is you repair your html coding for
your product listings, test, and discover if you
don't have better luck, then clean up your
document source print so it is legible.

Godzilla!


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

Date: Fri, 26 Jan 2001 16:13:38 GMT
From: whubley@my-deja.com
Subject: More efficient than split?
Message-Id: <94s7n8$tbm$1@nnrp1.deja.com>

From what I read, split is not very efficient.  Is there a more
efficient substitution for split when parsing values from pipe-
delimited string of text?

If:

$line = “45345|test|43234|testdomain”;

Currently I use:

@array = split (/\|/, $line);

I have heard that I can use unpack, but have failed at all attempts to
do so.

Thank you.


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


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

Date: Fri, 26 Jan 2001 16:46:53 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: More efficient than split?
Message-Id: <3a71a9fd.3c46$f5@news.op.net>
Keywords: myocardial, oersted, pour, sly


In article <94s7n8$tbm$1@nnrp1.deja.com>,  <whubley@my-deja.com> wrote:
>From what I read, split is not very efficient.  

Split is extremely efficient, in the sense that it would be very
difficult to construct an equivalent function that would be faster.
You have either misunderstood or been deceived.  'unpack' is only
suitable when the fields have the same width in each record.

>Is there a more efficient substitution for split when parsing values
>from pipe- delimited string of text?

Short of a hand-coded special-purpose routine in C, probably not.
Even that might not win.

What exactly is the problem here?  Is your program running too slowly?
Is the problem really coming from your use of 'split'?  If not, I
suggest that you are worrying about performance at too low a level.

>I have heard that I can use unpack, but have failed at all attempts to
>do so.

Now, let's suppose you have spent an hour attempting to use 'unpack'.
Let's suppose that you found a way to split the line that was twice as
fast as using 'split'.  

An hour is 3600 seconds.  My slow, obsolete P233 system performs
25,600 splits per second; in one hour it will split the line 92
million times.

If your data file contains 100,000 records, your program spends about
3.9 seconds splitting.  With the hypothetical twice as fast method,
you will save 1.45 seconds in each run of your program.  

You spent 3600 seconds finding the fast method.  3600 / 1.45 is 2482.
You will have to run your program 2482 times just to break even.  Of
course, you really won't break even, because an hour of the computer's
time is worth a lot less than an hour of your time.

Hope this helps.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 26 Jan 2001 18:28:04 GMT
From: dennis <dennis.moreno@pop.safetran.com>
Subject: Perl 5.6 - line oriented quoting with "print" function?
Message-Id: <3A71C1AC.66EAD174@pop.safetran.com>

Can any tell me if anything is wrong with this code?
My debugger keep indicating a syntax error and that
I need a semicolon at the end of lines 33-36.

31 # Output the mail header
32 print (MAIL <<"EOMH");
33 Reply-to: $from 
34 From: $from
35 To: $TO
36 Subject: $SUBJECT
37 EOMH

Thanks
Dennis


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

Date: 26 Jan 2001 08:29:18 -0600
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: perl editors
Message-Id: <67A1456DABB82566.5FE2C61BC651EC0F.6734CAED6F8CE386@lp.airnews.net>

hanja <hanja@my-deja.com> writes:

> Out of curiousity, what editor do you use to write your scripts?

echo "<perlcode>" > filename

Of course editing the script to debug it is a bit hard....

Kent
-- 
'In God we trust -- all others we polygraph.' 

            -- Jim Christy,
               special assistant for law enforcement, U.S. Air Force


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

Date: 26 Jan 2001 10:15:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: perl editors
Message-Id: <3de6s5ss.fsf@pobox.com>

Kent Perrier <kperrier@blkbox.com> writes:

> Of course editing the script to debug it is a bit hard....

That's what perl -pei is for.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

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


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