[30296] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1539 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 13 11:09:47 2008

Date: Tue, 13 May 2008 08:09:12 -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           Tue, 13 May 2008     Volume: 11 Number: 1539

Today's topics:
    Re: code written under 5.10.0 to be run under 5.8.8 dummy@phony.info
    Re: code written under 5.10.0 to be run under 5.8.8 <abigail@abigail.be>
    Re: code written under 5.10.0 to be run under 5.8.8 <abigail@abigail.be>
        Constants across package boundaries bernie@fantasyfarm.com
    Re: Constants across package boundaries <joost@zeekat.nl>
    Re: Constants across package boundaries bernie@fantasyfarm.com
    Re: Constants across package boundaries bernie@fantasyfarm.com
    Re: Constants across package boundaries <tzz@lifelogs.com>
    Re: Constants across package boundaries <ben@morrow.me.uk>
    Re: Constants across package boundaries <ThomasKratz@REMOVEwebCAPS.de>
    Re: Constants across package boundaries <1usa@llenroc.ude.invalid>
    Re: FAQ 4.47 How do I handle circular lists? sheinrich@my-deja.com
    Re: FAQ 4.47 How do I handle circular lists? <brian.d.foy@gmail.com>
    Re: FAQ 4.47 How do I handle circular lists? <szrRE@szromanMO.comVE>
    Re: FAQ 4.47 How do I handle circular lists? <someone@example.com>
    Re: Get variable from its name string or vice versa? jerrykrinock@gmail.com
        How to pass around an Array of Arrays (or Array Refs) jerrykrinock@gmail.com
    Re: How to pass around an Array of Arrays (or Array Ref <joost@zeekat.nl>
        Newsgroup Markup. Was Re: Perl DBI Module: SQL query wh <RedGrittyBrick@SpamWeary.foo>
    Re: Perl DBI Module: SQL query where there is space in  <RedGrittyBrick@SpamWeary.foo>
    Re: Perl DBI Module: SQL query where there is space in  <szrRE@szromanMO.comVE>
    Re: Selected cipher type not supported by server <smallpond@juno.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 13 May 2008 02:13:54 -0700
From: dummy@phony.info
Subject: Re: code written under 5.10.0 to be run under 5.8.8
Message-Id: <6lji24t5t16slm5k2stliv4qs4i1rkg7tg@4ax.com>

On 12 May 2008 18:37:29 GMT, Abigail <abigail@abigail.be> wrote:

>                                             _
>dummy@phony.info (dummy@phony.info) wrote on VCCCLXVII September MCMXCIII
>in <URL:news:0gqc245d164jqt67qo69ho0lif7i1f7clv@4ax.com>:
><>  I understand that one can specify that a script must be run under a perl
><>  version no earlier than a particular version.  So, if I say 'use 5.6.0',
><>  that code will throw an error if one tries to run it under perl 5.5.0,
><>  right?
><>  
><>  But how about the reverse case?
>
>The reverse case is pretty easy:
>
>    BEGIN {
>        die "Your Perl version is too new" if $] > 5.008008;
>    }

Not what I meant. That would prevent me from doing the development on
the desktop, using 5.10.0, defeating my intent.

BTW, beginning with 5.10.0 one can say "no someversion", which might
someday be of some use, but not now.  It throws an error in 5.10.0,
since 5.10.0 is too new, and it throws an error in every other version
too, since it's not recognized.  One could say "no 5.10.2", and that
would throw an error if someday 5.10.2 were installed, forcing you to
delete the "no 5.10.2".  But what good could that possibly be?


>
><>  Suppose I write code on my desktop, which has perl 5.10.0 installed, and
><>  later transfer that code to a system that only has perl as far as 5.8.8.
><>  How can I cause an error on the desktop if I accidentally use any of the
><>  new features of 5.10.0, as I would want to do to signal incompatibility?
>
>That's not the reverse case.

You are right, sorry.

>
><>  Is this sort of thing impossible?
>
>
>Basically, yes. There are some new features that aren't available unless
>turned on explicitely, but that isn't the case for features that will not
>cause any backwards compatability issues. For instance, there are a ton of
>new features when using regexpes, and you get them regardless whether you
>use "use feature" or not. Furthermore, bug fixes will be there as well, and
>so will any modules that are in 5.010, but not in an older install of Perl.
>
>The best way to avoid accidentily using features that aren't available on
>older Perl is to install the oldest Perl you want to develop for, and test
>with that.

I was afraid of that.  I sure don't want to go back to Active State, and
strawberry is not available with older versions.




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

Date: 13 May 2008 10:26:26 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: code written under 5.10.0 to be run under 5.8.8
Message-Id: <slrng2ir6i.8ob.abigail@alexandra.abigail.be>

                                             _
dummy@phony.info (dummy@phony.info) wrote on VCCCLXIX September MCMXCIII
in <URL:news:6lji24t5t16slm5k2stliv4qs4i1rkg7tg@4ax.com>:
__  
__  I was afraid of that.  I sure don't want to go back to Active State, and
__  strawberry is not available with older versions.


