[17989] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 149 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 09:05:43 2001

Date: Fri, 26 Jan 2001 06:05:10 -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: <980517910-v10-i149@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
    Re: Any suggestions on how to improve this  script? <ccx138@coventry.ac.uk>
    Re: Comparing multiple values <tore@extend.no>
    Re: Comparing multiple values (Bernard El-Hagin)
    Re: Comparing multiple values (Martien Verbruggen)
    Re: Comparing multiple values <bart.lateur@skynet.be>
    Re: Comparing multiple values <tore@extend.no>
    Re: Comparing multiple values (Anno Siegel)
        DBI: row count problem matt@bomb.co.uk
    Re: DBI: row count problem (Rafael Garcia-Suarez)
        How to close a socket on inactivity ? jfn@dassic.com
        How valid is $ {$foo} ? (Roel de Cock)
    Re: How valid is $ {$foo} ? (Anno Siegel)
    Re: How valid is $ {$foo} ? (Abigail)
    Re: How valid is $ {$foo} ? (Martien Verbruggen)
    Re: How valid is $ {$foo} ? (Roel de Cock)
        Install of Perl 5.6 fraikin@my-deja.com
    Re: Is this the BEST way ? <drifter@clix.pt>
        newbie <rbalajitmr@my-deja.com>
        passing params to cgi prog using POST <stevie_d38nospam@hotmail.com>
    Re: regexpr as condition (Anno Siegel)
    Re: right place for a mod_perl question? (Anno Siegel)
    Re: Script to "rotate" the chars in a string. (Abigail)
    Re: Script to "rotate" the chars in a string. <Jerome.Abela@free.fr>
    Re: Upgrading to Perl 5.6 under Debian 2.2 <pking123@sympatico.ca>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 26 Jan 2001 11:06:37 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: Any suggestions on how to improve this  script?
Message-Id: <3A715A3D.EC687EF3@coventry.ac.uk>

My main point was not to write any thing that was exponential or quadratic
because binary speaking, i.e. good or bad,  they are not good.  They are both
bad, one is more bad than the other.

Linear is best, in that it will take a proportionate amount of time no matter how
many lines there are in each file, the overall run time would plot a straight
line on a graph.  The other methods shot the line off the top of the scale very
quickly.  This has nothing to do with the power of the cpu.
It is the simple way the a hash table has a Big O of 1 to search for a match, a
binary tree has log n and a sequential search has N.
Which was my many point.

Relying on the power of the cpu is a Microsoft (sorry about swearing) solution it
is bad programming (hacking).

Mark Jason Dominus wrote:

> In article <3A6EEC21.AFE34F01@coventry.ac.uk>,
> John Tutchings  <ccx138@coventry.ac.uk> wrote:
> >OK, what ever, it is still bad which ever way :)
>
> It makes a big difference.  Suppose that the largest file you can
> handle practically has a certain number of lines.  Then you buy a new
> computer that is twice as fast as the old computer.
>
> If the program has quadratic behavior, it will be practical to handle
> files that are up to 50% larger than the old files.
>
> If the program has exponential behavior, it will be practical to
> handle files that are up to 3 lines larger than the old files.
>
> Exponential is much, much worse than quadratic.
>
> --
> @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 12:42:34 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Comparing multiple values
Message-Id: <MPG.14db811482cf90a7989866@news.online.no>

In article <b5b17tg9bc5eus0ch30u2lvg1brdv5jkqn@4ax.com>, 
bart.lateur@skynet.be says...
>> if ($number =~ /[1|2|3|4]/) {

> Are you guys blind, or just plain lazy? The OP explicitely wrote:
> [...]

But this *is* simplicity. :)  I had an error in my regexp, by the way.  
Should have been something like;

  if ($number =~ /^[1|2|3|4]$/) {
  }

Still, this matches '|', so you should probably check if $number really 
is a number as well.


-- 
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/


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

Date: Fri, 26 Jan 2001 11:53:08 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Comparing multiple values
Message-Id: <slrn972p7l.2q0.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 26 Jan 2001 12:42:34 +0100, Tore Aursand <tore@extend.no> wrote:
>In article <b5b17tg9bc5eus0ch30u2lvg1brdv5jkqn@4ax.com>, 
>bart.lateur@skynet.be says...
>>> if ($number =~ /[1|2|3|4]/) {
>
>> Are you guys blind, or just plain lazy? The OP explicitely wrote:
>> [...]
>
>But this *is* simplicity. :)  I had an error in my regexp, by the way.  
>Should have been something like;
>
>  if ($number =~ /^[1|2|3|4]$/) {
>  }
>
>Still, this matches '|', so you should probably check if $number really 
>is a number as well.

