[29874] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1117 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 14 11:09:44 2007

Date: Fri, 14 Dec 2007 08:09:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 14 Dec 2007     Volume: 11 Number: 1117

Today's topics:
    Re: A strange phenomena with Module Cwd <ben@morrow.me.uk>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <xueweizhong@gmail.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <bik.mido@tiscalinet.it>
    Re: FAQ 4.58 How can I know how many entries are in a h <tzz@lifelogs.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <brian.d.foy@gmail.com>
        Functions within regular expressions <ianw@dontneedspam.com>
    Re: Functions within regular expressions <peter@makholm.net>
    Re: Functions within regular expressions <bik.mido@tiscalinet.it>
    Re: Functions within regular expressions <abigail@abigail.be>
    Re: most elegant way to split text file randomly into n <bik.mido@tiscalinet.it>
    Re: most elegant way to split text file randomly into n <tzz@lifelogs.com>
    Re: most elegant way to split text file randomly into n <tzz@lifelogs.com>
    Re: Net::SSH::Perl - How to set remote default file per <zhilianghu@gmail.com>
    Re: not sure why I am getting the following warning "Us <mcardeiro@yahoo.com>
    Re: Performance of CGI Reduced <stoupa@practisoft.cz>
    Re: Question about "undef'ing" variables <tadmc@seesig.invalid>
    Re: Question about "undef'ing" variables <abigail@abigail.be>
    Re: Question about "undef'ing" variables <stoupa@practisoft.cz>
    Re: question..? <tadmc@seesig.invalid>
        simple bar chart module <jcharth@gmail.com>
    Re: simple bar chart module <smallpond@juno.com>
    Re: simple bar chart module <ben@morrow.me.uk>
    Re: split is not convinient <Mark.Seger@hp.com>
    Re: Using the DBI to connect to an Oracle server w/o co <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 14 Dec 2007 11:42:46 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: A strange phenomena with Module Cwd
Message-Id: <mq6a35-rdq2.ln1@osiris.mauzo.dyndns.org>


Quoth Scott <rwxrxrx@gmail.com>:
> [scott@FreeBSD ~/perl]$ cat cwd.pl
> #!/usr/bin/perl
> #
> use Cwd;
> $dir = getcwd();
> print "$dir\n";
> [scott@FreeBSD ~/perl]$ perl cwd.pl
> /usr/home/scott/perl                # How does this "/usr" prefix come?
> [scott@FreeBSD ~/perl]$ pwd
> /home/scott/perl

I would guess that /home is a symlink to /usr/home. If you run /bin/pwd
instead of the shell builtin it should give the same result as perl.

Ben



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

Date: Fri, 14 Dec 2007 12:22:07 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <unp4m31ub4lbc4l80mt8vr43pdf4qti2b2@4ax.com>

On Thu, 13 Dec 2007 05:01:22 -0800 (PST), Todd <xueweizhong@gmail.com>
wrote:

>>         $num_keys = keys %hash;
>
>Seems there is a better way to do it:
>
>    #! /bin/perl -l
>
>    %hash = (a=>1, b=>2, c=>3, d=>4, e);
>    $num_keys = %hash+0;
>    print $num_keys;
>
>    __END__
>
>    5
>
>So it means when in numeric(not string) context, %hash return numbers
>of keys accidently. But anyway, it's a good feature.

No, it doesn't. It returns a string of the form "$n/$m" with $n and $m
being numbers. Using this string as a number, its value will be $n,
but $n is not guaranteed to be the number of keys.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 12:25:34 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <90q4m3lo9cvej1gudp6iqs30pq6kbl8284@4ax.com>

On Thu, 13 Dec 2007 18:59:21 -0800 (PST), Todd <xueweizhong@gmail.com>
wrote:

>xhos...@gmail.com wrote:
>> $ perl -le '$x{$_}=1 foreach 1..1e6; print scalar %x; print scalar keys %x'
>>
>> 644020/1048576
>> 1000000
>
>Really cool discovery.

No discovery, just knowledge one can get straight out of the docs:

: If you evaluate a hash in scalar context, it returns false if the hash
: is empty. If there are any key/value pairs, it returns true; more
: precisely, the value returned is a string consisting of the number of
: used buckets and the number of allocated buckets, separated by a slash.
: This is pretty much useful only to find out whether Perl's internal
: hashing algorithm is performing poorly on your data set. For example,
: you stick 10,000 things in a hash, but evaluating %HASH in scalar
: context reveals "1/16", which means only one out of sixteen buckets has
: been touched, and presumably contains all 10,000 of your items. This
: isn't supposed to happen.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 12:28:02 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <b5q4m3hjmg1e63qoe0req40kmj41n62aej@4ax.com>