Then you may have to compile it yourself.


Abigail
-- 
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'


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

Date: 13 May 2008 10:31:32 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: code written under 5.10.0 to be run under 5.8.8
Message-Id: <slrng2irg4.8ob.abigail@alexandra.abigail.be>

                                                           _
Sir Robin (robsku@NO-SPAM-REMOVE-THIS.fiveam.org) wrote on VCCCLXIX
September MCMXCIII in <URL:news:e6qh245fdrv2vsvr2l7sfo9fstljsluqtt@4ax.com>:
,,  On Mon, 12 May 2008 12:51:25 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at>
,,  wrote:
,,  
,, >On 2008-05-12 08:45, Sir Robin <robsku@NO-SPAM-REMOVE-THIS.fiveam.org> wrote:
,, >> On Sun, 11 May 2008 11:06:21 +0000 (UTC), Ben Bullock
,, >><benkasminbullock@gmail.com> wrote:
,, >>>I believe the new features are all turned off by default anyway, so you 
,, >>>have to "use 5.010;" anyway:
,, >>
,, >> On what versions of perl5 do you believe has new features off by default?
,, >
,, >In 5.10 you have to explicitely enable new features by adding a
,, >"use 5.010;" line.
,,  
,,  Too bad that they didn't come up with this, hmm, let's say somewhere around
,,  when 5.6.x came,

But 5.6.x didn't come with new keywords that could conflict with a possibly
choosen user defined subroutine. That's why 5.010 has "use feature", to turn
specific features that could break backwards compatability. 

,,                   that would have resulted in all my perl code beeing certain
,,  working with the version mentioned with 'use' - because now that I have give
,,  thought to it I am quite confident on one single thing of this subject and
,,  that is I started with perl 5.6.x, so... So having now checked "Whats New in
,,  5.6.0" list of new stuff I'd say that if  I one day install couple older
,,  versions of perl5 to examine if my scripts/apps needs newer version than
,,  whatever I have I pretty much know that theres not much point to test most o
,,  the scripts with anythin before 5.6.0.. well at least not much before.


You are misunderstanding "use feature". 5.010 came with a ton of new
features that will be there regardless of whether you use "use feature"
or not. Out of the many new features, only three of them require "use
feature" (or "use 5.010").



Abigail
-- 
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: Tue, 13 May 2008 05:36:40 -0700 (PDT)
From: bernie@fantasyfarm.com
Subject: Constants across package boundaries
Message-Id: <85c5f60e-9834-43d0-8d8b-9d955c663db0@c58g2000hsc.googlegroups.com>

I've been chasing a compile problem  and I just saw the light on what
my trouble is: I use a bunch of "use constant this => ...; use
constant that =>...;" to set parameters for the program.  BUT: the
program uses a 'package' or two [it has a small embedded objects in
it].  The trouble is that the package can't access the 'constant' --
that section of the program gets [not surprisingly] bareword errors.
I can fix them by using "main::..." but that's really ugly.  Is there
any really clean way to set up truly "global" constants?  Thanks!

  /Bernie\


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

Date: Tue, 13 May 2008 15:02:23 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Constants across package boundaries
Message-Id: <87ve1is6g0.fsf@zeekat.nl>

bernie@fantasyfarm.com writes:

> I've been chasing a compile problem  and I just saw the light on what
> my trouble is: I use a bunch of "use constant this => ...; use
> constant that =>...;" to set parameters for the program.  BUT: the
> program uses a 'package' or two [it has a small embedded objects in
> it].  The trouble is that the package can't access the 'constant' --
> that section of the program gets [not surprisingly] bareword errors.
> I can fix them by using "main::..." but that's really ugly.  Is there
> any really clean way to set up truly "global" constants?  Thanks!

I think you'd rather just export the constants to any package that
needs them, instead of making them truly global (which would be more
or less equivalent to exporting them to *all* packages)

See perldoc Exporter.



-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Tue, 13 May 2008 06:50:30 -0700 (PDT)
From: bernie@fantasyfarm.com
Subject: Re: Constants across package boundaries
Message-Id: <f2695dae-583c-4464-abd3-193c48501019@d77g2000hsb.googlegroups.com>

On May 13, 9:02=A0am, Joost Diepenmaat <jo...@zeekat.nl> wrote:
> ber...@fantasyfarm.com writes:
> > I've been chasing a compile problem =A0and I just saw the light on what
> > my trouble is: I use a bunch of "use constant this =3D> ...; use
> > constant that =3D>...;" to set parameters for the program. =A0BUT: the
> > program uses a 'package' or two [it has a small embedded objects in
> > it].

I note that this is documented on the 'constant' man page.  Sigh.  I
guess I could just use ::THIS and ::that but that feels a bit
inelegant...

> I think you'd rather just export the constants to any package that
> needs them, instead of making them truly global (which would be more
> or less equivalent to exporting them to *all* packages)