Both your regex and your comment to your regex are mindnumbingly inane.
Please read about character classes in:

perldoc perlre

and stop this insanity.

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


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

Date: Fri, 26 Jan 2001 23:11:05 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Comparing multiple values
Message-Id: <slrn972qap.tip.mgjv@martien.heliotrope.home>

On Fri, 26 Jan 2001 12:42:34 +0100,
	Tore Aursand <tore@extend.no> wrote:
> 
>   if ($number =~ /^[1|2|3|4]$/) {
>   }
> 
> Still, this matches '|', so you should probably check if $number really 
> is a number as well.

Euhmmm.. WOuldn't a simpler solution be to just leave out the '|' ? Or
to use one of the other solutions presented?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: Fri, 26 Jan 2001 12:43:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Comparing multiple values
Message-Id: <i7s27tooitamfdjo1j1s77adc4eqake02n@4ax.com>

Martien Verbruggen wrote:

>>   if ($number =~ /^[1|2|3|4]$/) {
>>   }
>> 
>> Still, this matches '|', so you should probably check if $number really 
>> is a number as well.
>
>Euhmmm.. WOuldn't a simpler solution be to just leave out the '|' ?

Replacing the square brackets with normal parens, that's the ticket.
Unless you want to be stuck with one character test strings forever.

-- 
	Bart.


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

Date: Fri, 26 Jan 2001 13:56:04 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Comparing multiple values
Message-Id: <MPG.14db924b9813217c989867@news.online.no>

In article <slrn972p7l.2q0.bernard.el-hagin@gdndev25.lido-tech>, 
bernard.el-hagin@lido-tech.net says...
> Both your regex and your comment to your regex are mindnumbingly
> inane.  Please read about character classes in:
> [...]

This example was nothing but just that - an example.  And I've already 
told the OP that he/she should read 'perlre' for more information.

My whole point was that it's completely unnecessary to use 'if-else' 
statements on this type of task.


-- 
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/


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

Date: 26 Jan 2001 13:04:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Comparing multiple values
Message-Id: <94rsle$omq$1@mamenchi.zrz.TU-Berlin.DE>

Tore Aursand  <tore@extend.no> wrote in comp.lang.perl.misc:
>In article <slrn972p7l.2q0.bernard.el-hagin@gdndev25.lido-tech>, 
>bernard.el-hagin@lido-tech.net says...
>> Both your regex and your comment to your regex are mindnumbingly
>> inane.  Please read about character classes in:
>> [...]
>
>This example was nothing but just that - an example.  And I've already 
>told the OP that he/she should read 'perlre' for more information.

An example for what?  All your example shows is you don't understand
regexes properly.

My whole point was that it's completely unnecessary to use 'if-else' 
>statements on this type of task.

It is true that you can avoid "if" in this problem.  Your "example"
doesn't show that, nor is it clear that "if" *should* be avoided.

Anno


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

Date: Fri, 26 Jan 2001 13:36:53 GMT
From: matt@bomb.co.uk
Subject: DBI: row count problem
Message-Id: <94ruhk$kl9$1@nnrp1.deja.com>

Hi All,
I've been trying to get a row count from a query..
and each time I get -1.. instead of the row count
expected. Can anyone please help tah.

