[30166] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1409 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 31 18:10:13 2008

Date: Mon, 31 Mar 2008 15:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 31 Mar 2008     Volume: 11 Number: 1409

Today's topics:
    Re: empty variables - getting rid of "uninitialized val <szrRE@szromanMO.comVE>
    Re: empty variables - getting rid of "uninitialized val <noreply@gunnar.cc>
    Re: empty variables - getting rid of "uninitialized val <szrRE@szromanMO.comVE>
    Re: empty variables - getting rid of "uninitialized val <willem@stack.nl>
    Re: empty variables - getting rid of "uninitialized val <devnull4711@web.de>
        every combination of Y/N in 5 positions joemacbusiness@yahoo.com
    Re: every combination of Y/N in 5 positions <smallpond@juno.com>
    Re: every combination of Y/N in 5 positions <sandy_saydakov@yahoo.com>
    Re: every combination of Y/N in 5 positions <noreply@gunnar.cc>
    Re: every combination of Y/N in 5 positions <jurgenex@hotmail.com>
    Re: Parse x.500 DN  and change order  displayed <szrRE@szromanMO.comVE>
    Re: Parse x.500 DN  and change order  displayed dummy@phony.info
    Re: Parse x.500 DN and change order displayed <gotsecure@gmail.com>
    Re: printf: zero pad after the decimal a given amount <mritty@gmail.com>
    Re: printf: zero pad after the decimal a given amount <szrRE@szromanMO.comVE>
    Re: printf: zero pad after the decimal a given amount <devnull4711@web.de>
    Re: printf: zero pad after the decimal a given amount <rvtol+news@isolution.nl>
    Re: printf: zero pad after the decimal a given amount <devnull4711@web.de>
    Re: printf: zero pad after the decimal a given amount xhoster@gmail.com
    Re: printf: zero pad after the decimal a given amount <ben@morrow.me.uk>
    Re: Sharing a DBI::Mysql database connection with your  xhoster@gmail.com
    Re: Sharing a DBI::Mysql database connection with your  <rvtol+news@isolution.nl>
    Re: Sharing a DBI::Mysql database connection with your  <szrRE@szromanMO.comVE>
    Re: Windows paths in glob <bart.lateur@pandora.be>
    Re: Windows paths in glob <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 31 Mar 2008 10:08:59 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <fsr5rb0koi@news2.newsguy.com>

Peter Scott wrote:
> On Mon, 31 Mar 2008 01:14:21 -0700, Joe Smith wrote:
>> Tomasz Chmielewski wrote:
>>> use strict;
>>> use warnings;
>>> ...
>>>     if ( $execargs[0] ne '' ) { ..... }
>>
>> Whenever you are using warnings, you should never attempt to use
>> an array element without first testing that it is there.
>>
>>     if (@execargs and $execargs[0] ne '') { ... }
>
> Not quite good enough.  The element could exist but be undef.
>
>  if (defined $execargs[0] && $execargs[0] ne '') { ... }

Instead of checking for definity, you could check for existance too:

   if (exists $execargs[0] && $execargs[0] ne '') { ... }

Or even:

   if (exists $execargs[0] && !!$execargs[0]) { ... }

-- 
szr 




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

Date: Mon, 31 Mar 2008 19:27:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <65clbeF2fe8l2U1@mid.individual.net>

szr wrote:
> Peter Scott wrote:
>> On Mon, 31 Mar 2008 01:14:21 -0700, Joe Smith wrote:
>>>
>>>     if (@execargs and $execargs[0] ne '') { ... }
>>
>> Not quite good enough.  The element could exist but be undef.
>>
>>  if (defined $execargs[0] && $execargs[0] ne '') { ... }
> 
> Instead of checking for definity, you could check for existance too:
> 
>    if (exists $execargs[0] && $execargs[0] ne '') { ... }

I think you missed the point...

C:\home>type test.pl
use warnings;
@execargs = undef;
if (exists $execargs[0] && $execargs[0] ne '') {
     # ...
}

C:\home>perl test.pl
Use of uninitialized value $execargs[0] in string ne at test.pl line 3.