Can you export from main *to* a package?  Using Exporter in this way
looks like it is a little confusing (it might become clearer after
another six readings of the man page..:o)).  I guess I could do
something along the lines of putting require Exporter in my main
program, setting up @EXPORT_OK in the main program the "constants" I
want the interior packages to be able to import, and then do
a ::import(stuff I need) after the 'package' for the interior object-
section?  You're right: that kind of approach would make the interior
packages be more self-contained and clearer (by making explicit that
they're pulling in those vbls from "main::")

OTOH, I see that there's a "Readonly" package that looks like it will
do what I was originally trying to do ["Readonly \my $CONST =3D> val"
generates a real cross-package constant].  [although now that I see a
way to do what I originally wanted, I'm not so sure it is as clean a
way to go as I'd like...:(]

Thanks...

  /Bernie\


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

Date: Tue, 13 May 2008 07:01:59 -0700 (PDT)
From: bernie@fantasyfarm.com
Subject: Re: Constants across package boundaries
Message-Id: <74550d38-2139-4032-a7a8-40a491034533@c58g2000hsc.googlegroups.com>

On May 13, 9:50=A0am, ber...@fantasyfarm.com wrote:
> On May 13, 9:02=A0am, Joost Diepenmaat <jo...@zeekat.nl> wrote:

> > I think you'd rather just export the constants to any package that
> > needs them, instead of making them truly global (which would be more
> > or less equivalent to exporting them to *all* packages)

>... =A0I guess I could do
> something along the lines of putting require Exporter in my main
> program, setting up @EXPORT_OK in the main program the "constants" I
> want the interior packages to be able to import, and then do
> a ::import(stuff I need) after the 'package' for the interior object-
> section?

I'm running down this path to see how it looks and feels to properly
export and import my "global" constants.  And I've run into a
problem.  The man page for Exporter says:

    package YourModule;
    use Exporter 'import'; # gives you Exporter's import() method
directly
    @EXPORT_OK =3D qw(munge frobnicate);  # symbols to export on request

But in my code I have:
--------------------------
#!/usr/bin/perl

use strict ;
use warnings ;

use Exporter 'import' ;
our @ISA =3D qw(Exporter);
use constant AAA =3D> 4 ;
our @EXPORT_OK =3D ('AAA') ;
----------------------------

"import" is not exported by the Exporter module at test.pl line 6

I can't figure out quite what I'm doing wrong...  And then I'm
guessing that down in the program in my package I'd do:
   package MYPACKAGE;
   ::import(qw(constants I want))

  /Bernie\


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

Date: Tue, 13 May 2008 09:07:33 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Constants across package boundaries
Message-Id: <86k5hypaai.fsf@lifelogs.com>

On Tue, 13 May 2008 05:36:40 -0700 (PDT) bernie@fantasyfarm.com wrote: 

b> I've been chasing a compile problem  and I just saw the light on what
b> my trouble is: I use a bunch of "use constant this => ...; use
b> constant that =>...;" to set parameters for the program.  BUT: the
b> program uses a 'package' or two [it has a small embedded objects in
b> it].  The trouble is that the package can't access the 'constant' --
b> that section of the program gets [not surprisingly] bareword errors.
b> I can fix them by using "main::..." but that's really ugly.  Is there
b> any really clean way to set up truly "global" constants?  Thanks!

This may be possible with some advanced wizardry or source filtering.
You could also fake it like this:

#!/usr/bin/perl

use warnings;
use strict;

use constant GLOBAL => 'global';

package test;

use constant LOCAL => main::GLOBAL; # can also be called GLOBAL

print LOCAL, "\n";

but it's probably easiest if you set up a 'constants' package that
exports the right things, and import it into each package that needs it.

I'm sure there's better ways :)

Ted


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

Date: Tue, 13 May 2008 15:26:59 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Constants across package boundaries
Message-Id: <j2lof5-u0v.ln1@osiris.mauzo.dyndns.org>


Quoth bernie@fantasyfarm.com:
> On May 13, 9:50 am, ber...@fantasyfarm.com wrote:
> > On May 13, 9:02 am, Joost Diepenmaat <jo...@zeekat.nl> wrote:
> 
> > > I think you'd rather just export the constants to any package that
> > > needs them, instead of making them truly global (which would be more
> > > or less equivalent to exporting them to *all* packages)
> 
> >...  I guess I could do
> > something along the lines of putting require Exporter in my main
> > program, setting up @EXPORT_OK in the main program the "constants" I
> > want the interior packages to be able to import, and then do
> > a ::import(stuff I need) after the 'package' for the interior object-
> > section?

It's probably a bad idea to export from main::. I'd define a separate
package for your constants, and 'use' it from everywhere else.

> I'm running down this path to see how it looks and feels to properly
> export and import my "global" constants.  And I've run into a
> problem.  The man page for Exporter says:
> 
>     package YourModule;
>     use Exporter 'import'; # gives you Exporter's import() method
> directly
>     @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request
> 
> But in my code I have:
> --------------------------
> #!/usr/bin/perl
> 
> use strict ;
> use warnings ;
> 
> use Exporter 'import' ;
> our @ISA = qw(Exporter);
> use constant AAA => 4 ;
> our @EXPORT_OK = ('AAA') ;
> ----------------------------
> 
> "import" is not exported by the Exporter module at test.pl line 6

Does the manpage you're using match your version of Exporter? The
ability to import (rather than inherit) Exporter::import was not present
in older versions of Exporter.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                               Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Tue, 13 May 2008 16:59:30 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Constants across package boundaries
Message-Id: <4829acd2$0$2649$bb690d87@news.main-rheiner.de>

bernie@fantasyfarm.com wrote:
> I've been chasing a compile problem  and I just saw the light on what
> my trouble is: I use a bunch of "use constant this => ...; use
> constant that =>...;" to set parameters for the program.  BUT: the
> program uses a 'package' or two [it has a small embedded objects in
> it].  The trouble is that the package can't access the 'constant' --
> that section of the program gets [not surprisingly] bareword errors.
> I can fix them by using "main::..." but that's really ugly.  Is there
> any really clean way to set up truly "global" constants?  Thanks!

Not clean nor elegant but works for simple (not array or hash) constants 
by feeding the constants from main again to 'use constants':

test.pl:

  use strict;
  use warnings;
  use constant BLA => 5;
  use Mod;
  print Mod::Sub1();

Mod.pm

  package Mod;
  use strict;
  use warnings;

  my %const;
  BEGIN {
     %const = map {
         (my $name = $_) =~ s/^main:://;
         no strict 'refs';
         $name => &$_();
     } grep {
         /^main::/
     } keys %constant::declared;
  }

  use constant \%const;

  sub Sub1 { return BLA; }

  1;

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Tue, 13 May 2008 14:59:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Constants across package boundaries
Message-Id: <Xns9A9D6FDB75BBBasu1cornelledu@127.0.0.1>

bernie@fantasyfarm.com wrote in news:85c5f60e-9834-43d0-8d8b-
9d955c663db0@c58g2000hsc.googlegroups.com:

> I've been chasing a compile problem  and I just saw the light on what
> my trouble is: I use a bunch of "use constant this => ...; use
> constant that =>...;" to set parameters for the program.  BUT: the
> program uses a 'package' or two [it has a small embedded objects in
> it].  The trouble is that the package can't access the 'constant' --
> that section of the program gets [not surprisingly] bareword errors.
> I can fix them by using "main::..." but that's really ugly.  Is there
> any really clean way to set up truly "global" constants?  Thanks!

The proper way to do this would be to set up a package for all your 
constants and use it from any file that needs any of those constants.

Keep in mind that constants defined using the constant pragma are not 
variables but subroutines.

In any case, here is how to do it:

E:\Home\asu1\Src\Test> cat My\Constants.pm
package My::Constants;

use strict;
use warnings;

use base qw( Exporter );

our @EXPORT = qw();
our @EXPORT_OK = qw( ONE TWO THREE );

use constant ONE => 'one';
use constant TWO => 'two';
use constant THREE => 'three';

1;

E:\Home\asu1\Src\Test> cat My\Util.pm
package My::Util;

use strict;
use warnings;

use My::Constants qw( ONE TWO THREE );

sub some_func { join( "\t", ONE, TWO, THREE ) }

1;

E:\Home\asu1\Src\Test> cat C.pl
#!/usr/bin/perl

use strict;
use warnings;

use My::Constants qw( ONE TWO THREE );
use My::Util;

print "$_\n" for ONE, TWO, THREE, My::Util::some_func;

__END__

E:\Home\asu1\Src\Test> C
one
two
three
one     two     three


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 13 May 2008 01:35:52 -0700 (PDT)
From: sheinrich@my-deja.com
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <437ac873-a0a5-4186-8f3d-fdb7a14d98de@k37g2000hsf.googlegroups.com>

On May 12, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> --------------------------------------------------------------------
>
> 4.47: How do I handle circular lists?
>
>     Circular lists could be handled in the traditional fashion with linked
>     lists, or you could just do something like this with an array:
>
>             unshift(@array, pop(@array));  # the last shall be first
>             push(@array, shift(@array));   # and vice versa
>
>

As the modulo operator provides a simple way to address an array in a
circular fashion, which is maybe not obvious to the less experienced,
I think it should be mentioned here.

my @Colours = qw( FFFFFF 000000 FFFF00 );

my $asize = @Colours;
my $index = 0;

for (1..10) {
  print $Colours[$index], "\n";

  $index = ++$index % $asize;
}

# or shorter, with an ever growing $index though:

$index = 0;

for (1..10) {
  print $Colours[$index++ % $asize], "\n";
}


steffen



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

Date: Tue, 13 May 2008 10:51:28 +0200
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <130520081051284596%brian.d.foy@gmail.com>

In article
<437ac873-a0a5-4186-8f3d-fdb7a14d98de@k37g2000hsf.googlegroups.com>,
<sheinrich@my-deja.com> wrote:

> On May 12, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> > --------------------------------------------------------------------
> >
> > 4.47: How do I handle circular lists?
> >
> >     Circular lists could be handled in the traditional fashion with linked
> >     lists, or you could just do something like this with an array:
> >
> >             unshift(@array, pop(@array));  # the last shall be first
> >             push(@array, shift(@array));   # and vice versa
> >
> >
> 
> As the modulo operator provides a simple way to address an array in a
> circular fashion, which is maybe not obvious to the less experienced,
> I think it should be mentioned here.

That's a good idea. I should also mention Tie::Cycle.

I'll update the answer. Thanks. :)


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

Date: Tue, 13 May 2008 06:06:03 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <g0c3nr01loe@news4.newsguy.com>

brian d foy wrote:
> In article
> <437ac873-a0a5-4186-8f3d-fdb7a14d98de@k37g2000hsf.googlegroups.com>,
> <sheinrich@my-deja.com> wrote:
>
>> On May 12, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>>> --------------------------------------------------------------------
>>>
>>> 4.47: How do I handle circular lists?
>>>
>>>     Circular lists could be handled in the traditional fashion with
>>>     linked lists, or you could just do something like this with an
>>> array:
>>>
>>>             unshift(@array, pop(@array));  # the last shall be first
>>>             push(@array, shift(@array));   # and vice versa
>>>
>>>
>>
>> As the modulo operator provides a simple way to address an array in a
>> circular fashion, which is maybe not obvious to the less experienced,
>> I think it should be mentioned here.
>
> That's a good idea. I should also mention Tie::Cycle.
>
> I'll update the answer. Thanks. :)

Tie::Cycle /is/ mentioned in this FAQ  :-)

