[27772] in Perl-Users-Digest
Perl-Users Digest, Issue: 9142 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 10 21:05:42 2006
Date: Mon, 10 Apr 2006 18:05:04 -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, 10 Apr 2006 Volume: 10 Number: 9142
Today's topics:
an UN-deprecated way to cvt aryRef to size? (David Combs)
Re: an UN-deprecated way to cvt aryRef to size? <matthew.garrish@sympatico.ca>
Re: an UN-deprecated way to cvt aryRef to size? <matthew.garrish@sympatico.ca>
Re: an UN-deprecated way to cvt aryRef to size? <noreply@gunnar.cc>
Re: an UN-deprecated way to cvt aryRef to size? <matthew.garrish@sympatico.ca>
Re: catch arrow keys xhoster@gmail.com
Re: EXAMPLE -- Re: Strange issue with `CHOMP' not worki <someone@example.com>
Looking for references/tips on learning other languages <not@invalid.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Apr 2006 18:29:27 -0400
From: dkcombs@panix.com (David Combs)
Subject: an UN-deprecated way to cvt aryRef to size?
Message-Id: <e1em87$du9$1@panix1.panix.com>
Subject: an UN-deprecated way to cvt aryRef to size?
The line at 792 gives me a deprecated-error:
my $ary1Size = scalar(@{$ary1Ref});
<line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
gives me the warning (I guess it's a warning):
1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
Dkclib.pm_02 syntax OK
DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
When I change it to this:
my $ary1Size = scalar(@{$ary1Ref});
# @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
I get no such message:
1458 ==/dkcjunk==> perl -wc Dkclib.pm
Dkclib.pm syntax OK
1459 ==/dkcjunk==>
Please, just what *is* the ("new" (as of 5.8.6?)) rule?
And, maybe that rule should be ADDED to the "error msg".
Thanks!
David
------------------------------
Date: Mon, 10 Apr 2006 18:47:15 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: an UN-deprecated way to cvt aryRef to size?
Message-Id: <PfB_f.2545$fo1.97237@news20.bellglobal.com>
"David Combs" <dkcombs@panix.com> wrote in message
news:e1em87$du9$1@panix1.panix.com...
>
> Subject: an UN-deprecated way to cvt aryRef to size?
>
> The line at 792 gives me a deprecated-error:
>
> my $ary1Size = scalar(@{$ary1Ref});
>
> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
> ONCE!
>
> gives me the warning (I guess it's a warning):
>
> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
> Dkclib.pm_02 syntax OK
>
> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
>
No, you're using an array as reference. Change it to:
@{$ary2Ref->[$ary1Ref]} = undef;
The way you wrote it above is equivalent to @{$ary2Ref}->[$ary1Ref].
Matt
------------------------------
Date: Mon, 10 Apr 2006 18:49:26 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: an UN-deprecated way to cvt aryRef to size?
Message-Id: <ShB_f.2546$fo1.97277@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:PfB_f.2545$fo1.97237@news20.bellglobal.com...
>
> "David Combs" <dkcombs@panix.com> wrote in message
> news:e1em87$du9$1@panix1.panix.com...
>>
>> Subject: an UN-deprecated way to cvt aryRef to size?
>>
>> The line at 792 gives me a deprecated-error:
>>
>> my $ary1Size = scalar(@{$ary1Ref});
>>
>> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
>> ONCE!
>>
>> gives me the warning (I guess it's a warning):
>>
>> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
>> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
>> Dkclib.pm_02 syntax OK
>>
>> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
>>
>
> No, you're using an array as reference. Change it to:
>
> @{$ary2Ref->[$ary1Ref]} = undef;
>
Bad typing on my part, that obviously should have been
@{$ary2Ref->[$ary1Size-1]}
Matt
------------------------------
Date: Tue, 11 Apr 2006 01:18:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: an UN-deprecated way to cvt aryRef to size?
Message-Id: <4a07dvFqa8h6U1@individual.net>
David Combs wrote:
> Subject: an UN-deprecated way to cvt aryRef to size?
>
> The line at 792 gives me a deprecated-error:
>
> my $ary1Size = scalar(@{$ary1Ref});
Why are you using the scalar() function?
my $ary1Size = @{ $ary1Ref };
> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
>
> gives me the warning (I guess it's a warning):
>
> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
> Dkclib.pm_02 syntax OK
So, it's not the conversion to size that rises the warning?
> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
How is that?
> When I change it to this:
>
> my $ary1Size = scalar(@{$ary1Ref});
>
> # @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
> $ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
>
> I get no such message:
>
> 1458 ==/dkcjunk==> perl -wc Dkclib.pm
> Dkclib.pm syntax OK
> 1459 ==/dkcjunk==>
So you found a solution. What's the problem, then?
Want an alternative solution?
${ $ary2Ref }[$ary1Size-1] = undef;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 10 Apr 2006 19:42:11 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: an UN-deprecated way to cvt aryRef to size?
Message-Id: <j3C_f.2569$fo1.99110@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:PfB_f.2545$fo1.97237@news20.bellglobal.com...
>
> "David Combs" <dkcombs@panix.com> wrote in message
> news:e1em87$du9$1@panix1.panix.com...
>>
>> Subject: an UN-deprecated way to cvt aryRef to size?
>>
>> The line at 792 gives me a deprecated-error:
>>
>> my $ary1Size = scalar(@{$ary1Ref});
>>
>> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
>> ONCE!
>>
>> gives me the warning (I guess it's a warning):
>>
>> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
>> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
>> Dkclib.pm_02 syntax OK
>>
>> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
>>
>
> No, you're using an array as reference. Change it to:
>
> @{$ary2Ref->[$ary1Ref]} = undef;
>
I shouldn't post before eating. I thought you were trying to get at the
array. Change that to:
@{$ary2Ref}[$ary1Size-1] = undef;
Matt
------------------------------
Date: 11 Apr 2006 00:09:44 GMT
From: xhoster@gmail.com
Subject: Re: catch arrow keys
Message-Id: <20060410202120.603$U2@newsreader.com>
Michael Goerz <news3@8439.e4ward.com> wrote:
> xhoster@gmail.com wrote:
> >> Hi, how can I catch if someone presses the Arrow-Keys (Up, Down, Left,
> >> use Term::ReadKey;
> >> while (not defined ($pressedkey = ReadKey(-1))) {
> >> # No key yet
> >> }
> >
> > Isn't that pretty silly? You go out of your way to do a nonblocking
> > read, only to put it into a busy-wait loop which emulates blocking in
> > a very inefficient way.
> >
> > $pressedkey = ReadKey();
> Then I have to press Enter after each "keystroke".
In your original code, exactly as you posted it, you need to press Enter,
too. I suspect this is because the code you posted is not the real code
you are running, but rather your real code has "ReadMode 4;" in it.
If you don't include the "ReadMode 4;", then you have to press Enter
either way. If you do include the "ReadMode 4;", then you don't need
to press Enter, either way. It isn't about the ReadKey, it is about the
ReadMode
> The code I used before was actually taken from
> http://search.cpan.org/~jstowe/TermReadKey-2.30/ReadKey.pm
Yep, but that example is expecting you to replace the "# No key yet" line
with something meaningful. If you leave it as is, then you are better
off using the blocking ReadKey.
Cheers,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 10 Apr 2006 22:39:51 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: EXAMPLE -- Re: Strange issue with `CHOMP' not working...
Message-Id: <X8B_f.45607$K11.38691@clgrps12>
Ignoramus20015 wrote:
> OK, here's an example to illustrate my problem with chomp.
>
> To those who have not seen my original post, please see it first.
>
> The file I read has not changed in years. When I read it,I get
> INTERMITTENT errors with chomp, they do not happen every time.
>
> This is a real life perl module that fails.
>
> The messages that I see in my errors file are something like this:
>
> Algebra::Config: BAD BAD BAD Input string after chomp but BEFORE regex: 'show_counter=yes
>
> Things look even worse than that, actually, as it seems that sometimes
> requesting a single line from a file slurps the entire file.
That sounds like the $/ (Input Record Separator) global variable is being
undefined and the value of $/ affects both readline() and chomp(). You need
to use local() to limit the changes in $/.
> Another
> tip, these issues pop up only a few minutes after the webserver is
> restarted.
>
> Look for BAD BAD BAD print in the file to see where I print the error
> message.
>
> ======================================================================
> package Algebra::Config;
>
> use strict;
>
> require Exporter;
>
> use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
>
> @ISA = qw(Exporter);
> @EXPORT= qw( get_config_var get_data_dir get_algebra_root );
> @EXPORT_OK = qw( get_config_var );
>
> $VERSION = 2000.0426;
>
> use vars qw( $algebra_data_dir );
>
> sub get_algebra_root {
> my $algebra_root = $ENV{'ALGEBRA_ROOT'} || $ENV{'DOCUMENT_ROOT'}
> || die "Webmaster has to define ALGEBRA_ROOT environment variable!";
> return $algebra_root;
>
> }
>
> sub get_config_var {
> my ($category, $variable) = @_;
> my $algebra_root = get_algebra_root;
> my $config_file = "$algebra_root/etc/$category";
> die "Config file '$config_file' does not exist or is not readable."
> unless -r $config_file;
> open( CONFIG, $config_file );
You have die() in the wrong place. The file permissions could be changed
between the call to stat() and the call to open().
open CONFIG, $config_file
or die "Cannot open config file '$config_file' $!";
> while( $_ = <CONFIG> ) {
> chomp;
>
> if( /(\n|\r)/ ) {
> print STDERR "Algebra::Config: BAD BAD BAD Input string after chomp but BEFORE regex: '$_'.\n";
> }
>
> $_ =~ s/(\n|\r)//;
You are using capturing parentheses but are not using the value captured in
$1? Do you just want to remove either the first "\n" or the first "\r"
character or do you want to remove all "\n" and "\r" characters?
> next if( /^\s*#/ );
> next if( /^\s*$/ );
> my( $key, $value ) = split( /\s*=\s*/, $_ );
That will not work correctly if $_ contains more than one '=' character.
my( $key, $value ) = split /\s*=\s*/, $_, 2;
> return $value if( $key eq $variable );
> }
>
> return undef;
Returning the undef value will not work correctly if this sub is called in
list context. Just use return with no arguments for the correct behaviour in
any context.
> }
>
> $algebra_data_dir = get_config_var( "general", "algebra_data_dir" )
> || $ENV{'ALGEBRA_ROOT'};
>
> sub get_data_dir {
> my ($category, $variable) = @_;
>
> my $dir = get_config_var( $category, $variable );
> if( !($dir =~ /^\// ) ) {
Or simply:
if( $dir !~ /^\// ) {
> $dir = $algebra_data_dir . "/$dir";
> }
> return $dir;
> }
>
>
> 1;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 11 Apr 2006 10:59:13 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Looking for references/tips on learning other languages after perl
Message-Id: <e1ev11$1qg1$1@bunyip2.cc.uq.edu.au>
Hi all,
While I continue to write in perl almost exclusively, my work has
changed slightly so that I need to get back into a fully compilable
language (I know about PAR, but its not wholly my decision). I used to
be quite proficient in C but its been so long that I've almost forgotten
it, and I'd prefer to be writing OO code, so I'm looking into C#.
Syntax I'll learn on the way - I've always found language syntax to be
the easy part of learning a language - but what I really need to have is
a kind of map of how to do things in C# that I currently do in perl - a
sort of translator if you will.
Some things I have found myself (Regular expressions, Hashes
especially), but there are other things that I use a lot in perl that I
still need to 'translate'. And I'm well aware there are some things that
won't easily translate (I'm expecting stringy evals to be near
impossible, but luckily I don't use them very often, and AUTOLOAD I'm
expecting to be quite difficult at the least too).
What I'm looking for is a reference/book/whatever that might have
information like this. Has anyone out there found such a thing, or know
of such a resource?
TIA,
MB
------------------------------
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 V10 Issue 9142
***************************************