C:\home>

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 31 Mar 2008 11:18:40 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <fsr9u10pjg@news2.newsguy.com>

Gunnar Hjalmarsson wrote:
> szr wrote:
>> Peter Scott wrote:
>>> On Mon, 31 Mar 2008 01:14:21 -0700, Joe Smith wrote:
>>>>
>>>>     if (@execargs and $execargs[0] ne '') { ... }
>>>
>>> Not quite good enough.  The element could exist but be undef.
>>>
>>>  if (defined $execargs[0] && $execargs[0] ne '') { ... }
>>
>> Instead of checking for definity, you could check for existance too:
>>
>>    if (exists $execargs[0] && $execargs[0] ne '') { ... }
>
> I think you missed the point...
>
> C:\home>type test.pl
> use warnings;
> @execargs = undef;
> if (exists $execargs[0] && $execargs[0] ne '') {
>     # ...
> }
>
> C:\home>perl test.pl
> Use of uninitialized value $execargs[0] in string ne at test.pl line
> 3.
> C:\home>

I ran the same test and got the same result.

Removing the  " && $execargs[0] ne '' "  portion prevented the error.

This works too:

   if (exists $execargs[0] && !!$execargs[0]) {

(Tested in 5.10.0, 5.8.8, and 5.6.1)


So I wonder, since  " exists $execargs[0] "  fails, why does it still
evaluate  " && $execargs[0] ne '' "  , thus causing the error.

This happens in all 3 versions I tested with. Is this a bug? I thought 
it is supposed to short-circuit if the first expr fails in an && or AND 
?

-- 
szr 




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

Date: Mon, 31 Mar 2008 18:23:00 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <slrnfv2b04.1don.willem@snail.stack.nl>

szr wrote:
) I ran the same test and got the same result.
)
) Removing the  " && $execargs[0] ne '' "  portion prevented the error.
)
) This works too:
)
)    if (exists $execargs[0] && !!$execargs[0]) {
)
) (Tested in 5.10.0, 5.8.8, and 5.6.1)
)
)
) So I wonder, since  " exists $execargs[0] "  fails, why does it still
) evaluate  " && $execargs[0] ne '' "  , thus causing the error.
)
) This happens in all 3 versions I tested with. Is this a bug? I thought 
) it is supposed to short-circuit if the first expr fails in an && or AND 
) ?

It may be an operator precedence issue.
Try 'and' instead of '&&', or use parentheses around the second expression.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Mon, 31 Mar 2008 20:29:48 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <65cosuF2faasvU4@mid.individual.net>

szr wrote:
> Gunnar Hjalmarsson wrote:
>>
>>use warnings;
>>@execargs = undef;

Better:
@execargs = (undef);

>>if (exists $execargs[0] && $execargs[0] ne '') {
>>    # ...
>>}
>>
>>C:\home>perl test.pl
>>Use of uninitialized value $execargs[0] in string ne at test.pl line
>>3.
> 
> I ran the same test and got the same result.
> 
> Removing the  " && $execargs[0] ne '' "  portion prevented the error.

Yes, because this test produces the warning.