-- 
szr 




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

Date: Tue, 13 May 2008 13:11:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: FAQ 4.47 How do I handle circular lists?
Message-Id: <7sgWj.2370$KB3.305@edtnps91>

sheinrich@my-deja.com wrote:
> On May 12, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>> --------------------------------------------------------------------
>>
>> 4.47: How do I handle circular lists?
>>
>>     Circular lists could be handled in the traditional fashion with li=
nked
>>     lists, or you could just do something like this with an array:
>>
>>             unshift(@array, pop(@array));  # the last shall be first
>>             push(@array, shift(@array));   # and vice versa
>>
>>
>=20
> As the modulo operator provides a simple way to address an array in a
> circular fashion, which is maybe not obvious to the less experienced,
> I think it should be mentioned here.
>=20
> my @Colours =3D qw( FFFFFF 000000 FFFF00 );
>=20
> my $asize =3D @Colours;
> my $index =3D 0;
>=20
> for (1..10) {
>   print $Colours[$index], "\n";
>=20
>   $index =3D ++$index % $asize;

perldoc perlop

[ SNIP ]

     Note that just as in C, Perl doesn=92t define when the variable is
     incremented or decremented. You just know it will be done sometime
     before or after the value is returned. This also means that
     modifying a variable twice in the same statement will lead to
     undefined behaviour.  Avoid statements like:

         $i =3D $i ++;
         print ++ $i + $i ++;

     Perl will not guarantee what the result of the above statements is.


So don't do that.  Do this instead:

   $index =3D ( $index + 1 ) % $asize;



John
--=20
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 13 May 2008 07:39:17 -0700 (PDT)
From: jerrykrinock@gmail.com
Subject: Re: Get variable from its name string or vice versa?
Message-Id: <2246bafd-a4db-4493-a7f2-3ac8a9d24998@l64g2000hse.googlegroups.com>

On May 10, 11:31 am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:

> I think what is needed in this case a macro, not a subroutine...
> Macros are not part of perl per se, but can be implemented via source
> filters. It shouldn't be too hard to write a filter like that.
>
Thank you, Peter.  Indeed I do want a preprocessor macro, but I was
not aware that perl's preprocessor macros were called filters
(perlfilter).

> But it happens that Damian Conway already wrote one which might do what
> the OP wants: Smart::Comments.

Well, I want something which will log to the same file as Log::StdLog
does, so I wrote my own.  It's got some rough edges and a kludge or
two, but it works and does not use any of the black magic.  Here it
is.  Thanks again for the help...

package LogVar ;

use Filter::Util::Call;

sub import {
  my ($type) = @_;
  my ($ref) = [];
  filter_add(bless $ref);
}

sub filter {
    my ($self) = @_;
    my ($status);
    if (($status = filter_read()) > 0) {
        # Substitute for the one-argument version, LogVar(varName)
        s /LogVar[\s]*\([\s]*(\$|\@|\%)([\w]+)[\s]*\)/doLogVar($2,
$1$2, info)/ ;

        # Substitute for the two-argument version, LogVar(varName,
level),
        # when the level is 'warn'.
        # The 'warn' has to be treated specially because 'warn' is
        # also a predefined function in perl and really weird things
        # happen if I don't do this
        s /LogVar[\s]*\([\s]*(\$|\@|\%)([\w]+),[\s]*warn[\s]*\)/
doLogVarWarn($2, $1$2)/ ;

        # Substitute for the two-argument version, LogVar(varName,
level)
        # for other levels
        s /LogVar[\s]*\([\s]*(\$|\@|\%)([\w]+),[\s]*([\w]+)[\s]*\)/
doLogVar($2, $1$2, $3)/ ;

        # Now, heres the tricky part.  I need to define the functions
        # doLogVar, doLogVarWarn (and makeDefined, which they call).
        # For some reasons which I don't understand,
        # (1) If I simply define sub doLogVar in this module, it is
        #     "not found" when it runs from the host program file.
        # (2) If I change the calls to "LogVar::doLogVar", then it
runs,
        #     but nothing gets logged
        # So, my workaround for these two problems is to add the
placeholder
        #     use logVarFunctions
        # to the main program file and then replace it with the
function
        # definitions using the following s///, except s''' is used
to
        # avoid variable interpolations.
        # This also has the advantage of using the same Log::StdLog
        # initialization and thus the same level that is used in the
main
        # program file.
        s 'use[\s]*LogVarFunctions[\s]*;'
        sub makeDefined {
            my $var_ref = shift ;
            if (!defined($$var_ref)) {
            $$var_ref = "<undefined>" ;
                }
        }

        sub doLogVar {
            my $varName = shift ;
            my $varValue = shift ;
            my $level = shift ;
            makeDefined(\$varValue) ;
            my $msg = sprintf ("%24s: %s\n", $varName, $varValue) ;
            print {*STDLOG} $level => $msg ;
        }

        sub doLogVarWarn {
            my $varName = shift ;
            my $varValue = shift ;
            makeDefined(\$varValue) ;
            my $msg = sprintf ("%24s: %s\n", $varName, $varValue) ;
            print {*STDLOG} \'warn\' => $msg ;
        }
        '

    }
  $status;
}


