[27769] in Perl-Users-Digest
Perl-Users Digest, Issue: 9141 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 10 18:05:47 2006
Date: Mon, 10 Apr 2006 15:05: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, 10 Apr 2006 Volume: 10 Number: 9141
Today's topics:
Re: A problem with precedence <abigail@abigail.nl>
ANNOUNCE: Set::Array V 0.14 <ron@savage.net.au>
catch arrow keys <news3@8439.e4ward.com>
Re: catch arrow keys xhoster@gmail.com
Re: catch arrow keys <news3@8439.e4ward.com>
Re: EXAMPLE -- Re: Strange issue with `CHOMP' not worki <ignoramus20015@NOSPAM.20015.invalid>
Re: EXAMPLE -- Re: Strange issue with `CHOMP' not worki <daveandniki@ntlworld.com>
Re: EXAMPLE -- Re: Strange issue with `CHOMP' not worki <ignoramus20015@NOSPAM.20015.invalid>
Re: EXAMPLE -- Re: Strange issue with `CHOMP' not worki <ignoramus20015@NOSPAM.20015.invalid>
Re: XS progamming question <nospam-abuse@ilyaz.org>
Re: XS progamming question <nospam-abuse@ilyaz.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Apr 2006 19:13:45 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: A problem with precedence
Message-Id: <slrne3lbj9.b4.abigail@alexandra.abigail.nl>
xhoster@gmail.com (xhoster@gmail.com) wrote on MMMMDCV September MCMXCIII
in <URL:news:20060410120148.667$eg@newsreader.com>:
}} Abigail <abigail@abigail.nl> wrote:
}} > Lukas Mai (rwxr-xr-x@gmx.de) wrote on MMMMDCIV September MCMXCIII in
}} > <URL:news:e1b1nt$98g$00$1@news.t-online.com>:
}} > <> Mark Hobley <markhobley@hotpop.deletethisbit.com> schrob:
}} > <>
}} > <> > I now add brackets to change the precedence:
}} > <> >
}} > <> > print (4 + 2) * 3; # This unexpectedly gives 6
}} > <>
}} > <> Use warnings.
}} >
}} > Actually, the fact this gives a warning is a damn good reason to NOT
}} > use warnings.
}} >
}} > Because Perl is more often wrong about this warning than it is right.
}}
}} That is not my experience.
}}
}}
}} > If I were to advocate against using Perl, I'd point out the warnings
}} > it gives with 'print', and then rest my case.
}} >
}} > print(4 + 2) * 3; # No warning.
}} > print (4 + 2) * 3; # Warning.
}} > print (4 + 2) * 3; # No warning (!)
}} > print (4 + 2) * 3; # No warning.
}} >
}} > Four mistakes, only one warning.
}}
}} Strange, I get 6 warning.
}}
}} print (...) interpreted as function at foo line 2.
}} print (...) interpreted as function at foo line 3.
I presumed this was the warning we're discussing - as that's the
warning that was being quoted from the documentation.
}} Useless use of multiplication (*) in void context at foo line 1.
}} Useless use of multiplication (*) in void context at foo line 2.
}} Useless use of multiplication (*) in void context at foo line 3.
}} Useless use of multiplication (*) in void context at foo line 4.
More reason to rip out the 'print (...)' warning - you're getting a
different warning anyway.
Abigail
--
perl -we '$| = 1; $_ = "Just another Perl Hacker\n"; print
substr $_ => 0, 1 => "" while $_ && sleep 1 => 1'
------------------------------
Date: Mon, 10 Apr 2006 10:11:47 GMT
From: Ron Savage <ron@savage.net.au>
Subject: ANNOUNCE: Set::Array V 0.14
Message-Id: <IxIvDr.AzL@zorch.sf-bay.org>
The pure Perl module Set::Array V 0.14
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.
On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.
An extract from the docs:
0.14 Mon Apr 10 19:51:00 2006
- Fix test which used a hard-coded version number
------------------------------
Date: Mon, 10 Apr 2006 22:23:50 +0200
From: Michael Goerz <news3@8439.e4ward.com>
Subject: catch arrow keys
Message-Id: <49vt6mFq7ohtU1@uni-berlin.de>
Hi, how can I catch if someone presses the Arrow-Keys (Up, Down, Left,
Right) on the keyboard? I tried
use Term::ReadKey;
while (not defined ($pressedkey = ReadKey(-1))) {
# No key yet
}
printf(" Decimal: %d\tHex: %x\n", ord($pressedkey),
ord($pressedkey));
but that only return the escape-symbol (27) for each of the arrow-keys.
I need to react on which key was pressed.
Thanks,
Michael Goerz
------------------------------
Date: 10 Apr 2006 20:26:25 GMT
From: xhoster@gmail.com
Subject: Re: catch arrow keys
Message-Id: <20060410163758.966$iu@newsreader.com>
Michael Goerz <news3@8439.e4ward.com> wrote:
> Hi, how can I catch if someone presses the Arrow-Keys (Up, Down, Left,
> Right) on the keyboard? I tried
>
> 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();
> printf(" Decimal: %d\tHex: %x\n", ord($pressedkey),
> ord($pressedkey));
>
> but that only return the escape-symbol (27) for each of the arrow-keys.
> I need to react on which key was pressed.
Control keys return multiple bytes per key-press. Once you see the 27, you
need to call ReadKey some more to get the rest of them.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 10 Apr 2006 22:57:23 +0200
From: Michael Goerz <news3@8439.e4ward.com>
Subject: Re: catch arrow keys
Message-Id: <49vv5iFqp75eU1@uni-berlin.de>
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". The code I used
before was actually taken from
http://search.cpan.org/~jstowe/TermReadKey-2.30/ReadKey.pm
> Control keys return multiple bytes per key-press. Once you see the 27, you
> need to call ReadKey some more to get the rest of them.
Yes, that appears to work. Thanks a lot!
Michael
------------------------------
Date: Mon, 10 Apr 2006 18:08:05 GMT
From: Ignoramus20015 <ignoramus20015@NOSPAM.20015.invalid>
Subject: Re: EXAMPLE -- Re: Strange issue with `CHOMP' not working...
Message-Id: <9ax_f.134938$u%1.46967@fe42.usenetserver.com>
After looking at stuff for a while, I realized that I was not closing
the file after read, which after a while could screw things up. This
thing was working correctly for a few years despite this. So, I made a
change to always close the file, and will see if that helps or not.
i
On Mon, 10 Apr 2006 17:56:27 GMT, Ignoramus20015 <ignoramus20015@NOSPAM.20015.invalid> 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. 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 );
> while( $_ = <CONFIG> ) {
> chomp;
>
> if( /(\n|\r)/ ) {
> print STDERR "Algebra::Config: BAD BAD BAD Input string after chomp but BEFORE regex: '$_'.\n";
> }
>
> $_ =~ s/(\n|\r)//;
> next if( /^\s*#/ );
> next if( /^\s*$/ );
> my( $key, $value ) = split( /\s*=\s*/, $_ );
> return $value if( $key eq $variable );
> }
>
> return undef;
> }
>
> $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 =~ /^\// ) ) {
> $dir = $algebra_data_dir . "/$dir";
> }
> return $dir;
> }
>
>
> 1;
>
------------------------------
Date: Mon, 10 Apr 2006 20:12:28 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: EXAMPLE -- Re: Strange issue with `CHOMP' not working...
Message-Id: <443aa00e$0$19681$8fcfb975@news.wanadoo.fr>
"Ignoramus20015" <ignoramus20015@NOSPAM.20015.invalid> wrote in message
news:f%w_f.134881$u%1.132371@fe42.usenetserver.com...
> 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. 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 );
> while( $_ = <CONFIG> ) {
> chomp;
>
> if( /(\n|\r)/ ) {
> print STDERR "Algebra::Config: BAD BAD BAD Input string
> after chomp but BEFORE regex: '$_'.\n";
> }
>
> $_ =~ s/(\n|\r)//;
> next if( /^\s*#/ );
> next if( /^\s*$/ );
> my( $key, $value ) = split( /\s*=\s*/, $_ );
> return $value if( $key eq $variable );
> }
>
> return undef;
> }
>
> $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 =~ /^\// ) ) {
> $dir = $algebra_data_dir . "/$dir";
> }
> return $dir;
> }
>
>
> 1;
>
Bear in mind that the exact behavoiur of chomp is determined by $/
if the calling script changes this the behaviour of your module will change.
You might do best to localise $/ to the value you expect in get_config_var.
------------------------------
Date: Mon, 10 Apr 2006 18:13:16 GMT
From: Ignoramus20015 <ignoramus20015@NOSPAM.20015.invalid>
Subject: Re: EXAMPLE -- Re: Strange issue with `CHOMP' not working...
Message-Id: <0fx_f.61229$7F6.19158@fe14.usenetserver.com>
Sorry for these self ollowups, I rewrote the module considerably to
reflect a few years of accumulated perl experience.
If anyone is curious, here it is now. I will see if it helps or not.
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 $_values );
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) = @_;
if( exists $_values->{$category}->{$variable} ) {
return $_values->{$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 );
while( $_ = <CONFIG> ) {
chomp;
if( /(\n|\r)/ ) {
my $str = substr( $_, 0, 80 );
print STDERR "Algebra::Config: BAD BAD BAD Input string after chomp but BEFORE regex: '$str'.\n";
}
$_ =~ s/(\n|\r)//;
next if( /^\s*#/ );
next if( /^\s*$/ );
my( $key, $value ) = split( /\s*=\s*/, $_ );
$_values->{$category}->{$key} = $value;
}
close( CONFIG );
if( exists $_values->{$category}->{$variable} ) {
return $_values->{$category}->{$variable};
}
$_values->{$category}->{$variable} = undef;
return undef;
}
$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 =~ /^\// ) ) {
$dir = $algebra_data_dir . "/$dir";
}
return $dir;
}
$_values = {};
1;
------------------------------
Date: Mon, 10 Apr 2006 18:14:26 GMT
From: Ignoramus20015 <ignoramus20015@NOSPAM.20015.invalid>
Subject: Re: EXAMPLE -- Re: Strange issue with `CHOMP' not working...
Message-Id: <6gx_f.61237$7F6.47385@fe14.usenetserver.com>
On Mon, 10 Apr 2006 20:12:28 +0200, Dave <daveandniki@ntlworld.com> wrote:
> Bear in mind that the exact behavoiur of chomp is determined by $/
> if the calling script changes this the behaviour of your module will change.
> You might do best to localise $/ to the value you expect in get_config_var.
OK, this is a good one. I like it. I think that I will see if my
latest changes (see my couple of followups) help, if not, I will watch
$/ and see who sets it.
Thanks a lot for some very sensible thoughts.
i
------------------------------
Date: Mon, 10 Apr 2006 20:03:12 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: XS progamming question
Message-Id: <e1edm0$2d8t$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Ferry Bolhar
<bol@adv.magwien.gv.at>], who wrote in article <1144663959.957971@proxy.dienste.wien.at>:
> >> I have different (internal) C functions, but want to make visible to Perl
> >> only one of them, but always with the same name.
>
> I would very appreciate if you could tell me how - no, I do not mean any
> kind of aliasing. I do not want to make the other function(s) visible from
> Perl, only the one selected during execution of the BOOT code.
Use aliasing. Including the functions you do not want visible - make
them invisible by aliasing - or just remove the relevant glob:
perl -wle "sub aa {print 12} BEGIN{ delete $main::{aa} } aa()"
Undefined subroutine &main::aa called at -e line 1.
But make sure that the glob is removed BEFORE any call to these
subroutines is compiled. If you do not have calls already compiled
into the parse tree, then something as simple as
perl -wle "sub aa {print 12}; *aa = \&undef; $aa='aa'; $aa->()"
Subroutine main::aa redefined at -e line 1.
Undefined subroutine &main::undef called at -e line 1.
may work too.
Hope this helps,
Ilya
------------------------------
Date: Mon, 10 Apr 2006 20:26:16 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: XS progamming question
Message-Id: <e1ef18$2dpp$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Ferry Bolhar
<bol@adv.magwien.gv.at>], who wrote in article <1144662749.282811@proxy.dienste.wien.at>:
> > Then your sentences should have been:
> >
> > "That's true if x is a valid Anno's identifier"
>
> Please add "Ferry's" in addition. Because - to go back to my initial
> question - what is the meaning of:
>
> *x = 3;
>
> the "3" really doesn't look like an identifier.
This emotion of yours bears no relationship to the question of
identifiers. Witness
perl -wle "BEGIN {*a = qq(\cU\cU)} $b=12; *{qq(\cU\cU)} = \$b; print $a"
Hope this helps,
Ilya
------------------------------
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 9141
***************************************