> This works too:
> 
>    if (exists $execargs[0] && !!$execargs[0]) {
> 
> (Tested in 5.10.0, 5.8.8, and 5.6.1)
> 
> So I wonder, since  " exists $execargs[0] "  fails,

No, "exists $execargs[0]" succeeds, because there is an element 0.

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Mon, 31 Mar 2008 13:57:11 -0700 (PDT)
From: joemacbusiness@yahoo.com
Subject: every combination of Y/N in 5 positions
Message-Id: <c859d4a0-6e48-4e7a-9b1d-bc56092ed952@l42g2000hsc.googlegroups.com>

Hi All,

This has probably already been written but I did not see it on CPAN.
Is there a code snippent that can print every possible combination
of Y/N's in a 5 position array or string?

For example: Y Y Y Y Y becomes
N Y Y Y Y
Y N Y Y Y....
Y Y N N Y etc.

Here is my first attempt but it only handles a single field change
moving from left to right etc...

Thanks, --Joe Mac.

#!/usr/bin/perl

my @array = qw(Y Y Y Y Y);

&jumble(0);
&jumble(1);
&jumble(2);
&jumble(3);
&jumble(4);

sub jumble {
    my $arg = shift;
#    print "$arg\n";
    $newvar = &changeIt($arg);
    if ($arg == 0){
        print "$newvar $array[1] $array[2] $array[3] $array[4]\n";
    } elsif ($arg == 1){
        print "$array[0] $newvar $array[2] $array[3] $array[4]\n";
    } elsif ($arg == 2){
        print "$array[0] $array[1] $newvar $array[3] $array[4]\n";
    } elsif ($arg == 3){
        print "$array[0] $array[1] $array[2] $newvar $array[4]\n";
    } elsif ($arg == 4){
        print "$array[0] $array[1] $array[2] $array[3] $newvar\n";
    }
}

sub changeIt {
    my $var = shift;
#print "array[$var] is $array[$var]\n";
    if ($array[$var] eq "Y"){
        $var = "N";
    }
    return("$var");
}

#
# $ perl ./jumble.pl
N Y Y Y Y
Y N Y Y Y
Y Y N Y Y
Y Y Y N Y
Y Y Y Y N


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

Date: Mon, 31 Mar 2008 14:06:01 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: every combination of Y/N in 5 positions
Message-Id: <91c33be5-63cb-45f2-b3ce-f9eff7e11790@y24g2000hsd.googlegroups.com>

On Mar 31, 4:57 pm, joemacbusin...@yahoo.com wrote:
> Hi All,
>
> This has probably already been written but I did not see it on CPAN.
> Is there a code snippent that can print every possible combination
> of Y/N's in a 5 position array or string?
>
> For example: Y Y Y Y Y becomes
> N Y Y Y Y
> Y N Y Y Y....
> Y Y N N Y etc.
>

Who gets the credit for doing your homework?



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

Date: Mon, 31 Mar 2008 14:21:27 -0700 (PDT)
From: Sandy <sandy_saydakov@yahoo.com>
Subject: Re: every combination of Y/N in 5 positions
Message-Id: <f1f5a806-56b8-470a-9d59-160d165e97ec@e10g2000prf.googlegroups.com>

On Mar 31, 1:57 pm, joemacbusin...@yahoo.com wrote:
>
> This has probably already been written but I did not see it on CPAN.
> Is there a code snippent that can print every possible combination
> of Y/N's in a 5 position array or string?

If I understand you correctly, it sounds like a 5-bit binary with N
and Y instead of 0 and 1. Try looping through numbers 0..31 (max 5-bit
number) and call some transforming function (let's call it to_string),
which would loop trough the bits and produce a string of Ys and Ns
accordingly. I intentionally give you just an idea, so you could be
proud of yourself implementing it :) It will take some 15 lines of
code.

/sandy
http://myperlquiz.com/


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

Date: Mon, 31 Mar 2008 23:23:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: every combination of Y/N in 5 positions
Message-Id: <65d36hF2fj9v1U1@mid.individual.net>

smallpond wrote:
> On Mar 31, 4:57 pm, joemacbusin...@yahoo.com wrote:
>> Hi All,
>>
>> This has probably already been written but I did not see it on CPAN.
>> Is there a code snippent that can print every possible combination
>> of Y/N's in a 5 position array or string?
>>
>> For example: Y Y Y Y Y becomes
>> N Y Y Y Y
>> Y N Y Y Y....
>> Y Y N N Y etc.
>>
> 
> Who gets the credit for doing your homework?

I do, I hope. :)

     foreach my $num ( 0 .. 0b11111 ) {
         local *_ = \ sprintf '%05b', $num;
         tr/01/NY/;
         print "$_\n";
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 31 Mar 2008 21:36:55 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: every combination of Y/N in 5 positions
Message-Id: <l4m2v3964i3ie3u4rbsit78d8q96npkqev@4ax.com>

joemacbusiness@yahoo.com wrote:
>This has probably already been written but I did not see it on CPAN.
>Is there a code snippent that can print every possible combination
>of Y/N's in a 5 position array or string?

I am sure it has been written many times. Search for permutation with
repetitions.

However, just for the fun of it, here's yet another implementation:

for (0..2**5-1) {
    $_ = sprintf "%05b", $_;
    s/0/N/g;
    s/1/Y/g;
    print "$_\n";
}


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

Date: Mon, 31 Mar 2008 09:42:03 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Parse x.500 DN  and change order  displayed
Message-Id: <fsr48s0j1e@news2.newsguy.com>

Hallvard B Furuseth wrote:
> SecureIT writes:
>> I am trying to change this
>> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"
>> to this:
>> "serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"
>
> Without escape sequences like "\," and "\+" in the DNs (if that's
> allowed anyway, I don't remember the details of X.500 Dn syntax), this
> moves serialNumber first in each RDN:
>
> s/(^|,)([^,]*)\+(serialNumber=[^+,]*)(?=[+,])/$1$3+$2/gi;
> die "didn't catch all 'foo+serialNumber's" if /\+serialNumber=/i;

Using this regex will take care of \, and \+ escapes:

s/(^|(?<!\\),)((?:[^,]|\\,)*)\+(serialNumber=(?:[^+,]|\\[+,])*)(?=(?<!\\)[+,])/$1$3+$2/gi;


Matches:

   my $dn = "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US";
   $dn =~ s/
         (^|(?<!\\),)  ((?:[^,]|\\,)*)  \+
         (serialNumber  =  (?:[^+,]  |  \\[+,])*)
         (?=(?<!\\)[+,])
      /$1$3+$2/gix;
   print $dn;


   __OUTPUT__
   serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US


And:

   my $dn = "cn=Smith\\, Bob+serialNumber=CR01312\\+0080827,o=ICM,c=US";
   $dn =~ s/
         (^|(?<!\\),)  ((?:[^,]|\\,)*)  \+
         (serialNumber  =  (?:[^+,]  |  \\[+,])*)
         (?=(?<!\\)[+,])
      /$1$3+$2/gix;
   print $dn;


   __OUTPUT__
   serialNumber=CR01312\+0080827+cn=Smith\, Bob,o=ICM,c=US


Hope this helps.

-- 
szr 




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

Date: Mon, 31 Mar 2008 14:31:46 -0700
From: dummy@phony.info
Subject: Re: Parse x.500 DN  and change order  displayed
Message-Id: <3tl2v31m5a6g3i79di104fnt8soh1t2tj5@4ax.com>

On Mon, 31 Mar 2008 04:09:07 GMT, Uri Guttman <uri@stemsystems.com>
wrote:

>>>>>> "S" == SecureIT  <gotsecure@gmail.com> writes:
>
>  S> I am trying to change this
>  S> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"
>
>  S> to this:
>
>  S> "serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"
>
>  S> There are about 2000 entries like this and I need to have them all
>  S> displayed with serialNumber first, and cn last then the rest of the
>  S> DN, the names and serialNumbers are all unique to each entry.
>
>are all the entries separated by +? how many are there (you show only 2)?
>
>if it is always + then you can just split the lines, grab out the cn one
>(use grep) and also filter out the rest. then order them as you
>want. call join '+' to rebuild the line. it can also be done with a hash
>but that is about the same amount of code. 
>
>uri

Am I missing something?  Why can't (or shouldn't) he do this?
$entry =~ s/(cn[^+]+)\+([^,]+)(.*)$/$2+$1$3/;

Is it less efficient in some way?


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

Date: Mon, 31 Mar 2008 09:20:48 -0700 (PDT)
From: SecureIT <gotsecure@gmail.com>
Subject: Re: Parse x.500 DN and change order displayed
Message-Id: <abc10185-ab47-40c7-b19c-cca5d90f7b73@e39g2000hsf.googlegroups.com>

On Mar 31, 8:26=A0am, Hallvard B Furuseth <h.b.furus...@usit.uio.no>
wrote:
> SecureIT writes:
> > I am trying to change this
> > "cn=3DBob Smith+serialNumber=3DCR013120080827,o=3DICM,c=3DUS"
> > to this:
> > "serialNumber=3DCR013120080827+cn=3DBob Smith,o=3DICM,c=3DUS"
>
> Without escape sequences like "\," and "\+" in the DNs (if that's
> allowed anyway, I don't remember the details of X.500 Dn syntax), this
> moves serialNumber first in each RDN:
>
> s/(^|,)([^,]*)\+(serialNumber=3D[^+,]*)(?=3D[+,])/$1$3+$2/gi;
> die "didn't catch all 'foo+serialNumber's" if /\+serialNumber=3D/i;
>
> --
> Hallvard

That worked great, thanks so much. Just ran it and all 2000 DN's are
properly formatted now.

-G


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

Date: Mon, 31 Mar 2008 10:37:14 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <79c388ed-60e1-4ef9-9b7b-7e67f274d814@f63g2000hsf.googlegroups.com>

On Mar 30, 4:09=A0pm, jida...@jidanni.org wrote:
> Why is there no way to tell printf to zero pad like the right column:

Why do you assume that because you don't know the way, there is no
way?

> 0.1 =A0 =A0:0.100
> 0.05 =A0 :0.050
> 0.03 =A0 :0.030
> 0.025 =A0:0.025
> 0.02 =A0 :0.020
> 0.015 =A0:0.015
> 0.0125 :0.0125
> 0.01 =A0 :0.010
> 0.009 =A0:0.009
> 0.00625:0.00625
> 0.005 =A0:0.005
> The challenge: Change only the "WHAT?" below to produce the right
> column above. Thanks.
> use constant S =3D> 100000;
> for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500 ) {
> =A0 =A0 printf "%-7g:WHAT?\n", $_ / S, $_ / S;
>

%.03f

$ perl -e'printf("%.03f\n", .1)'
0.100

Paul Lalli


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

Date: Mon, 31 Mar 2008 11:05:51 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <fsr9600oi5@news2.newsguy.com>

Paul Lalli wrote:
> On Mar 30, 4:09 pm, jida...@jidanni.org wrote:
>> Why is there no way to tell printf to zero pad like the right column:
>
> Why do you assume that because you don't know the way, there is no
> way?
>
>> 0.1 :0.100
>> 0.05 :0.050
>> 0.03 :0.030
>> 0.025 :0.025
>> 0.02 :0.020
>> 0.015 :0.015
>> 0.0125 :0.0125
>> 0.01 :0.010
>> 0.009 :0.009
>> 0.00625:0.00625
>> 0.005 :0.005
>> The challenge: Change only the "WHAT?" below to produce the right
>> column above. Thanks.
>> use constant S => 100000;
>> for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500
>> ) { printf "%-7g:WHAT?\n", $_ / S, $_ / S;
>>
>
> %.03f
>
> $ perl -e'printf("%.03f\n", .1)'
> 0.100
>
> Paul Lalli

Actually that truncates to 3 decimal places, which isn't what the op 
required:

$ perl -e'printf("%.03f\n", .00625)'
0.006


See my other post for a working solution.

-- 
szr 




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

Date: Mon, 31 Mar 2008 20:12:34 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <65cnskF2faasvU3@mid.individual.net>

szr wrote:
> Paul Lalli wrote:
>>
>>%.03f
>>
>>$ perl -e'printf("%.03f\n", .1)'
>>0.100
>>
>>Paul Lalli
> 
> Actually that truncates to 3 decimal places, which isn't what the op 

s/truncates/rounds/;

> required:
> 
> $ perl -e'printf("%.03f\n", .00625)'
> 0.006

The 0 in .03 is useless.

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Mon, 31 Mar 2008 21:22:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <fsrl7t.1g0.1@news.isolution.nl>

jidanni@jidanni.org schreef:
> Why is there no way to tell printf to zero pad like the right column:
> 0.1    :0.100
> 0.05   :0.050
> 0.03   :0.030
> 0.025  :0.025
> 0.02   :0.020
> 0.015  :0.015
> 0.0125 :0.0125
> 0.01   :0.010
> 0.009  :0.009
> 0.00625:0.00625
> 0.005  :0.005

$ perl -wle'
    print "".reverse sprintf "%05.1f", "".reverse sprintf "%f", $_
        for qw/.1 .05 .03 .025 .02 .015 .0125 .01 .009 .00625 .005
1.987654321E1/
'
0.100
0.050
0.030
0.025
0.020
0.015
0.0125
0.010
0.009
0.00625
0.005
9.876543

;)

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Mon, 31 Mar 2008 21:57:23 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <65cu16F2faasvU6@mid.individual.net>

Dr.Ruud wrote:
> 
> $ perl -wle'
>     print "".reverse sprintf "%05.1f", "".reverse sprintf "%f", $_
>         for qw/.1 .05 .03 .025 .02 .015 .0125 .01 .009 .00625 .005
> 1.987654321E1/
> '
> 0.100
> 0.050
> 0.030
> 0.025
> 0.020
> 0.015
> 0.0125
> 0.010
> 0.009
> 0.00625
> 0.005
> 9.876543
> 
> ;)