1;

__END__

=head1 NAME

LogVar - Logs variable name and value using Log::StdLog

=head1 SYNOPSIS

    # Your program file must be using Log::StdLog and
    # have initialized it with a level.

    # Both of these are necessary
    use LogVar ;
    use LogVarFunctions ;

    my $myVar = 5 ;

    # Log to Log::StdLog at default level 'info'
    LogVar($myVar) ;

    # Log to Log::StdLog at some other level
    LogVar($myVar, trace) ;
    LogVar($myVar, debug) ;
    # ...
    LogVar($myVar, none) ;


=head1 DESCRIPTION

This module provides a perl filter (see perlfilter), which is a
preprocessor.
It provides the macro LogVar() which extracts the variable name from
the
first argument and logs the variable name and value to the file
designated
in Log::StdLog, producing lines that are nicely aligned like this:

             $myVar: 5
              $name: Jerry
            $weight: 150.3




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

Date: Tue, 13 May 2008 07:56:39 -0700 (PDT)
From: jerrykrinock@gmail.com
Subject: How to pass around an Array of Arrays (or Array Refs)
Message-Id: <14236a89-69f8-4b1a-bf24-095e9cd0db9d@p25g2000hsf.googlegroups.com>

I need to pass an array of arrays from a function, but I can't make an
array of arrays work.  Actually, I've got better results making an
array of array references.  Here's what I've done:

#!/usr/bin/perl

my @array ;
my @row ;
@row = ('a00', 'a01') ;
push (@array, \@row) ;
@row = ('a10', 'a11') ;
push (@array, \@row) ;
@row = ('a20', 'a21') ;
push (@array, \@row) ;

# In real life I will return @array to the caller, but the
# problem can be demonstrated without doing that...

my $nRows = @array ;
foreach my $array_ref (@array) {
    # $array_ref is a reference to an array (row)
    # Dereference it.
    my @row = @$array_ref ;
    # Print each element (column) separated by spaces
    foreach my $element (@row) {
        print "$element    ";
    }
    # Next row, new line
    print "\n" ;
}

My expected result is:

    a00    a01
    a10    a11
    a20    a21

but the actual result is:

    a20    a21
    a20    a21
    a20    a21

What am I doing wrong?

Thanks,

Jerry Krinock


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

Date: Tue, 13 May 2008 17:02:30 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: How to pass around an Array of Arrays (or Array Refs)
Message-Id: <87mymuqmbd.fsf@zeekat.nl>

jerrykrinock@gmail.com writes:

> I need to pass an array of arrays from a function, but I can't make an
> array of arrays work.  Actually, I've got better results making an
> array of array references.  Here's what I've done:
>
> #!/usr/bin/perl
>
> my @array ;
> my @row ;
> @row = ('a00', 'a01') ;
> push (@array, \@row) ;
> @row = ('a10', 'a11') ;
> push (@array, \@row) ;
> @row = ('a20', 'a21') ;
> push (@array, \@row) ;

 <snip>

> What am I doing wrong?

You're reusing the same array for each row; each row is a reference to
the same array (@row), which means you end up with each row containing
the values you last assigned to @row.

