[29312] in Perl-Users-Digest
Perl-Users Digest, Issue: 556 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 22 16:10:04 2007
Date: Fri, 22 Jun 2007 13: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 Fri, 22 Jun 2007 Volume: 11 Number: 556
Today's topics:
array not working as a hash value. <usaims@yahoo.com>
Re: array not working as a hash value. <klaus03@gmail.com>
Re: array not working as a hash value. <kaldrenon@gmail.com>
Re: array not working as a hash value. <usaims@yahoo.com>
Re: Assigning another filehandle to STDOUT, using binmo <a24061@ducksburg.com>
Re: Assigning another filehandle to STDOUT, using binmo <klaus03@gmail.com>
Re: DBD::AnyData hangs when exporting XML xhoster@gmail.com
Re: FAQ 1.6 What is perl6? <savagebeaste@yahoo.com>
How to get a reference to a map function? <kingskippus@gmail.com>
Re: How to get a reference to a map function? <peter@makholm.net>
Re: How to get a reference to a map function? <kingskippus@gmail.com>
Re: I need some cleanings tips and advice. <pjb@informatimago.com>
Re: Perl Best Practices - Code Formatting. <louisREMOVE@REMOVEh4h.com>
Re: Perl Best Practices - Code Formatting. <vronans@nowheresville.spamwall>
Re: Perl Best Practices - Code Formatting. <asuter@cisco.com>
Re: why we need perl6 if we have parrort? <savagebeaste@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Jun 2007 11:15:44 -0700
From: usaims <usaims@yahoo.com>
Subject: array not working as a hash value.
Message-Id: <1182536144.303159.293010@g4g2000hsf.googlegroups.com>
Hi,
I'm trying to get this little script to print:
10.230.0.14
10.230.0.15
10.230.0.16
but its printing:
1
10.230.0.ARRAY(0x8105294)
###################################
Below is the script, what am I doing wrong?
#!/usr/bin/perl
use warnings;
use strict;
my @range_one = (14, 15, 16);
my @range_two = (23, 24, 25);
my %roxiecluster = (
"1" => \@range_one,
"2" => \@range_two
);
print "What range do you want to check on?\n";
print "Press (1) and <ENTER> for Range 1
[10.230.0.14-23]\n";
print "Press (2) and <ENTER> for Range 2
[10.230.0.23-25]\n";
my $choice = <STDIN>;
chomp($choice);
my @roxie = $roxiecluster{$choice};
foreach my $x (@roxie) {
print "10.230.0.$x\n";
}
------------------------------
Date: Fri, 22 Jun 2007 11:32:02 -0700
From: Klaus <klaus03@gmail.com>
Subject: Re: array not working as a hash value.
Message-Id: <1182537122.326150.176860@q75g2000hsh.googlegroups.com>
On Jun 22, 8:15 pm, usaims <usa...@yahoo.com> wrote:
[ snip ]
> my %roxiecluster = (
> "1" => \@range_one,
> "2" => \@range_two
> );
[ snip ]
> my @roxie = $roxiecluster{$choice};
my @roxie = @{ $roxiecluster{$choice} };
That should work.
I remember vaguely that one has to use @{ ... } in those cases, but I
can't find the exact reference anymore in perldoc
--
Klaus
------------------------------
Date: Fri, 22 Jun 2007 18:37:46 -0000
From: Kaldrenon <kaldrenon@gmail.com>
Subject: Re: array not working as a hash value.
Message-Id: <1182537466.734794.233500@u2g2000hsc.googlegroups.com>
I changed your code to this:
#!/usr/bin/perl
use warnings;
use strict;
$| = 1;
my @range_one = (14, 15, 16);
my @range_two = (23, 24, 25);
my %roxiecluster = (
"1" => \@range_one,
"2" => \@range_two
);
print "What range do you want to check on?\n";
print "Press (1) and <ENTER> for Range 1: [10.230.0.14-23]\n";
print "Press (2) and <ENTER> for Range 2: [10.230.0.23-25]\n";
my $choice = <STDIN>;
chomp($choice);
foreach (@{$roxiecluster{$choice}}) {
print "10.230.0.$_\n";
}
$roxiecluster{$choice} is scalar, but wrap it in @{...} and it's an
array again.
Also, I added the line $| = 1;, which causes print statements to flush
automatically. The first time I ran your version I didn't see the
prompt until I typed something in.
-Andrew
------------------------------
Date: Fri, 22 Jun 2007 12:29:24 -0700
From: usaims <usaims@yahoo.com>
Subject: Re: array not working as a hash value.
Message-Id: <1182540564.098414.92460@o11g2000prd.googlegroups.com>
On Jun 22, 2:37 pm, Kaldrenon <kaldre...@gmail.com> wrote:
> I changed your code to this:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> $| = 1;
> my @range_one = (14, 15, 16);
> my @range_two = (23, 24, 25);
>
> my %roxiecluster = (
> "1" => \@range_one,
> "2" => \@range_two
> );
>
> print "What range do you want to check on?\n";
> print "Press (1) and <ENTER> for Range 1: [10.230.0.14-23]\n";
> print "Press (2) and <ENTER> for Range 2: [10.230.0.23-25]\n";
>
> my $choice = <STDIN>;
> chomp($choice);
>
> foreach (@{$roxiecluster{$choice}}) {
> print "10.230.0.$_\n";
>
> }
>
> $roxiecluster{$choice} is scalar, but wrap it in @{...} and it's an
> array again.
>
> Also, I added the line $| = 1;, which causes print statements to flush
> automatically. The first time I ran your version I didn't see the
> prompt until I typed something in.
>
> -Andrew
Thank you all
my @roxie = @{ $roxiecluster{$choice} }; DID THE TRICK :-) !
------------------------------
Date: Fri, 22 Jun 2007 19:18:19 +0100
From: Adam Funk <a24061@ducksburg.com>
Subject: Re: Assigning another filehandle to STDOUT, using binmode.
Message-Id: <bcgtk4-vq8.ln1@news.ducksburg.com>
On 2007-06-21, Dr.Ruud wrote:
> Adam Funk schreef:
>
>> Is using binmode the most correct way to suppress those annoying "Wide
>> character" warnings?
>
> What is annoying about them? The just mean that you need to fix your
> program.
OK, let my try a different set of questions: is using binmode the
correct way to fix the error that causes those warnings?
As I said, I'm running the program in a UTF-8 environment but getting
thousands (I think) of identical warnings about "Wide characters"
which actually refer to correct UTF-8 characters that Perl has read
from input data files without a hiccup.
Why is it unreasonable that I find this annoying?
or
What am I doing that constitutes an error?
------------------------------
Date: Fri, 22 Jun 2007 11:39:31 -0700
From: Klaus <klaus03@gmail.com>
Subject: Re: Assigning another filehandle to STDOUT, using binmode.
Message-Id: <1182537571.047534.205960@m37g2000prh.googlegroups.com>
On Jun 22, 8:18 pm, Adam Funk <a24...@ducksburg.com> wrote:
> On 2007-06-21, Dr.Ruud wrote:
> > Adam Funk schreef:
>
> >> Is using binmode the most correct way to suppress those annoying "Wide
> >> character" warnings?
>
> > What is annoying about them? The just mean that you need to fix your
> > program.
>
> OK, let my try a different set of questions: is using binmode the
> correct way to fix the error that causes those warnings?
>
> As I said, I'm running the program in a UTF-8 environment but getting
> thousands (I think) of identical warnings about "Wide characters"
> which actually refer to correct UTF-8 characters that Perl has read
> from input data files without a hiccup.
>
> Why is it unreasonable that I find this annoying?
> or
> What am I doing that constitutes an error?
try perl -C7
see perldoc perlrun:
++ ===============================
++ -C [number/list]
++
++ The -C flag controls some Unicode of the Perl
++ Unicode features.
++
++ As of 5.8.1, the -C can be followed either by a
++ number or a list of option letters. The letters, their
++ numeric values, and effects are as follows; listing
++ the letters is equal to summing the numbers.
++
++ I 1 STDIN is assumed to be in UTF-8
++ O 2 STDOUT will be in UTF-8
++ E 4 STDERR will be in UTF-8
++ S 7 I + O + E
++ ...
++ ===============================
--
Klaus
------------------------------
Date: 22 Jun 2007 18:36:38 GMT
From: xhoster@gmail.com
Subject: Re: DBD::AnyData hangs when exporting XML
Message-Id: <20070622143640.107$Ii@newsreader.com>
xhoster@gmail.com wrote:
> KomsBomb@hotmail.com wrote:
> > Perl 5.8.0
> > Newest DBD::AnyData and AnyData just downloaded from CPAN.
> > When export a test database to xml, the script hangs and seems
> > it's in a dead loop.
> >
> > ********My Code start*************
> > use strict;
> > use warnings;
> > use DBI;
> >
> > my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):');
> > my ($table, $format, $file, $flags) = (
> > 'test', 'XML', 'cars.csv', { col_names => 'make,model,year' }
> > );
> > $dbh->do("CREATE TABLE test (id TEXT,phrase TEXT)");
> > $dbh->do("INSERT INTO test VALUES (1,'foonadfjlsdj')");
> > $dbh->do("INSERT INTO test VALUES (2,'bar')");
> > $dbh->func( $table, $format, $file, 'ad_export'); #hangs here
> > ********My Code end*************
> >
> > By doing more investigation, I found where it hangs,
> >
> > In package AnyData (note not the DBD::AnyData), line 639, in sub
> > adConvert, there is a line
> > " @cols = @{ shift @{ $source_data } };"
> > When I execute step by step there, the program hangs at that line.
>
> I've run strace on this program. It appears to be opening two handles
> onto the file cars.csv, and trying to obtain a exclusive lock on each of
> those handles, leading to a self-deadlock. The very last instruction
> executed is a flock, so I don't think you've identified the correct line
> for the freezing point.
I've found the problem in AnyData/Format/XML.pm, around line 876:
#$self->{twig}->print;
#z if ( ( $storage and $file and !($file eq $storage->{file_name}) )
#z or ( $storage and $file and !$storage->{fh} )
if ( ( $storage and $file )
) {
$storage->{file_name} = $file;
close $storage->{fh} if $storage->{fh}; ### Just added by Me
$storage->{fh} = $storage->open_local_file($file,'o');
}
$storage->{fh} already holds a locked filehandle, so trying to obtain
a new filehandle and lock it (which open_local_file does) deadlocks.
I initially tried just to undef $storage->{fh}, but that didn't work.
Apparently, this handle is held somewhere besides just in $storage, so
I had to go with close rather than undef.
I must say that this adventure didn't make me terribly eager to use AnyData
in my own programs.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 22 Jun 2007 11:52:09 -0700
From: "Clenna Lumina" <savagebeaste@yahoo.com>
Subject: Re: FAQ 1.6 What is perl6?
Message-Id: <5e2k2sF36rvseU1@mid.individual.net>
Randal L. Schwartz wrote:
>>>>>> "Purl" == Purl Gurl <purlgurl@purlgurl.net> writes:
>
>>> "We're really serious about reinventing everything that needs
>>> reinventing." --Larry Wall
>
>
> Purl> Now hold on there just a minute! A few days back some of the
> childish Purl> False Gods of Perl around here were screaming their
> heads off about, Purl> "not reinventing the wheel."
>
> Purl> I'll be damn, there is Larry Wall confessing to "reinventing
> the wheel."
>
> I've never told people not to reinvent the wheel, if I was absolutely
> sure they were completely familiar with the wheel they were
> reinventing.
>
> In this case, I'm pretty sure that Larry is familiar with the wheel
> he is reinventing. Heck, he invented most of it in the first place.
>
> Put your "wand of unjustified comparisons" back in its sheath.
I have have to sort of agree with "Purl" on this one, some what. I have
seen soem regualars reepatedly tell people not to reinvent whats already
good and working and accepted. Even if the OP who posted the reinvention
did a decent job, theres usually aready to way theres already a way to
do it thats generally accepted.
But, Larry Wall's own words do seem to add a hint of contradicting to
soem of the preachings. Yes, it good to use what's workign well and
accepted and I suport that notion, but if that were always the case,
then there wouldn't be a Perl6 in the works :)
--
CL
------------------------------
Date: Fri, 22 Jun 2007 12:51:10 -0700
From: TonyV <kingskippus@gmail.com>
Subject: How to get a reference to a map function?
Message-Id: <1182541870.589577.79060@g37g2000prf.googlegroups.com>
Hopefully this is a really simple question.
I am using a map function to get an array, and I need to pass a
reference to that array to another function. Right now, this is
working:
# @queues is an array of anonymous hashes
my @q = map { $_->{name} } @queues;
do_something(\@q);
My question is this: Is there any way to skip assigning that
temporary variable and pass the result of the map function directly in
the do_something function call? Something like this:
# This is syntactically incorrect, but I need to pass the result of
the
# map function to do_something as an array *reference*, not an array.
do_something(\map { $_->{name} } @queues);
Thanks for any help!
------------------------------
Date: Fri, 22 Jun 2007 19:57:34 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: How to get a reference to a map function?
Message-Id: <871wg3224x.fsf@makholm.net>
TonyV <kingskippus@gmail.com> writes:
> # This is syntactically incorrect, but I need to pass the result of
> the
> # map function to do_something as an array *reference*, not an array.
> do_something(\map { $_->{name} } @queues);
do_something([ map { $_->{name} } @queues ]);
or even without parentheses
do_something [ map { $_->{name} } @queues ];
//Makholm
------------------------------
Date: Fri, 22 Jun 2007 13:07:02 -0700
From: TonyV <kingskippus@gmail.com>
Subject: Re: How to get a reference to a map function?
Message-Id: <1182542822.755094.112990@g37g2000prf.googlegroups.com>
On Jun 22, 3:57 pm, Peter Makholm <p...@makholm.net> wrote:
> TonyV <kingskip...@gmail.com> writes:
> > # This is syntactically incorrect, but I need to pass the result of
> > the
> > # map function to do_something as an array *reference*, not an array.
> > do_something(\map { $_->{name} } @queues);
>
> do_something([ map { $_->{name} } @queues ]);
>
> or even without parentheses
>
> do_something [ map { $_->{name} } @queues ];
>
> //Makholm
Awesome, that's perfect! Thanks a ton!
------------------------------
Date: Fri, 22 Jun 2007 21:19:30 +0200
From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: I need some cleanings tips and advice.
Message-Id: <87fy4jkda5.fsf@thalassa.lan.informatimago.com>
"Colin B." <cbigam@somewhereelse.nucleus.com> writes:
> In comp.lang.perl.misc CleaningTips@gmail.com wrote:
>> Me and my buddy made a website called www.stupidpinheads.com, its
>> basically a free forum and free blog driven web site dedicated as a
>> source people can goto to find out how to clean and remove stains from
>> pretty much anything. Problem is, as of yet, you couldn't find out how
>> to clean anything right now cause the site is new and no one has found
>> it yet.
>
> Let's see if I get this right.
>
> You create a website for a subject that you know nothing about. Then you
> try to solicit content in a bunch of programming language newsgroups.
>
> Wow, that's pretty pathetic, even for a google-groups poster!
>
> Begone with you.
Pathetic, but it's a prooven way to become millionaire with the
Internet. You can't blame him... http://www.milliondollarhomepage.com/
--
__Pascal Bourguignon__ http://www.informatimago.com/
NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
------------------------------
Date: Fri, 22 Jun 2007 12:10:20 -0700
From: "Wayne M. Poe" <louisREMOVE@REMOVEh4h.com>
Subject: Re: Perl Best Practices - Code Formatting.
Message-Id: <5e2l4vF36dsm9U1@mid.individual.net>
Petr Vileta wrote:
> Asim Suter wrote:
>> K&R style below
>> ============
>> for my $item ( @list ) {
>> .......
>> .......
>> }
>>
>> BSD style below
>> ============
>> for my $item ( @list )
>> {
>> ....
>> ....
>> }
>>
>>
>> PS: It does not matter - but I find BSD style more appealing.
>
> I prefer BSD style too because by me this is better readable for
> human. --
Err, it's the difference of a single \n vs a single space just before
the opening curly brase... how can that possibly be enough of a
difference to change if it's "human readable" or not?
It's just " {\n" vs "\n{\n" - esstentially the differce of ONE
character. ONE. So what is really the big deal?
Personally I find a greator problem in working with code that uses one
or more differnce intent spacings (I tend to use 3, but have worked with
people who prefer 4, 5 or even 8, and soemtiems they are raw spaces and
soemtiems raw tabs.
(I always prefered the "K&R" (what does that stand for... I never knew
that was the name for it :P ) but that probably because thats the style
I first learned programming with and it stuck.)
------------------------------
Date: Fri, 22 Jun 2007 12:17:50 -0700
From: "Vronans" <vronans@nowheresville.spamwall>
Subject: Re: Perl Best Practices - Code Formatting.
Message-Id: <AtKdnZq6Lcr8veHbnZ2dnUVZ_uqvnZ2d@wavecable.com>
Abigail wrote:
>
> _ anno4000@radom.zrz.tu-berlin.de (anno4000@radom.zrz.tu-berlin.de)
> wrote
> on VXLIII September MCMXCIII in
> <URL:news:5e1on1F36fb0dU1@mid.dfncis.de>: "" damian@conway.org
> <thoughtstream@gmail.com> wrote in comp.lang.perl.misc: "" > Asim
> Suter wrote: "" >
> "" > > I was readingPerlBest Practices by RespectedDamianConway
> "" > > and he rather strongly advices using K&R style of code format
> as opposed to "" > > BSD style or GNU style.
> "" >
> "" > Strongly? When on pages 8&9 where I write:
> "" >
> "" > "...the particular code layout style you ultimately decide
> upon "" > does not matter at all.
> ""
> "" What *does* matter is that the implications (of bracing style or a
> "" gazillion of other decisions) are discussed so the decision can be
> "" made on a rational basis.
> ""
> "" The merit of _PBP_ isn't so much that it gives us a standard to
> adhere "" to but a standard to deviate from.
>
>
> What always amazes me is dat discussions about coding standards always
> rapidly focusses on layout nitpicks and other trivial things.
>
> I don't care whether code I inherit use K&R bracing style, or BSD
> bracing
> style, or whether is uses 3 or 4 space indent, or whether it uses
> single
> or double quotes to delimit constant strings.
>
> I *do* care about readable, structured code. And such code *IS NOT*
> about
> always using /x in your regexp, or not using postfix 'if' or most of
> the guidelines about PBP. Nor is about most of the stuff perlcritic
> warns about.
>
> Proper encapsulation, the right abstraction, sensible variable names,
> useful comments, etc, that's important.
>
> Forget the trivial formatting stuff.
No offense, but it's difficult to ignore "trivial formatting" when you
cannot even use proper quoting delimiters. I think you have bene asked
countless times to fix that. There are some basic stanards one -should-
adhere too, or at least try to stay close to. Standard quoting falls
right into that catagory so why not stop breaking news reader quote
processing abroad?
------------------------------
Date: Fri, 22 Jun 2007 12:38:08 -0700
From: "Asim Suter" <asuter@cisco.com>
Subject: Re: Perl Best Practices - Code Formatting.
Message-Id: <1182541090.563701@sj-nntpcache-2.cisco.com>
"Wayne M. Poe" <louisREMOVE@REMOVEh4h.com> wrote in message
news:5e2l4vF36dsm9U1@mid.individual.net...
> Petr Vileta wrote:
>> Asim Suter wrote:
>>> K&R style below
>>> ============
>>> for my $item ( @list ) {
>>> .......
>>> .......
>>> }
>>>
>>> BSD style below
>>> ============
>>> for my $item ( @list )
>>> {
>>> ....
>>> ....
>>> }
>>>
>>>
>>> PS: It does not matter - but I find BSD style more appealing.
>>
>> I prefer BSD style too because by me this is better readable for
>> human. --
>
> Err, it's the difference of a single \n vs a single space just before the
> opening curly brase... how can that possibly be enough of a difference to
> change if it's "human readable" or not?
>
> It's just " {\n" vs "\n{\n" - esstentially the differce of ONE character.
> ONE. So what is really the big deal?
>
> Personally I find a greator problem in working with code that uses one or
> more differnce intent spacings (I tend to use 3, but have worked with
> people who prefer 4, 5 or even 8, and soemtiems they are raw spaces and
> soemtiems raw tabs.
>
> (I always prefered the "K&R" (what does that stand for... I never knew
> that was the name for it :P ) but that probably because thats the style I
> first learned programming with and it stuck.)
>
K&R came from Kernighan and Ritchie's well known The C Programming Book
http://en.wikipedia.org/wiki/Indent_style#K.26R_style
Regards.
Asim Suter
------------------------------
Date: Fri, 22 Jun 2007 11:41:03 -0700
From: "Clenna Lumina" <savagebeaste@yahoo.com>
Subject: Re: why we need perl6 if we have parrort?
Message-Id: <5e2je2F36fpriU1@mid.individual.net>
brian d foy wrote:
> In article <f5gq36$rme$1@netnews.hinet.net>, sonet
> <sonet.all@msa.hinet.net> wrote:
>
>> If every dynamically languages (such as Perl6 and Python...)
>> will convert to PIR and automatically converted inside Parrot to
>> PBC (Parrot Bytecode).
>>
>> 1.Why we need perl6 ? We can learn how to coding in PIR direct.
>
> For the same reason we have Java instead of programming in Java
> bytecode: higher level languages condense higher level concepts into
> keywords that represent a lot of behind-the-scenese lower-level code.
>
>
>> 2.Why not convert perl5 to PIR (convert to Parrot bytecode)?
>
> Some people were working on that with PONIE (Perl On New Interpreter
> Image), but those are also the same people doing Perl 6 / parrot
> things.
>
> There's a lot more to Perl 6 than just using parrot for its
> interpreter.
Why did they go with parrot instead of just augmenting the existing Perl
interpreter. Using Parrot (or any 3rd party interpreter) just kinda maks
it feel less like Perl in a way; not as "pure" as Perl5 and ealier :)
------------------------------
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 556
**************************************