And how do you deal with negative numbers and numbers >= 10? ;)

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: 31 Mar 2008 20:10:46 GMT
From: xhoster@gmail.com
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <20080331161048.920$03@newsreader.com>

jidanni@jidanni.org wrote:
> Why is there no way to tell printf to zero pad like the right column:

One reason is that what you want is ill-defined.  If we are going to tweak
sprintf to make it suit our personal preferences, I'd rather see a
conversion character that behaved just like %f if given a good number, but
returned the empty string if given either an empty string or undef (rather
than converting it to zero and then applying %f to the zero.)

> 0.1    :0.100
> 0.05   :0.050
> 0.03   :0.030
> 0.025  :0.025
> 0.02   :0.020
> 0.015  :0.015

Apparently you want to preserve non-zero digits even if that means going
beyond 3 digits right of the decimal.  But why did you stop at 4?

0.014999999999999999444888

> 0.0125 :0.0125


0.0125000000000000006938893

How many consecutive zeros or nines are needed before you decide there are
enough to ignore what is the right of them?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 31 Mar 2008 21:55:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <kmv7c5-im4.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> jidanni@jidanni.org wrote:
> > Why is there no way to tell printf to zero pad like the right column:
> 
> One reason is that what you want is ill-defined.  If we are going to tweak
> sprintf to make it suit our personal preferences, I'd rather see a
> conversion character that behaved just like %f if given a good number, but
> returned the empty string if given either an empty string or undef (rather
> than converting it to zero and then applying %f to the zero.)
> 
> > 0.1    :0.100
> > 0.05   :0.050
> > 0.03   :0.030
> > 0.025  :0.025
> > 0.02   :0.020
> > 0.015  :0.015
> 
> Apparently you want to preserve non-zero digits even if that means going
> beyond 3 digits right of the decimal.  But why did you stop at 4?
> 
> 0.014999999999999999444888
> 
> > 0.0125 :0.0125
> 
> 
> 0.0125000000000000006938893
> 
> How many consecutive zeros or nines are needed before you decide there are
> enough to ignore what is the right of them?