------------------------------------------------------------
$string =~ s/'/''/g;
my $csr = $dbh->prepare("SELECT searchstring
                         FROM search_summary
                         WHERE searchstring = ?")
or die "Couldn't prepare statement: " . $dbh->errstr;

$csr->execute($string);
print $csr->rows."\n";
------------------------------------------------------------

I'm quite newbie .. and I might be missing the obvious.
bye
Matt.


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


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

Date: Fri, 26 Jan 2001 14:03:52 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: DBI: row count problem
Message-Id: <slrn9730v9.koa.rgarciasuarez@rafael.kazibao.net>

matt@bomb.co.uk wrote in comp.lang.perl.misc:
> Hi All,
> I've been trying to get a row count from a query..
> and each time I get -1.. instead of the row count
> expected. Can anyone please help tah.
> 
> ------------------------------------------------------------
> $string =~ s/'/''/g;
> my $csr = $dbh->prepare("SELECT searchstring
>                          FROM search_summary
>                          WHERE searchstring = ?")
> or die "Couldn't prepare statement: " . $dbh->errstr;
> 
> $csr->execute($string);

You should put a "or die" after the execute (unless you
connected to the DB with RaiseError => 1).

> print $csr->rows."\n";

Read more carefully the DBI manpage:

  'rows'
      $rv = $sth->rows;

    Returns the number of rows affected by the last row
    affecting command, or -1 if the number of rows is not
    known or not available.

    Generally, you can only rely on a row count after a
    non-`SELECT' `execute' (for some specific operations
    like `UPDATE' and `DELETE'), or after fetching all the
    rows of a `SELECT' statement.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 26 Jan 2001 12:45:15 GMT
From: jfn@dassic.com
Subject: How to close a socket on inactivity ?
Message-Id: <94rrgp$i34$1@nnrp1.deja.com>

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

 ...is it built into the Socket support, or is it something that has to
be done using a seperate timer (thread) that monitors the time since
the last input and closes the socket after a given number of seconds ?

I need it for a small tcp client that takes something on stdin and
transfer it to a server script. I only have input for about 2 seconds
every 5 minutes, so I'd prefer to have the socket open only for those
two seconds, and I can't base the close on the content on stdin, so it
has to be a solution that works with any input.


l8r/Jspr


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


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

Date: Fri, 26 Jan 2001 11:23:35 GMT
From: rdecock@kub.nl.spam.spam.spam (Roel de Cock)
Subject: How valid is $ {$foo} ?
Message-Id: <3a725d52.918244594@mailnews.kub.nl>

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:

  print $ {$foo};

and this works fine with Perl 5.005, but is that by design or by
chance? If it's not quite clean, is there a better solution?

Thx,

Roel



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

Date: 26 Jan 2001 11:47:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <94ro4h$mta$1@mamenchi.zrz.TU-Berlin.DE>

Roel de Cock <rdecock@kub.nl.spam.spam.spam> wrote in comp.lang.perl.misc:
>Hi,
>
>The indirect-construction
>
>  print ${$foo};

Let's hope you're not talking symrefs here...

>confuses indentation and brace matching in the perl-mode of Emacs,
>obviously because it thinks ${ is a variable. I therefore tried an
>extra space:
>
>  print $ {$foo};
>
>and this works fine with Perl 5.005, but is that by design or by
>chance? If it's not quite clean, is there a better solution?

Perl has tolerated spaces between a Funny Character and whatever
follows for quite a while.  The feature isn't documented, however,
and may go away in a future version.

The real solution is to switch off syntax highlighting, and your
example shows why.  What good is a highlighter when you have to help
it along (with dubious constructs, even) with your better under-
standing of the actual syntax?  How can you trust it when you don't
understand what's going on?

Anno


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

Date: 26 Jan 2001 11:48:17 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <slrn972p01.q5.abigail@tsathoggua.rlyeh.net>

Roel de Cock (rdecock@kub.nl.spam.spam.spam) wrote on MMDCCV September
MCMXCIII in <URL:news:3a725d52.918244594@mailnews.kub.nl>:
[] 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:
[] 
[]   print $ {$foo};
[] 
[] and this works fine with Perl 5.005, but is that by design or by
[] chance? If it's not quite clean, is there a better solution?


It's an old, undocumented relic from ancient times.

It may cease to work without any notice. It might not work on full moons.
Keep away from pets. 


As for the better solutions, about a nice vi clone?



Abigail
-- 
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
          q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'


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

Date: Fri, 26 Jan 2001 23:04:08 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <slrn972pto.tip.mgjv@martien.heliotrope.home>

On Fri, 26 Jan 2001 11:23:35 GMT,
	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:
> 
>   print $ {$foo};
> 
> and this works fine with Perl 5.005, but is that by design or by
> chance? If it's not quite clean, is there a better solution?

I am not entirely sure what your question is. It can't be about the
syntax matching of emacs, because then you would have posted to
some other newsgroup, so it must be about the syntax of Perl.

Are you aksing what ${$foo} is and why it works? Or are you asking why
you are allowed to put spaces in between parts of that? Or are you
asking whether the fact that you can put spaces in between is an
accident or design?

If you have strict off, then ${$foo} can be a symbolic reference. But
you don't need those, and shouldn't use those. If you think you do need
those, they're documented in perlref. Also documented there are hard
references, and the block syntax, albeit only marginally.

@{ ... } will evaluate ... as a block, and dereference the result of
that as an array reference. ${ ... } will do the same, but expect a
scalar reference.

If that's all known to you, and you're only interested in the fact that
whitespace is allowed there: Whitespace is allowed in many many places
in Perl, by design. There are only a few places where whitespace is
mandatory, and few places where it is disallowed. It isn't allowed in
the middle of tokens (variable names, keywords). It's mandatory in some
places where it could introduce ambiguity, or 

$ perl -wle '$foo="bar";print$foo'
bar
$ perl -wle '$foo = "bar"; print $ foo'
bar
$ perl -wl
$
foo
=
"bar" 
;
print
$
foo
__END__
bar

This is by design, but not really well documented, I believe.

The fact that emacs perl-mode and vim's syntax colouring don't deal with
this correctly is their problem. I quoted this a few days ago here as
well, and I'll just repeat it: Nothing can parse Perl but perl.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: Fri, 26 Jan 2001 13:47:09 GMT
From: rdecock@kub.nl.spam.spam.spam (Roel de Cock)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <3a747fdc.927087973@mailnews.kub.nl>

On 26 Jan 2001 11:47:29 GMT, my agent told me that
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> >The indirect-construction
> >
> >  print ${$foo};
> 
> Let's hope you're not talking symrefs here...

Looking it up in the Perl manpages, I think that's what Perlies call
it, yes. I don't think it's easy to avoid since this construction
appears inside an eval which gets user input from a file. No, I didn't
write it, just have to deal with it.

> The real solution is to switch off syntax highlighting, and your
> example shows why.  What good is a highlighter when you have to help
> it along (with dubious constructs, even) with your better under-
> standing of the actual syntax?  How can you trust it when you don't
> understand what's going on?

How can I trust a programming language interpreter to get it right if
even a fairly decent syntax highlighter can't?

Fact is that I'm saddled with 300 lines of code inside 1 function
block, of which the author didn't deem it necessary to indent or
whiteline too much. That's where the syntax highlighter/indenter comes
in: make it legible in the first place, before I decide to rewrite
anything at all.

Roel



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

Date: Fri, 26 Jan 2001 12:51:05 GMT
From: fraikin@my-deja.com
Subject: Install of Perl 5.6
Message-Id: <94rrrm$iem$1@nnrp1.deja.com>

I'm trying to install Perl 5.6 on my server Unix RM 400 with Sinix 5.44
of Siemens.
Actually I'm working with Perl 5.00404 (binary version)
After Configure with
sh Configure -des -Ubincompat. -Ud_bincompat3 -Dcc="cc -W0" \
             -Dprefix="/home/tools/perl6.6" \
             -Dlocincpth="/home/tools/perl6.6/include" \
             -Dloclibpth="/home/tools/perl6.6" \

I try < make > and receive an error

 ..............
	  CCCMD =  /bin/cc -DPERL_CORE -c -I/usr/include -
I/usr/ucbinclude -DLANGUAGE_C -O
	  CCCMD =  /bin/cc -DPERL_CORE -c -I/usr/include -
I/usr/ucbinclude -DLANGUAGE_C -O
	  CCCMD =  /bin/cc -DPERL_CORE -c -I/usr/include -
I/usr/ucbinclude -DLANGUAGE_C -O
	  CCCMD =  /bin/cc -DPERL_CORE -c -I/usr/include -
I/usr/ucbinclude -DLANGUAGE_C -O
	  CCCMD =   -c
cflags: /config.sh: not found

make: Fatal error.

What's wrong?

Francis

make: Fatal error.


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


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

Date: Fri, 26 Jan 2001 13:37:00 +0000
From: Matti =?iso-8859-1?Q?S=E4rkisilta?= <drifter@clix.pt>
Subject: Re: Is this the BEST way ?
Message-Id: <3A717D7C.43CE566C@clix.pt>


--------------F64669D36678282CC4B77879
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

>
> >     my $sth = $dbh->prepare("SELECT * FROM phone where number = '$_'");
>
> As Rafael mentioned, pull this out of the loop.  Unless the 'print
> "@row\n"' below is for more than debugging, you should really select only
> the fields you're going to use rather than all of them.
>
>  >     $sth->execute();
> > while (my @row = $sth->fetchrow_array) {
> >        print  "@row\n";
> >           my $number = shift @row;
> >                 my $first = shift @row;
> >                 my $last = shift @row;
> >          print "$number\n";
> >          print "$first\n";
> >          print "$last\n";
> >          }
> >     }
> >
>
> I'd use fetchrow_hashref and the actual field names here both to shorten
> your code and remove the needless dependency on the order and position of
> the fields.  Assuming the field names are NUMBER, FIRST, and LAST, you'd
> do something like:
>
> while (my $row = $sth->fetchrow_hashref) {
>   print "$row->{NUMBER}\n$row->{FIRST}\n$row->{LAST}\n";
> }

Also as I've used on mod_perl this works just as fine:
while (my $row = $sth->fetchrow_hashref) {
  print "$$row{'NUMBER'}\n$$row{'FIRST'}\n$$row{'LAST'}";
}

Though $row->{FIELD} is equal to $$row{FIELD}, IMHO it's simpler to write it
like that.

And depending on the number of fields, you could also use arrayref, ex:
while (my$row = $sth->fetchrow_arrayref) {
   print "$$row[0]\n$$row[1]\n$$row[2]";          # or maybe print
$$row[0..2]; <- never tried this tho ,)
}

also before disconnecting, do

$sth->finish;
$dbh->disconnect;

just to make sure that if you make multiple queries and your mysql server is
having even a bit of traffic it's always better to finish statements.

--
  _________________________________________
// Matti Särkisilta - www.prisma.pt/~drifter
@a=split((\d)/,"4Hacker2another3Perl1Just");
shift(@a);%a=@a;print "@a{1..4}";
\\________________________________________

--- Begin gek code ---
GIT/GCM d? s++:s-- a? C++++ UL+++ P++++ L++++ E--- W++ N-
o-- w--- O- M V PS+++ PE Y+ PGP++ t 5 X+ R+ tv-- b++ DI++
D++ G e++ h++ r* z**
--- End geek code ---



--------------F64669D36678282CC4B77879
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<blockquote TYPE=CITE>&nbsp;
<br>>&nbsp;&nbsp;&nbsp;&nbsp; my $sth = $dbh->prepare("SELECT * FROM phone
where number = '$_'");
<p>As Rafael mentioned, pull this out of the loop.&nbsp; Unless the 'print
<br>"@row\n"' below is for more than debugging, you should really select
only
<br>the fields you're going to use rather than all of them.
<p>&nbsp;>&nbsp;&nbsp;&nbsp;&nbsp; $sth->execute();
<br>> while (my @row = $sth->fetchrow_array) {
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print&nbsp; "@row\n";
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $number
= shift @row;
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
my $first = shift @row;
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
my $last = shift @row;
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "$number\n";
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "$first\n";
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "$last\n";
<br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>>&nbsp;&nbsp;&nbsp;&nbsp; }
<br>>
<p>I'd use fetchrow_hashref and the actual field names here both to shorten
<br>your code and remove the needless dependency on the order and position
of
<br>the fields.&nbsp; Assuming the field names are NUMBER, FIRST, and LAST,
you'd
<br>do something like:
<p>while (my $row = $sth->fetchrow_hashref) {
<br>&nbsp; print "$row->{NUMBER}\n$row->{FIRST}\n$row->{LAST}\n";
<br>}</blockquote>
Also as I've used on mod_perl this works just as fine:
<br>while (my $row =&nbsp;$sth->fetchrow_hashref) {
<br>&nbsp; print "$$row{'NUMBER'}\n$$row{'FIRST'}\n$$row{'LAST'}";
<br>}
<p>Though $row->{FIELD} is equal to $$row{FIELD}, IMHO it's simpler to
write it like that.
<p>And depending on the number of fields, you could also use arrayref,
ex:
<br>while (my$row =&nbsp;$sth->fetchrow_arrayref) {
<br>&nbsp;&nbsp; print "$$row[0]\n$$row[1]\n$$row[2]";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# or maybe print $$row[0..2]; &lt;- never tried this tho ,)
<br>}
<p>also before disconnecting, do
<p>$sth->finish;
<br>$dbh->disconnect;
<p>just to make sure that if you make multiple queries and your mysql server
is
<br>having even a bit of traffic it's always better to finish statements.
<pre>--&nbsp;
&nbsp; _________________________________________
// Matti S&auml;rkisilta - www.prisma.pt/~drifter
@a=split((\d)/,"4Hacker2another3Perl1Just");
shift(@a);%a=@a;print "@a{1..4}";
\\________________________________________

--- Begin gek code ---
GIT/GCM d? s++:s-- a? C++++ UL+++ P++++ L++++ E--- W++ N-
o-- w--- O- M V PS+++ PE Y+ PGP++ t 5 X+ R+ tv-- b++ DI++
D++ G e++ h++ r* z**
--- End geek code ---</pre>
&nbsp;</html>

--------------F64669D36678282CC4B77879--



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

Date: Fri, 26 Jan 2001 03:37:20 -0800
From: "Deja User" <rbalajitmr@my-deja.com>
To: comp.lang.perl.misc@list.deja.com
Subject: newbie
Message-Id: <200101261137.DAA27789@mail10.bigmailbox.com>

Hi there

I am Balaji from Cambridge, I am using perl for data conversion areas, could anyone explain me how to use perl for matching brackets.

e.g. \header{The aricle title \it{vs}}

Thanks in Advance

Balaji




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




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


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

Date: Fri, 26 Jan 2001 05:21:00 -0600
From: "StevieD" <stevie_d38nospam@hotmail.com>
Subject: passing params to cgi prog using POST
Message-Id: <03dc6.400$9o1.201891@nnrp3.sbc.net>

Hello -

Just gave up after 14 hours trying to call a perl .cgi prog and make it work
right from another perl script instead of the html form it normally starts
from.

Because a password is one of the form values i need to give it i don't want
to append it to the URL .... After much stabbing about in the dark, i've
used the HTTP::Request::Common and LWP::UserAgent mods to almost make it
work.

Only problem is, even tho the called script verifies a correct
username/password combo, it doesn't "stick" the way it does when called from
a regular form, giving a "Password Incorrect" response upon taking any
additional actions. This has something to do with after verifying the
password it writes a cookie using Javascript document.write.cookie then
moves to another [static] page using document.location ... There is
something different about receiving this via an HTTP::Response object than
"normal", or maybe because its a virtual browser doing the requesting? I am
clueless here and totally at a dead end, yet it seems like i'm so close.
Below is what i've come up with (as you can see i played around with trying
to let the called script's cookie-writing work, but the best i got was a
blank screen):
####################
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

print "Content-type: text/html\n\n";

$ua = LWP::UserAgent->new;

#use HTTP::Cookies;
#$cookie_jar = HTTP::Cookies->new;

my $req = POST 'http://www.mysite.com/cgi-bin/utils/repmgr.pl',
   [ username => $formdata{'repname'}, password => $formdata{'password'},
cgifunction => 'Crop Data Services', ];
$response = $ua->request($req);
#$response = $ua->request($req)->as_string;

#$ua->cookie_jar([$cookie_jar]);
#$cookie_jar->extract_cookies($response);

print $response->content;
########################

desperate to figure this out .... thanks for any help! If there is a totally
different approach that would work, would also be curious to find out ...

-Stevie D





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

Date: 26 Jan 2001 11:11:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexpr as condition
Message-Id: <94rm0g$k72$1@mamenchi.zrz.TU-Berlin.DE>

Hessu  <qvyht@iobox.fi> wrote in comp.lang.perl.misc:
>Newbie here wondering if this is possible
>Can I use regular expressions in loops or elsewhere like this:
>
>do block 0 or more times:
>*{ BLOCK } condition;
>*{ BLOCK }
>----------
>do block 1 or more times
>+{ BLOCK } condition (like do..while)
>----------
>do block 1 or 0 times
>?{ BLOCK } condition
>----------
>do block at least n and at most m times
>{n,m} { BLOCK }
>----------
>if block's result is true straight forward
>otherwise continue like block wasn't never
>done
>
>reset{BLOCK }

If you are asking if you can do that in current Perl it would have
been easier to try than to ask here.  The answer is no, of course.
Some of your construct will give you a syntax error while others
just don't do what you describe.

If the question is if these constructs would be desirable, the
answer is subjective.  The first four can be emulated using existing
constructs (a combination of while, last and possibly a counter
variable), though the usefulness of "{n,m} { BLOCK }" seems somewhat
doubtful.

reset{ BLOCK } simply can't be done the way you describe.  { BLOCK }
may have done irreversible things, from sending nasty email to
your mother-in-law to launching a missile to Shanghai.  It would
be nice if things could be undone as easily...

Anno


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

Date: 26 Jan 2001 13:45:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: right place for a mod_perl question?
Message-Id: <94rv1c$hm0$1@mamenchi.zrz.TU-Berlin.DE>

Daniel W. Burke <dwb1@home.com> wrote in comp.lang.perl.misc:

[snip Gary E. Ansok's good advice]

>It seems weird that mod_perl is passing the apache object to each script in
>@_, but if each script is called like a function inside the interpreter, I
>guess it makes sense...

Well, @_ a truly global variable, and everyone has access to it.
Consequently it is a mistake to assume anything about its contents
unless you have assigned it yourself.

>What I ended up doing, and I don't know if this is the best way to go but it
>seems to work on a global scale, I modified every script and added this line
>to the top:
>
>shift if (defined($_[0]));

Unfortunately this doesn't solve anything.  You are (sometimes) shifting
one item off the @_ array, but you'll never know what else could be in
there.

>The "if defined" bit is probably unnecessary, but a co-worker agreed that it
>makes the shift look more useful and avoids being grilled by the B.O.S.S.
>next time he looks at any of our code... ;)

Makes it look more useful how?  I don't understand.

Anyway, there's no way to really fix this but to change all calls
of the form "&func" to "func()".  This is because "&func" implicitly
makes the assumption that @_ contains what func expects.  As I have
argued above, this assumption is fundamentally flawed when your code
is called in an environment you don't control.  

Note that you have Perl to help you with the mass changes.  Write a script
to make the necessary adjustments, but don't forget to apply it in such a
way that you have a backup, just in case.  It may even be worth wile to
write a log file of the changes.

Anno


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

Date: 26 Jan 2001 11:13:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <slrn972muo.q5.abigail@tsathoggua.rlyeh.net>

James Kufrovich (eggie@REMOVE_TO_REPLYsunlink.net) wrote on MMDCCIV
September MCMXCIII in <URL:news:slrn971d6r.emp.eggie@melody.mephit.com>:
** Hi.
** 
** 	I just put together a small script (at the bottom there) that will
** rotate the characters in a string (supplied on the command line) and print
** the resulting string out, both forwards and backwards.  In other words,
** giving the program the string "funky" will produce the following output:
** 
** funky
** unkyf
** nkyfu
** kyfun
** yfunk
** yknuf
** knufy
** nufyk
** ufykn
** fyknu
** 
** 	For anyone who subscribes to Games magazine, yes, this is to help
** solve the "Rows Garden" puzzles.  Anyway, the script below works,
** splitting the string into an array of its characters, and rotating that.
** I'm sure it can be made shorter somehow, but I don't know how.  Any
** suggestions?  Or any ideas for a different approach?  Thanks.


Here's a one liner:

perl -le'$:=reverse$;=pop;map{chop;map{print}/(?=(.{${\length$;}}))/g}$;x2,$:x2'



Abigail
-- 
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${${@}}[$#{@{${@}}}]'


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

Date: Fri, 26 Jan 2001 13:03:58 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <3A7174BC.F61D3560@free.fr>

Abigail wrote:
> Here's a one liner:
perl -le'$:=reverse$;=pop;map{chop;map{print}/(?=(.{${\length$;}}))/g}$;x2,$:x2'

A one liner is always a contest. Here is shorter variation (no need to chop):
perl -le'$:=reverse$;=pop;map{map{print}/(?=(.{${\length$;}}).)/g}$;x2,$:x2'

I tried to avoid a map, but it's not shorter:
perl -le'$:=reverse$;=pop;map{print}"$;$;\n$:$:"=~/(?=(.{${\length$;}}).)/g'


Jerome.


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

Date: Fri, 26 Jan 2001 12:50:42 GMT
From: Paul King <pking123@sympatico.ca>
Subject: Re: Upgrading to Perl 5.6 under Debian 2.2
Message-Id: <g3037tkrsc9vj9uej2d24ptqugh2s2uv46@4ax.com>

Thanks for everyone's help so far. I will try out some of the
suggestions.

Paul King


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

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


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