You want something like:

 my @array ;
 my @row ;
 @row = ('a00', 'a01') ;
 push (@array, [ @row ]);   # [ @row ] creates a reference to a new array
                            # with copies of the values in @row.
 @row = ('a10', 'a11') ;
 push (@array, [ @row ]);
 @row = ('a20', 'a21') ;
 push (@array, [ @row ]);


or less ugly:

 my @array = ( [ 'a00', 'a01' ],
               [ 'a10', 'a11' ] );

 push @array, ['a20','a21'];


-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Tue, 13 May 2008 14:49:42 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Newsgroup Markup. Was Re: Perl DBI Module: SQL query where there is space in field name
Message-Id: <48299c79$0$10632$fa0fcedb@news.zen.co.uk>

Newsgroup Markup?
=================

Structured Text
---------------

  "l) I'd prefer plain text markup of the sort used by GrutaTxt or
  ASCIIDOC but simplified. That way I could embed tables that work well
  in plain-text newsreaders but would also look pretty in any
  newsreader that supported that format." - RGB

  "That would be nice, but wouldn't you have the same battle on your hands
  that those pushing html currently do?" - szr

A battle sure, but a different one:

  * Structured text mark-up is, IMO, perfectly acceptable
    to existing newsreader software and users.
  * I can't imagine how to get a standard agreed though.


Candidates
----------

Here's a few structured text formats in no particular order.

+----------+------------------------------------------------------+
| Grutatxt | http://www.triptico.com/software/grutatxt.html       |
|          | (the Grutatxt home page                              |
+----------+------------------------------------------------------+
| ASCIIDOC | http://www.methods.co.nz/asciidoc/                   |
+----------+------------------------------------------------------+
| STX2Any  | http://www.sange.fi/~atehwa/cgi-bin/piki.cgi/stx2any |
+----------+------------------------------------------------------+

The last reference above lists lots of others in the same vein.

A problem, in my view, is that some of these depart too far from the 
idea of a mark-up that looks almost exactly like plain text.


Afterword
---------

This posting is written in a form compatible with Grutatxt. In theory a 
newreader could render it with the headings in various fonts and sizes, 
with the bullet lists shown with proper bullet characters and with the 
tables displayed in some more pleasing form..

Is there any anti-HTML-in-newsgroups reader out there who finds the 
formatting and markup of this posting really objectionable?

-- 
RGB

P.S. Yes I know this has a snowball's chance in hell. Treat it as 
whimsey. I'd prefer it to HTML though.


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

Date: Tue, 13 May 2008 12:35:32 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Perl DBI Module: SQL query where there is space in field name
Message-Id: <48297d08$0$10647$fa0fcedb@news.zen.co.uk>

szr wrote:
> Sir Robin wrote:
>> On Sat, 10 May 2008 12:23:46 -0700, Andrew DeFaria
>> <Andrew@DeFaria.com> wrote:
>>
> [...]
>> And there is no reason whatsoever why a newsreader should need to be
>> able to handle HTML
> 
> What reason is there not to, to be honest? 

Ooh, here's a few off the top of my head ...

a) There's no single thing called HTML.
HTML 3.2?
HTML 3.2 with IE5 quirks?
 ...
HTML 4.0?
XHTML?
CSS1?
CSS2?
HTML 5?

b) At the moment, presence of HTML is a useful indication of SPAM.

c) Widespread adoption of (some variants of) HTML might end with many 
posts omitting any plain-text alternative parts. This might balkanise 
newsgroups.

d) Why not some other XML application like, oh, DocBook. Or maybe some
new NewsGroup-article DTD?

e) Why not RTF, PDF or ODF?

f) What if I want to read newsgroups on my phone or PDA using a 
low-speed Internet link - maybe bandwidth would be an issue for 
image-rich HTML or other formats.

g) All too often I receive a word .DOC that contains just a 1 page 
meeting agenda in two fonts (title & body) - It just makes an extra slow 
step to fire up Word to view an attachment when the content would lose 
nothing from being presented as plain text. Why encourage unecessary 
complexity.

h) The same reason I don't meed a surround-sound video-telephone when 
phoning a fried for advice about Java.

i) The same reasons colour newspapers never completely rerplaced black 
and white newspapers I suppose.

j) The same reason Gutenberg's Bible is a superior example of 
information publishing. I'm sure that neither it's aesthetics nor it's 
information content would be enhanced by use of <blink> and <marquee>.

k) Do you need me to add multiple fonts, tables, bullet lists etc to the 
above to make it intelligible? (If I can't write plain text clearly, 
what hope do I have with multi-coloured animated ransom note typography?)

l) I'd prefer plain text markup of the sort used by GrutaTxt or ASCIIDOC 
but simplified. That way I could embed tables that work well in 
plain-text newsreaders but would also look pretty in any newsreader that 
supported that format.

Just my GBP 0.02 worth. Your Mileage Will Vary.

-- 
RGB


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

Date: Tue, 13 May 2008 05:58:42 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Perl DBI Module: SQL query where there is space in field name
Message-Id: <g0c3a201ksa@news4.newsguy.com>