It appears to me the OP wants either 3 s.f. after the point or 3 places,
whichever comes out shorter. Something like

    sub fmt {
        return
            map /(\d*\.\d{3}\d*?)0*$/,
            map /(\d*\.0*[1-9]\d\d)/,
            map { sprintf "%.308f", $_ }
            @_;
    }

appears to work, but it's hardly pretty :(. The 308 is the number of
places required to represent DBL_MIN with 53-bit doubles; if your perl
is using 64-bit long doubles you will need 4932 instead.

Ben



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

Date: 31 Mar 2008 17:06:38 GMT
From: xhoster@gmail.com
Subject: Re: Sharing a DBI::Mysql database connection with your children
Message-Id: <20080331130640.144$or@newsreader.com>

Andrew DeFaria <Andrew@DeFaria.com> wrote:
>
> I have a process I was thinking of making into a multithreaded daemon
> that deals with a MySQL database. The thought is that the daemon would
> open the database once, then listen for clients. As clients connected
> the daemon would fork off a copy of itself and handle the requests. This
> would make the process faster because I wouldn't need to open the
> database every time a new client wanted service.

On my system it takes less than one millisecond to open a connection
to a MySQL server (located on a different system.)  Do you find that
connection time problematic?  This is about the same amount of time
it takes to fork in the first place.