On Thu, 13 Dec 2007 08:48:12 -0800 (PST), Todd <xueweizhong@gmail.com>
wrote:

>If you evaluate a hash in scalar context, it returns false if the hash
>is empty.  If there are any key/value pairs, it returns true; more
>precisely, the value returned is a string consisting of the number of
>used buckets and the number of allocated buckets, separated by a slash.
>
>
>Is it still accident or undefined behavior?

Accident: "used buckets" ne "keys"!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 12:29:33 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <18q4m3ti2614vd0vp7sq43bas6lm72mrjn@4ax.com>

On Thu, 13 Dec 2007 18:34:18 GMT, Uri Guttman <uri@stemsystems.com>
wrote:

>good point which i hadn't noticed before. regardless, i never use %hash
>in a scalar context. hell, i can't recall using keys either in a scalar

Then probably you're not a perl programmer.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 12:30:43 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <taq4m3ht2mgpvrcc7ufp1j8a4h9h3s2c85@4ax.com>

On Thu, 13 Dec 2007 08:57:45 -0800 (PST), Todd <xueweizhong@gmail.com>
wrote:

>Uri Guttman wrote:
>> no, it is not a feature nor is it good. please don't think you will
>> discover such a neat thing given how little perl you know. what a hash
>> returns in scalar context is documented and it is the a string with the
>> number of entries/the number of buckets. it will numerify to the same
>> value as scalar keys but it is not warning safe. this is typical newbie
>> mistake of not studying the docs and not enabling warnings.
>
>?

!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 04:58:34 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <eb5ee865-c44f-4e1b-ac60-6f39e9fba8e0@e25g2000prg.googlegroups.com>

Thanks Michele.

Seems that many people (include me certainly) are not patient enough
to read the whole perldoc thoroughly before making the conclusion.
I'll take care of it as a good lesson.


-Todd


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

Date: Fri, 14 Dec 2007 14:11:57 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <h705m31pvkcu9hmo4e3tvdbktv1aibp47q@4ax.com>

On Fri, 14 Dec 2007 04:58:34 -0800 (PST), Todd <xueweizhong@gmail.com>
wrote:

>Seems that many people (include me certainly) are not patient enough
>to read the whole perldoc thoroughly before making the conclusion.
>I'll take care of it as a good lesson.

It happens all the time. In another thread I "corrected" myself the
views of the OP only to discover I was misguided too.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 08:52:39 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <86bq8t9vm0.fsf@lifelogs.com>

On Fri, 14 Dec 2007 04:58:34 -0800 (PST) Todd <xueweizhong@gmail.com> wrote: 

T> Thanks Michele.
T> Seems that many people (include me certainly) are not patient enough
T> to read the whole perldoc thoroughly before making the conclusion.
T> I'll take care of it as a good lesson.

I think your excitement when you discovered something new was
understandable.  Keep enjoying the process of discovery.  You'll
eventually have to read the perldocs if you want to be good at Perl (the
"Programming Perl" book is good but the perldocs are painfully precise);
you should at least go through all the FAQs to make sure you don't
discover something already well-known.

Ted


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

Date: Fri, 14 Dec 2007 09:02:02 -0600
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <141220070902027537%brian.d.foy@gmail.com>

In article
<d0974888-4737-4596-8c68-d41a2d33582a@a35g2000prf.googlegroups.com>,
Todd <xueweizhong@gmail.com> wrote:

> brian d foy wrote:
> > You're relying on undefined behaviour instead of the documented way to
> > do it.
> 
> This is from official Perl5.8.8 manual:
> 
> perldoc perldata
> 
> If you evaluate a hash in scalar context, it returns false if the hash
> is empty.  If there are any key/value pairs, it returns true; more
> precisely, the value returned is a string consisting of the number of
> used buckets and the number of allocated buckets, separated by a slash.
> 
> 
> Is it still accident or undefined behavior?

Where in that extract does it say anything about the number of keys?
There's no docs that say it returns the number of keys.


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