RedGrittyBrick wrote:
> szr wrote:
>> Sir Robin wrote:
>>> On Sat, 10 May 2008 12:23:46 -0700, Andrew DeFaria
>>> <Andrew@DeFaria.com> wrote:
>>>
>> [...]
>>> And there is no reason whatsoever why a newsreader should need to be
>>> able to handle HTML
>>
>> What reason is there not to, to be honest?
>
> Ooh, here's a few off the top of my head ...
>
> a) There's no single thing called HTML.
> HTML 3.2?
> HTML 3.2 with IE5 quirks?
> ...
> HTML 4.0?
> XHTML?
> CSS1?
> CSS2?
> HTML 5?

True.

> b) At the moment, presence of HTML is a useful indication of SPAM.

Based on what? Most spam that I see in any news group tends to be almost 
always plain text (not multipart, but plain ony.) In all honesty it 
seems UseNet spam is hardly ever in HTML.

> c) Widespread adoption of (some variants of) HTML might end with many
> posts omitting any plain-text alternative parts. This might balkanise
> newsgroups.

Agreed that this would not be good.

> d) Why not some other XML application like, oh, DocBook. Or maybe some
> new NewsGroup-article DTD?
>
> e) Why not RTF, PDF or ODF?

I would say probably the same reason they aren't used to create web 
pages en masse either.

> f) What if I want to read newsgroups on my phone or PDA using a
> low-speed Internet link - maybe bandwidth would be an issue for
> image-rich HTML or other formats.

Which is why it would need to be crucial to have plain text versions. 
Admittedly that would only really work if there were some way a reader 
could ask the /server/ for /just/ the plain version.

> g) All too often I receive a word .DOC that contains just a 1 page
> meeting agenda in two fonts (title & body) - It just makes an extra
> slow step to fire up Word to view an attachment when the content
> would lose nothing from being presented as plain text. Why encourage
> unecessary complexity.

Agreed.

> h) The same reason I don't meed a surround-sound video-telephone when
> phoning a fried for advice about Java.

I'm going to assume you means "friend", otherwise that brings some 
rather gruesome images to mind :-)

> i) The same reasons colour newspapers never completely rerplaced black
> and white newspapers I suppose.

I'm not sure what you mean? Any modern news paper I've seen usually have 
color images and trim on the fronts and back and white inside.

> j) The same reason Gutenberg's Bible is a superior example of
> information publishing. I'm sure that neither it's aesthetics nor it's
> information content would be enhanced by use of <blink> and <marquee>.
>
> k) Do you need me to add multiple fonts, tables, bullet lists etc to
> the above to make it intelligible? (If I can't write plain text
> clearly, what hope do I have with multi-coloured animated ransom note
> typography?)

I think the arguement was using "multiple fonts, tables, bullet lists 
etc" as a visual aid, but I see your point.

> l) I'd prefer plain text markup of the sort used by GrutaTxt or
> ASCIIDOC but simplified. That way I could embed tables that work well
> in plain-text newsreaders but would also look pretty in any
> newsreader that supported that format.


That would be nice, but wouldn't you have the same battle on your hands 
that those pushing html currently do?

-- 
szr 




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

Date: Tue, 13 May 2008 10:51:16 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: Selected cipher type not supported by server
Message-Id: <c6519$4829aae7$11796@news.teranews.com>

lovecreatesbea...@gmail.com wrote:
> On May 9, 11:59 pm, smallpond <smallp...@juno.com> wrote:
> 
>>lovecreatesbea...@gmail.com wrote:
>>
>>>I manually ssh login the host and check the version. Is OpenSSH_4.6p1
>>>an SSH1 or SSH2 implementation, or both?
>>
>>The rule when you don't know what's wrong is to step back to the
>>earliest place that you get an error.
>>
>>Most ssh supports protocol type 1 and 2 these days, but to narrow
>>down your problem, try each each individually.  Let the cipher type
>>be the default for that protocol.  So try each of these separately:
>>
>>$cnn = Net::SSH::Perl->new($host, -protocol => '1');
>>
>>$cnn = Net::SSH::Perl->new($host, -protocol => '2');
>>
>>You may get a different error from each one which would be a clue
>>for what's wrong.
> 
> 
> Hi, thank you very much. When I specified protocol => '2' explicitly,
> I was prompted with the message of missing perl modules:
> 
>     my $ssh = Net::SSH::Perl->new("192.168.50.50", protocol => '2');
>     $ssh->login($user, $pass);
>     $ssh->cmd("hostname");
>     ### Can't locate Math/Pari.pm in @INC
> 
> When I used `protocol=>'1' or didn't specify that parameter then I got
> "Selected cipher type not supported by server Options". I downloaded
> those from cpan and had them installed. Now it works.
> 
> Before I tried this successfully, I ever went to except script but
> failed at last. So, thank you very much.


It seems like in the last 30 years I haven't learned much about
programming, but I have learned about debugging.  It tells you
where I spend most of my time.
--S
** Posted from http://www.teranews.com **


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

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


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