> However, I've found that once I fork the database handle (obtained
> through DBI) is no longer valid. Reading around a little bit I noticed
> people saying to reopen or reconnect to the database in the child.

Yes, true.

> Well
> that's the very time consuming thing

I find that hard to believe.

> I was trying to avoid!
>
> Does anybody know how to open a MySQL database such that that database
> connection can be used in forked children?

I don't.  I rather doubt other people do, either.   Maybe your server
should handle requests internally rather than forking.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 31 Mar 2008 20:08:52 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Sharing a DBI::Mysql database connection with your children
Message-Id: <fsrgj3.1fk.1@news.isolution.nl>

Andrew DeFaria schreef:

> Does anybody know how to open a MySQL database such that that database
> connection can be used in forked children?

See connect_cached and Ima::DBI.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Mon, 31 Mar 2008 11:22:17 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Sharing a DBI::Mysql database connection with your children
Message-Id: <fsra4p0psh@news2.newsguy.com>

xhoster@gmail.com wrote:
> Andrew DeFaria <Andrew@DeFaria.com> wrote:
>>
>> I have a process I was thinking of making into a multithreaded daemon
>> that deals with a MySQL database. The thought is that the daemon
>> would open the database once, then listen for clients. As clients
>> connected the daemon would fork off a copy of itself and handle the
>> requests. This would make the process faster because I wouldn't need
>> to open the database every time a new client wanted service.
>
> On my system it takes less than one millisecond to open a connection
> to a MySQL server (located on a different system.)  Do you find that
> connection time problematic?  This is about the same amount of time
> it takes to fork in the first place.