Date: Fri, 14 Dec 2007 12:21:37 -0000
From: "IanW" <ianw@dontneedspam.com>
Subject: Functions within regular expressions
Message-Id: <fjtsn0$2scd$1@energise.enta.net>

Is it possible to execute a function within a regular expression. For 
example, say I have a string like this:

my $string = "Item 1 cost is: 2345.67\nItem 2 cost is: 5678.90\n";

Say I have a function ( called formatPrice() ) that processes a number, like 
2345.67 in that string, and makes it look like this:

$2,345.67

So, in a regexp I want to do something like this:

$string =~ s/(Item \d+ cost is: )(.+?)\n/$1formatPrice($2)\n/g;

That doesn't work as it stands, but is this kind of thing possible?

Thanks
Ian 




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

Date: Fri, 14 Dec 2007 12:27:49 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Functions within regular expressions
Message-Id: <87zlwd5um2.fsf@hacking.dk>

"IanW" <ianw@dontneedspam.com> writes:

> So, in a regexp I want to do something like this:
>
> $string =~ s/(Item \d+ cost is: )(.+?)\n/$1formatPrice($2)\n/g;
>
> That doesn't work as it stands, but is this kind of thing possible?

You should look at the /e modifier for you substitution. Read 'perldoc
perlop' the paragraph starting with

  s/PATTERN/REPLACEMENT/egimosx

//Makholm


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

Date: Fri, 14 Dec 2007 13:52:15 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Functions within regular expressions
Message-Id: <p0v4m3988e702v6m661dna4ejscl0o4m7u@4ax.com>

On Fri, 14 Dec 2007 12:21:37 -0000, "IanW" <ianw@dontneedspam.com>
wrote:

>Is it possible to execute a function within a regular expression. For 

If it is a question, then it should end with a question mark.
If it is a question, then the answer is "yes"...

>$string =~ s/(Item \d+ cost is: )(.+?)\n/$1formatPrice($2)\n/g;

 ...but this has nothing to do with "functions *within* regexen".

>That doesn't work as it stands, but is this kind of thing possible?

/e


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 14 Dec 2007 13:37:05 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Functions within regular expressions
Message-Id: <slrnfm51o0.1sh.abigail@alexandra.abigail.be>

                                      _
IanW (ianw@dontneedspam.com) wrote on VCCXVIII September MCMXCIII in
<URL:news:fjtsn0$2scd$1@energise.enta.net>:
,,  Is it possible to execute a function within a regular expression. For 
,,  example, say I have a string like this:
,,  
,,  my $string = "Item 1 cost is: 2345.67\nItem 2 cost is: 5678.90\n";
,,  
,,  Say I have a function ( called formatPrice() ) that processes a number, like 
,,  2345.67 in that string, and makes it look like this:
,,  
,,  $2,345.67
,,  
,,  So, in a regexp I want to do something like this:
,,  
,,  $string =~ s/(Item \d+ cost is: )(.+?)\n/$1formatPrice($2)\n/g;
,,  
,,  That doesn't work as it stands, but is this kind of thing possible?


You don't want to execute a function from your regular expression, 
instead, what you want is to do some action in the replacement.

That's an important difference. 

I would write it as:

    s/(Item \d+ cost is: )(.+)\n/$1 . formatPrice ($2)/eg;

or, if I were to write it next week, after the release of 5.10:

    s/Item \d+ cost is: \K(?<price>.+)(?=\n)/formatPrice ($+ {price})/eg;


Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;


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

Date: Fri, 14 Dec 2007 12:45:43 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: most elegant way to split text file randomly into n parts?
Message-Id: <mlq4m3193bj9064gj59fnhtu77ds03n4ba@4ax.com>

On Fri, 14 Dec 2007 05:27:48 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>> parts? If the original file contains m lines, the n new file should
>> each contain about m/n lines, chosen uniformly at random.
>
>perldoc -q shuffle
>
>and then simply write each chunk of m/n lines to an individual file.

The (possibly) interesting part is that about "*about* m/n lines". I
would generate n random numbers and normalize them suitably. Of course
he could like to narrow the standard deviation of the starting numbers
in the first place e.g.:

  my @nums = map 1+$alpha*rand, 1..$n;


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 14 Dec 2007 08:28:46 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: most elegant way to split text file randomly into n parts?
Message-Id: <86wsrh9wpt.fsf@lifelogs.com>

On Thu, 13 Dec 2007 21:03:58 -0800 (PST) Markus Dehmann <markus.dehmann@gmail.com> wrote: 