Normally this would be true, if the MySQL server is on the same network, 
but if it's not, connection time depends entirely on the latency between 
the OP's running system and the MySQL server, such is the case if it is 
across the internet; it will surely take longer than a millisecond. But 
then again, that would hardly be an ideal setup, but it's not unheard 
of.

-- 
szr 




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

Date: Mon, 31 Mar 2008 22:38:52 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Windows paths in glob
Message-Id: <uii2v3lrhpuramsqooj2drjr4cmqdl6vc5@4ax.com>

Dmitry wrote:

>Question: is there any way to use the same path string with glob and with the rest of Perl, 
>without having to convert them back and forth?

Is a simple conversion acceptable?

If you put double quotes aroudn the path *in* the string for glob, then
it'll work.

    ($\, $,) = ("\n", "\t");
    chdir 'c:/temp';
    foreach('C:/Documents and Settings', 'C:\\Documents and Settings') {
         print $_, glob(qq("$_")), -d $_ || 0;
    }

Result:

    C:/Documents and Settings	C:/Documents and Settings	1
    C:\Documents and Settings	C:./Documents and Settings	1

Well, ok... the response of glob to a backslash *is* weird. But at
least, it seems to  work.

-- 
	Bart.


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

Date: Mon, 31 Mar 2008 21:57:55 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Windows paths in glob
Message-Id: <jrv7c5-im4.ln1@osiris.mauzo.dyndns.org>


Quoth Bart Lateur <bart.lateur@pandora.be>:
> 
> Result:
> 
>     C:/Documents and Settings	C:/Documents and Settings	1
>     C:\Documents and Settings	C:./Documents and Settings	1
> 
> Well, ok... the response of glob to a backslash *is* weird. But at
> least, it seems to  work.

Not just weird: wrong. Win32 has a notion of 'current directory on a
given drive'; C:./Documents and Settings is a path relative to the
current directory on drive C:. 

Ben



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

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


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