MD> What is the most elegant way to split a text file randomly into n
MD> parts? If the original file contains m lines, the n new file should
MD> each contain about m/n lines, chosen uniformly at random.

MD> Leaving the actual handling of files aside here is a naive solution:

MD> my $n = 10;
MD> foreach my $line (0..9999){
MD>     my $r = rand;
MD>     for(my $i=$n; $i>=0; --$i){
MD>         if($r > $i/$n){
MD>             print "Line $line: Print to file $i\n";
MD>             last;
MD>         }
MD>     }
MD> }

MD> Are there other ways to do it? This seems like a very typical perl
MD> problem, so it would be interesting to see what solutions others come
MD> up with!

Usually programmers don't like the word "about" in a specification, so
your requirements should be refined a bit.

Essentially you're trying to partition a set S of size M into N subsets
(S[0]...S[N-1]).  You should define what to do with the left over (M%N)
elements of S: assign them randomly or according to some specific rule?

Also, do you want to guarantee a minimum amount of elements in each
subset?

If you assign leftovers randomly and don't require minimums, you're just
picking a random number between 1 and N for any input you're given:

while (<>)
{
 printf "Line %d goes to set %d\n", $. , rand(100)+1;
}

If you're not happy with the built-in random number generator you could
use something else instead of rand().  Note how I use rand(100) to get
random numbers between 0 and 99.

Ted


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

Date: Fri, 14 Dec 2007 08:35:01 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: most elegant way to split text file randomly into n parts?
Message-Id: <86prx99wfe.fsf@lifelogs.com>

On Fri, 14 Dec 2007 12:45:43 +0100 Michele Dondi <bik.mido@tiscalinet.it> wrote: 

MD> On Fri, 14 Dec 2007 05:27:48 GMT, "Jürgen Exner"
MD> <jurgenex@hotmail.com> wrote:

>>> parts? If the original file contains m lines, the n new file should
>>> each contain about m/n lines, chosen uniformly at random.
>> 
>> perldoc -q shuffle
>> 
>> and then simply write each chunk of m/n lines to an individual file.

MD> The (possibly) interesting part is that about "*about* m/n lines". I
MD> would generate n random numbers and normalize them suitably. Of course
MD> he could like to narrow the standard deviation of the starting numbers
MD> in the first place e.g.:

MD>   my @nums = map 1+$alpha*rand, 1..$n;

I think Perl's rand() is uniformly distributed so this should be OK
without the extra normalization, but as I mentioned in my other reply
the word "about" is too imprecise to bother trying to guess what the OP
really meant.

Ted


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

Date: Fri, 14 Dec 2007 06:25:12 -0800 (PST)
From: Joe <zhilianghu@gmail.com>
Subject: Re: Net::SSH::Perl - How to set remote default file permissions
Message-Id: <057f3e7d-e16a-428e-b780-bbb2a2e96383@b1g2000pra.googlegroups.com>

On Dec 13, 12:53 pm, Joe <zhilian...@gmail.com> wrote:
> When I manually execute a script with Net::SSH::Perl to run a remote
> program, the output file has a permission "660"; When I use a web
> server to execute the script (the script uses my user account identity/
> pass), the remote output file has a permission "600".
>
> How can I make the script to set a default remote file permission
> (like "644") so the web server can read the results back?  I tried:
>  ($stdout, $stderr, $exit) = $ssh->cmd("umask 022; script");
> and it didn't work.

Well, a reply to myself - I accomplished this by
($stdout, $stderr, $exit) = $ssh->cmd("script; chmod 644 'outfile'");

Joe


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

Date: Fri, 14 Dec 2007 06:25:41 -0800 (PST)
From: "mcardeiro@yahoo.com" <mcardeiro@yahoo.com>
Subject: Re: not sure why I am getting the following warning "Useless use of a  constant in void context"
Message-Id: <512aa0fe-40ab-4173-812f-997eb6fa3b9d@e6g2000prf.googlegroups.com>


On Dec 13, 1:52 pm, Glenn Jackman   wrote:

> the execute() routine returns a value that you're ignoring.

no I'm not.  the "|| error_page()" written after the execute  means if
there is no return value from execute run error_page() (but as Ben
pointed out I will not get a very helpful message as I have $dbh-
>errstr enclosed in double quotes ).





On Dec 13, 1:52 pm, Ben Morrow <b...@morrow.me.uk> wrote:


> This style of block comment is not helpful. It just makes it impossible
> to get any overview of the structure of the code.

???

> Posting code with more
> than 80 columns is rude.

sorry.  was unaware of this rule.

> As John said, this is a precedence error: get into the habit of always
> using 'and' and 'or' for flow control, not && and ||.

this is not a problem as error_page() causes the script to exit (I
should have changed it to "die" in my post for clarity)


> This line doesn't give that warning, in a minimal example I just
> constructed. Please give us a whole example.

thats a bummer, the example I gave was about as complete as I could
make it without pasting in the hundereds of lines of code in the real
script.  Thanks for going through the code and trying to help.

Mike Cardeiro





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

Date: Fri, 14 Dec 2007 16:23:31 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Performance of CGI Reduced
Message-Id: <fju8j5$g9a$3@ns.felk.cvut.cz>

Praki wrote:
> Hi All,
> 
> when i use
> 
> use CGI;
> use CGI::Session;
> use Net::LDAP;
> 
> in my cgi file the performance is reduced. i mean it takes more time
> to get load every time and all the pages where ever i use this .
> why it is happening ? is there any other alternative for this...
> 
You can use part only

    use CGI qw(:cgi);
or
    use CGI qw(:standard);
or other part you need.
-- 
Petr
Skype: callto://fidokomik
Na mail uvedeny v headeru zpravy nema cenu nic posilat, konci to v PR*
:-) 

Odpovidejte na petr na practisoft cz


Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.) 

Please reply to <petr AT practisoft DOT cz>



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

Date: Fri, 14 Dec 2007 12:11:55 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Question about "undef'ing" variables
Message-Id: <slrnfm4shn.6d3.tadmc@tadmc30.sbcglobal.net>

Klaus <klaus03@gmail.com> wrote:

> It is common practice to reset your variables using "undef":
>
> undef $a;
> undef $b;
> undef $c;
> undef $d;


That is a very _rare_ practice in my experience.

It is common practice to "reset" your variables by letting them
go out of scope on each loop iteration.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: 14 Dec 2007 13:40:03 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Question about "undef'ing" variables
Message-Id: <slrnfm51tj.1sh.abigail@alexandra.abigail.be>

                                  _
somebody (some@body.com) wrote on VCCXVIII September MCMXCIII in
<URL:news:iL2dncniwMa6ZvzanZ2dnUVZ_s6mnZ2d@comcast.com>:
||  In the code snippet below, I process each line of a file using the split
||  command.  After the variables $a, $b, $c, and $d are used, I need to
||  ensure they're "undef'd" before processing the next line, so the value
||  assigned from the previous line is not defined.  So the line
||  ($a, $b, $c, $d) = (0) x 4; resets these variables.  (In reality there
||  are more variables). This seems to slow down my program significantly.  Is

Really? That sounds quite amazing. Do you have a snippet of code that
should how expensive this is?

||  there a better way to re-initialize these variables?  Maybe define them
||  local to the sub instead of globally?

My main reason to put them into a block would not be performance. 
Defining your variables in the smallest possible block is just a
good engineering principle.



Abigail
-- 
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";


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

Date: Fri, 14 Dec 2007 16:32:38 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Question about "undef'ing" variables
Message-Id: <fju8j6$g9a$4@ns.felk.cvut.cz>

Martijn Lievaart wrote:
> On Thu, 13 Dec 2007 22:40:23 -0500, somebody wrote:
>
>> In the code snippet below, I process each line of a file using the
>> split command.  After the variables $a, $b, $c, and $d are used, I
>> need to
>
> Don't use $a and $b, they're magic. I understand this is just an

Ehm, $a and $b are magic for Perl 5.8.x, not for Perl 5.6.x, and I think this 
was be a stupid idea. Maybe could be used some like $_a and $_b or $__ and 
$___ . But now is too late :-(
-- 
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>



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

Date: Fri, 14 Dec 2007 12:11:55 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: question..?
Message-Id: <slrnfm4s9f.6d3.tadmc@tadmc30.sbcglobal.net>

malboros <hpobox@gmail.com> wrote:

> Subject: question..?


Please put the subject of your article in the Subject of your article.

Have you seen the Posting Guidelines that are posted here frequently?



-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Fri, 14 Dec 2007 06:50:30 -0800 (PST)
From: joe <jcharth@gmail.com>
Subject: simple bar chart module
Message-Id: <e32d50c9-ec37-4fd0-9c7f-077b3e3cad92@s19g2000prg.googlegroups.com>

Hello does anyone know of any simple bar chart module without GD. I
would use GD but it look like I have to compile a few things to get it
working. So i am trying to find something easy like text graph module.
Any ideas?


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

Date: Fri, 14 Dec 2007 06:59:26 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: simple bar chart module
Message-Id: <133cbb83-82f8-4d9c-92fa-b072cfa0aa27@d27g2000prf.googlegroups.com>

On Dec 14, 9:50 am, joe <jcha...@gmail.com> wrote:
> Hello does anyone know of any simple bar chart module without GD. I
> would use GD but it look like I have to compile a few things to get it
> working. So i am trying to find something easy like text graph module.
> Any ideas?


I haven't tried it, but Tk::Graph looks to be pure perl.
--S


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

Date: Fri, 14 Dec 2007 15:19:03 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: simple bar chart module
Message-Id: <7gja35-rnt.ln1@osiris.mauzo.dyndns.org>


Quoth smallpond <smallpond@juno.com>:
> On Dec 14, 9:50 am, joe <jcha...@gmail.com> wrote:
> > Hello does anyone know of any simple bar chart module without GD. I
> > would use GD but it look like I have to compile a few things to get it
> > working. So i am trying to find something easy like text graph module.
> > Any ideas?
> 
> I haven't tried it, but Tk::Graph looks to be pure perl.

Well, yes, but it depends on Tk, which isn't.

To the OP: what do you actually want? As in, what sort of output do you
want? If you want an image, you're unlikely to find a non-XS module that
will help; similarly if you want your program to open a window. If
you're happy with a textual output format like SVG, then there's
SVG::TT::Graph.

Ben



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

Date: Fri, 14 Dec 2007 09:32:27 -0500
From: Mark Seger <Mark.Seger@hp.com>
To: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: split is not convinient
Message-Id: <476293FB.6090600@hp.com>

Tad J McClellan wrote:
> Mark Seger <Mark.Seger@hp.com> wrote:
> 
>> 0[root@cag-dl380-01 collectl]# cat test.pl
>     ^^^^
>     ^^^^
> 
> I hope you are not really trying out Perl snippets as the superuser...
doesn't everybody?  9-)
-mark


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

Date: Fri, 14 Dec 2007 08:46:56 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Using the DBI to connect to an Oracle server w/o connecting to a database
Message-Id: <86ir319vvj.fsf@lifelogs.com>

On 13 Dec 2007 18:04:48 GMT xhoster@gmail.com wrote: 

x> Tim <google@hoodfamily.org> wrote:
>> I've searched for the answer to this problem and have not seen it
>> (which suggests what the answer might be ;-) ). Is it possible to use
>> DBI (and DBD::Oracle) to connect to an Oracle server without
>> connecting to a database? This would be the DBI equivalent of:
>> 
>> sqlplus /nolog
SQL> connect user/passwd@database;

x> /nolog turns sqlplus into something unusual and highly specific
x> to Oracle.  I doubt DBI has an interest in trying to reproduce that.

>> or, more similarly:
>> 
>> sqlplus /nolog @my.sql
>> 
>> where my.sql might be:
>> 
>> connect user/passwd@database;
>> select ...
>> etc.
>> 
>> I'm thinking this is not possible, but I hope it is. Thanks.

x> Why would you want that?  The point of DBI is that it provides a perl
x> interface for interactively communicating with Oracle.  If you just
x> want to feed a text file through sqlplus with no interaction, then why
x> bother trying to do it with DBI?

Well this *is* a valid question: how to mix DBI connect calls with DBI
SQL statements?  See in his input how he connected to a particular
database through *user input* and not code?  I don't think you can do
that with SQL statements passed to DBI, you need to do a new connect().

One answer, specifically for DB connections, is to parse the input on
the fly, something like:

my $dbh;
while (my $line = <>)
{
 if ($line =~ m/^connect\s/i)
 {
  # switch the $dbh handle
  $dbh = ... connect call with parameters parsed from $line ...
 }
 elsif (defined $dbh)
 {
  ... use $line on $dbh ...
 }
 else
 {
  warn "Input [$line] came before a 'connect ...' call in the input, so no database connection was available";
 }
}

This is generically useful, not just for Oracle interaction.

Ted


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 1117
***************************************


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