[28623] in Perl-Users-Digest
Perl-Users Digest, Issue: 9987 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 20 14:05:52 2006
Date: Mon, 20 Nov 2006 11:05:06 -0800 (PST)
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, 20 Nov 2006 Volume: 10 Number: 9987
Today's topics:
Re: "Did not find leading dereferencer" - new findings <ro.naldfi.scher@gmail.com>
Re: Date::Parse mysteriously lowercases text when an un (reading news)
Re: Date::Parse mysteriously lowercases text when an un (reading news)
Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U c <robertospara@gmail.com>
Re: FAQ 7.17 How can I access a dynamic variable while <brian.d.foy@gmail.com>
Re: Fetching input character without newline? (reading news)
Re: Fetching input character without newline? <anon40629@hotmail.com>
Re: Fetching input character without newline? <anon40629@hotmail.com>
Re: Fetching input character without newline? <anon40629@hotmail.com>
Re: How to change Perl's concept of a newline in regexp (reading news)
Re: How to change Perl's concept of a newline in regexp <rkrause@searstower.org>
How to post back the data by selecting a value from dro <kunanu@gmail.com>
Re: How to post back the data by selecting a value from <mritty@gmail.com>
Re: How to post back the data by selecting a value from <kunanu@gmail.com>
Re: How to post back the data by selecting a value from <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Nov 2006 07:59:25 -0800
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: Re: "Did not find leading dereferencer" - new findings to an old puzzle
Message-Id: <1164038365.771595.9030@h48g2000cwc.googlegroups.com>
OK, thank you for all the helpful comment in this matter, and of course
for your patience, because you finally have convinced me. :-D
Ronald
------------------------------
Date: Mon, 20 Nov 2006 15:04:47 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Date::Parse mysteriously lowercases text when an unrelated variable is used.
Message-Id: <45619A80.8070103@earthlink.net>
On 11/19/2006 08:48 AM, Peter Scott wrote:
> On Sun, 19 Nov 2006 12:35:14 +0000, Mumia W. (reading news) wrote:
>> To reduce my boredom I took grocery_stocker's data from "At a loss how
>> to sort this file," and I wrote a program to sort it:
>>
>> 1 #!/usr/bin/perl
>> 2
>> 3 use strict;
>> 4 use warnings;
>> 5 use Date::Parse;
>> 6 my $reverser = -1;
>> 7
>> 8 my $sortfn = sub {
>> 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
>> 10 $reverser * ($c <=> $d);
>> 11 };
>> 12
>> 13 @ARGV = 'sort-long-dates.txt';
>> 14 my @data = map uc $_, grep /./, <>;
>> 15 my @sorted = sort $sortfn @data;
>> 16 print join("",@sorted), "\n";
>> 17
>>
>> The data is sorted as expected, but something strange happens:
>> Date::Parse::str2time lowercases the weekday names. I deliberately
>> capitalize everything on the line to show that only the dates are affected.
> [snip]
>> BTW, the dates are not modified if the $reverser variable is defined
>> within the $sortfn subroutine, e.g.
>>
>> 7 my $sortfn = sub {
>> 8 my $reverser = -1;
>> 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
>> 10 $reverser * ($c <=> $d);
>> 11 };
>>
>> What's going on?
>>
>> -------------------------------
>> Perl 5.8.4
>> Debian GNU/Linux 3.1
>> Date::Parse 2.27
>
> Good report. I suspect you are running into the bug reported at
> http://groups-beta.google.com/group/perl.perl5.porters/browse_thread/thread/eefb0a6227a31891/7b14af5525b9d861?hl=en
> .. Maybe you could try 5.9.3 on your program and let us know. If it's not
> fixed you can dust off perlbug.
>
> str2time does sort() and lc() internally. Apparently the bug has
> something to do with sort subs that are closures (moving the definition of
> $reverser out of the sub does that).
>
Indeed, that looks like the bug, and it looks like it's still in Perl 5.9.4:
--------PROGRAM FOLLOWS---------
#!/usr/local/bin/perl5.9.4
use strict;
use warnings;
use Date::Parse;
my $reverser = -1;
printf ("Perl version: %vd\n", $^V);
printf ("Date::Parse version: $Date::Parse::VERSION\n");
# print '-------------------', "\n";
# Use a sorting function that is NOT a closure.
my $sortfn1 = sub {
my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
-1 * ($c <=> $d);
};
# Use a sorting function that IS a closure.
my $sortfn2 = sub {
my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
$reverser * ($c <=> $d);
};
# Load the data while making everything upper case.
my @data = map uc $_, <DATA>;
# If the the result of using $sortfn2 is different from
# the result of using $sortfn1, this perl interpreter
# is buggy.
my $usingfn1 = join '', sort $sortfn1 @data;
my $usingfn2 = join '', sort $sortfn2 @data;
if ($usingfn1 ne $usingfn2) {
print "We have a buggy perl here.\n";
}
__DATA__
irongeek ttypi Wed Nov 15 17:27
lar ttyp2 Fri Nov 17 17:12
lar ttypa Fri Nov 17 15:53
lar ttypp Thu Nov 16 17:11
lar ttypk Thu Nov 16 14:20
sabre ttyp5 Wed Nov 15 13:59
lar ttyp5 Wed Nov 15 13:57
sabre ttyp5 Wed Nov 15 13:28
sabre ttypc Wed Nov 15 12:10
lar ttypn Thu Nov 16 13:23
lar ttypd Fri Nov 17 07:27
irongeek ttyp2 Thu Nov 16 07:49
sabre ttypg Sat Nov 11 15:56
-------------OUTPUT FOLLOWS--------------
Perl version: 5.9.4
Date::Parse version: 2.27
We have a buggy perl here.
-------------OUTPUT ENDS-----------------
That program demonstrates that when the sorting subroutine is not a
closure, the lowercasing effect of Date::Parse::str2time is NOT
permitted to modify the original data, and when the sorting subroutine
IS a closure, the lowercasing effect of Date::Parse::str2time IS
permitted to modify the original data.
This is probably a bug in the perl interpreter.
I'm using Debian GNU/Linux 3.1 i386.
---
Flags:
category=
severity=
---
Site configuration information for perl 5.9.4:
Configured by (user) at Mon Nov 20 03:07:07 CST 2006.
Summary of my perl5 (revision 5 version 9 subversion 4) configuration:
Platform:
osname=linux, osvers=2.4.27-3-386,
archname=i686-linux-thread-multi-64int
uname='linux dike 2.4.27-3-386 #1 thu sep 14 08:44:58 utc 2006 i686
gnulinux '
config_args='-Dusethreads -Dprefix=/usr/local/share/perl-5.9
-Duse64bitint -Dcc=gcc -Dusedevel -Duseperlio -Dman1ext=1perl
-Dman3ext=3perl -de'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-13)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.2'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
---
@INC for perl 5.9.4:
/usr/local/lib/CPAN/share/perl
/usr/local/lib/CPAN/lib/perl
/usr/local/lib/CPAN/lib/site_perl/5.9.4/i686-linux-thread-multi-64int
/usr/local/lib/CPAN/lib/site_perl/5.9.4
/usr/local/share/perl-5.9/lib/5.9.4/i686-linux-thread-multi-64int
/usr/local/share/perl-5.9/lib/5.9.4
/usr/local/share/perl-5.9/lib/site_perl/5.9.4/i686-linux-thread-multi-64int
/usr/local/share/perl-5.9/lib/site_perl/5.9.4
.
---
Environment for perl 5.9.4:
HOME=/home/(user)
LANG=en_US
LANGUAGE=en_US:en_GB:en
LC_CTYPE=en_US.ISO-8859-1
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin:.:/home/(user)/bin:/usr/local/share/perl-5.9/bin
PERL5LIB=/usr/local/lib/CPAN/share/perl:/usr/local/lib/CPAN/lib/perl:/usr/local/lib/CPAN/lib/site_perl/5.9.4
PERL_BADLANG (unset)
SHELL=/bin/bash
--
paduille.4060.mumia.w@earthlink.net
------------------------------
Date: Mon, 20 Nov 2006 17:41:25 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Date::Parse mysteriously lowercases text when an unrelated variable is used.
Message-Id: <9Nl8h.1241$1s6.1061@newsread2.news.pas.earthlink.net>
On 11/20/2006 09:04 AM, Mumia W. (reading news) wrote:
> On 11/19/2006 08:48 AM, Peter Scott wrote:
>> On Sun, 19 Nov 2006 12:35:14 +0000, Mumia W. (reading news) wrote:
>>> To reduce my boredom I took grocery_stocker's data from "At a loss
>>> how to sort this file," and I wrote a program to sort it:
>>>
>>> 1 #!/usr/bin/perl
>>> 2
>>> 3 use strict;
>>> 4 use warnings;
>>> 5 use Date::Parse;
>>> 6 my $reverser = -1;
>>> 7
>>> 8 my $sortfn = sub {
>>> 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
>>> 10 $reverser * ($c <=> $d);
>>> 11 };
>>> 12
>>> 13 @ARGV = 'sort-long-dates.txt';
>>> 14 my @data = map uc $_, grep /./, <>;
>>> 15 my @sorted = sort $sortfn @data;
>>> 16 print join("",@sorted), "\n";
>>> 17
>>>
>>> The data is sorted as expected, but something strange happens:
>>> Date::Parse::str2time lowercases the weekday names. I deliberately
>>> capitalize everything on the line to show that only the dates are
>>> affected.
>> [snip]
>>> BTW, the dates are not modified if the $reverser variable is defined
>>> within the $sortfn subroutine, e.g.
>>>
>>> 7 my $sortfn = sub {
>>> 8 my $reverser = -1;
>>> 9 my ($c, $d) = map str2time(substr($_, 43, 16)), ($a, $b);
>>> 10 $reverser * ($c <=> $d);
>>> 11 };
>>>
>>> What's going on?
>>>
>>> -------------------------------
>>> Perl 5.8.4
>>> Debian GNU/Linux 3.1
>>> Date::Parse 2.27
>>
>> Good report. I suspect you are running into the bug reported at
>> http://groups-beta.google.com/group/perl.perl5.porters/browse_thread/thread/eefb0a6227a31891/7b14af5525b9d861?hl=en
>>
>> .. Maybe you could try 5.9.3 on your program and let us know. If
>> it's not
>> fixed you can dust off perlbug.
>>
>> str2time does sort() and lc() internally. Apparently the bug has
>> something to do with sort subs that are closures (moving the
>> definition of
>> $reverser out of the sub does that).
>>
>
> Indeed, that looks like the bug, and it looks like it's still in Perl
> 5.9.4:
>
> --------PROGRAM FOLLOWS---------
>
> #!/usr/local/bin/perl5.9.4
>
> use strict;
> use warnings;
> use Date::Parse;
> my $reverser = -1;
>
> printf ("Perl version: %vd\n", $^V);
> printf ("Date::Parse version: $Date::Parse::VERSION\n");
> # print '-------------------', "\n";
>
> # Use a sorting function that is NOT a closure.
> my $sortfn1 = sub {
> my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
> -1 * ($c <=> $d);
> };
>
> # Use a sorting function that IS a closure.
> my $sortfn2 = sub {
> my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
> $reverser * ($c <=> $d);
> };
>
> # Load the data while making everything upper case.
> my @data = map uc $_, <DATA>;
>
> # If the the result of using $sortfn2 is different from
> # the result of using $sortfn1, this perl interpreter
> # is buggy.
> my $usingfn1 = join '', sort $sortfn1 @data;
> my $usingfn2 = join '', sort $sortfn2 @data;
>
> if ($usingfn1 ne $usingfn2) {
> print "We have a buggy perl here.\n";
> }
>
>
> __DATA__
> irongeek ttypi Wed Nov 15 17:27
> lar ttyp2 Fri Nov 17 17:12
> lar ttypa Fri Nov 17 15:53
> lar ttypp Thu Nov 16 17:11
> lar ttypk Thu Nov 16 14:20
> sabre ttyp5 Wed Nov 15 13:59
> lar ttyp5 Wed Nov 15 13:57
> sabre ttyp5 Wed Nov 15 13:28
> sabre ttypc Wed Nov 15 12:10
> lar ttypn Thu Nov 16 13:23
> lar ttypd Fri Nov 17 07:27
> irongeek ttyp2 Thu Nov 16 07:49
> sabre ttypg Sat Nov 11 15:56
> -------------OUTPUT FOLLOWS--------------
> Perl version: 5.9.4
> Date::Parse version: 2.27
> We have a buggy perl here.
> -------------OUTPUT ENDS-----------------
>
> That program demonstrates that when the sorting subroutine is not a
> closure, the lowercasing effect of Date::Parse::str2time is NOT
> permitted to modify the original data, and when the sorting subroutine
> IS a closure, the lowercasing effect of Date::Parse::str2time IS
> permitted to modify the original data.
>
> This is probably a bug in the perl interpreter.
>
> I'm using Debian GNU/Linux 3.1 i386.
>
> ---
> Flags:
> category=
> severity=
> ---
> Site configuration information for perl 5.9.4:
>
> Configured by (user) at Mon Nov 20 03:07:07 CST 2006.
>
> Summary of my perl5 (revision 5 version 9 subversion 4) configuration:
> Platform:
> osname=linux, osvers=2.4.27-3-386,
> archname=i686-linux-thread-multi-64int
> uname='linux dike 2.4.27-3-386 #1 thu sep 14 08:44:58 utc 2006 i686
> gnulinux '
> config_args='-Dusethreads -Dprefix=/usr/local/share/perl-5.9
> -Duse64bitint -Dcc=gcc -Dusedevel -Duseperlio -Dman1ext=1perl
> -Dman3ext=3perl -de'
> hint=recommended, useposix=true, d_sigaction=define
> useithreads=define, usemultiplicity=define
> useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
> use64bitint=define, use64bitall=undef, uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
> Compiler:
> cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
> -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
> -D_FILE_OFFSET_BITS=64',
> optimize='-O2',
> cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
> -fno-strict-aliasing -pipe -I/usr/local/include'
> ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-13)', gccosandvers=''
> intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
> ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
> Off_t='off_t', lseeksize=8
> alignbytes=4, prototype=define
> Linker and Libraries:
> ld='gcc', ldflags =' -L/usr/local/lib'
> libpth=/usr/local/lib /lib /usr/lib
> libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
> perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
> libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
> gnulibc_version='2.3.2'
> Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
> cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
>
> Locally applied patches:
>
>
> ---
> @INC for perl 5.9.4:
> /usr/local/lib/CPAN/share/perl
> /usr/local/lib/CPAN/lib/perl
> /usr/local/lib/CPAN/lib/site_perl/5.9.4/i686-linux-thread-multi-64int
> /usr/local/lib/CPAN/lib/site_perl/5.9.4
> /usr/local/share/perl-5.9/lib/5.9.4/i686-linux-thread-multi-64int
> /usr/local/share/perl-5.9/lib/5.9.4
>
> /usr/local/share/perl-5.9/lib/site_perl/5.9.4/i686-linux-thread-multi-64int
> /usr/local/share/perl-5.9/lib/site_perl/5.9.4
> .
>
> ---
> Environment for perl 5.9.4:
> HOME=/home/(user)
> LANG=en_US
> LANGUAGE=en_US:en_GB:en
> LC_CTYPE=en_US.ISO-8859-1
> LD_LIBRARY_PATH (unset)
> LOGDIR (unset)
>
> PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin:.:/home/(user)/bin:/usr/local/share/perl-5.9/bin
>
>
> PERL5LIB=/usr/local/lib/CPAN/share/perl:/usr/local/lib/CPAN/lib/perl:/usr/local/lib/CPAN/lib/site_perl/5.9.4
>
> PERL_BADLANG (unset)
> SHELL=/bin/bash
>
>
>
There are a few workarounds for this bug:
1) Copy the value returned by substr() using "my":
my ($c, $d) = map str2time(my $vv = substr($_, 27)), ($a, $b);
2) Create copies of $a and $b before giving them to map:
my @copies = ($a, $b);
my ($c, $d) = map str2time(substr($_, 27)), @copies;
... or do it in one line ...
my ($c, $d) = map str2time(substr($_, 27)), @{[ $a, $b ]};
... or, for the truly exotic ...
my ($c, $d) = map str2time(substr($_, 27)), sub { @_ }->($a, $b);
3) Sidestep the whole issue of substr() by extracting the data using a
match (it's almost cheating :-P ):
my ($c, $d) = map str2time((/^.{25}(.*)$/)[0]), ($a, $b);
4) Make $reverser a package variable (declared with our) and access it
through the symbol table:
our $reverser = -1;
my $sortfn = sub {
my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
${*reverser} * ($c <=> $d);
};
Note that the bug still occurs if $reverser is accessed directly--even
as a package variable.
5) Use the environment hash %ENV:
$ENV{REVERSER} = '-1';
my $sortfn = sub {
my ($c, $d) = map str2time(substr($_, 27)), ($a, $b);
$ENV{REVERSER} * ($c <=> $d);
};
Note that using normal hashers--declared either "my" our "our"--allows
the bug to happen.
6) Use a named (non-anonymous) comparison subroutine.
--
paduille.4060.mumia.w@earthlink.net
------------------------------
Date: 20 Nov 2006 06:31:02 -0800
From: "robertospara" <robertospara@gmail.com>
Subject: Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U can help??
Message-Id: <1164033062.222273.209290@e3g2000cwe.googlegroups.com>
Don't piss me off Deutche Jurgen ...
On 20 Lis, 14:35, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> robertospara wrote:
> > So MONKS OF THE PERL
> > ???????????????????????????????????????????????????????
> > Are you still
> > ALIVE?????????????????????????????????????????????????????????????Would=
you mind
> - not top posting?
> - not full quoting?
> - repairing your keyboard?
>=20
> jue
------------------------------
Date: Mon, 20 Nov 2006 11:48:56 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.17 How can I access a dynamic variable while a similarly named lexical is in scope?
Message-Id: <201120061148565288%brian.d.foy@gmail.com>
In article <1164005075.599296.97040@h48g2000cwc.googlegroups.com>, R
Krause <rkrause@searstower.org> wrote:
> There is a third way which isn't mentioned in the FAQ. It bypasses the
> need for a package name, and simply looks in the current symbol table.
>
> print "lexical is $var\n";
> print "global is ${*var}\n"; # grab the scalar entry
We don't mention that on purpose :)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Mon, 20 Nov 2006 15:04:53 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Fetching input character without newline?
Message-Id: <puj8h.1219$tM1.556@newsread1.news.pas.earthlink.net>
On 11/19/2006 10:33 PM, Mark wrote:
> "DJ Stunks" <DJStunks@gmail.com> wrote:
>> I think you should try using Term::ReadKey a little harder...
>
> (pours a gin & tonic...)
>
> Ok, this is as close as I can get to what I was trying to describe:
>
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> use Term::ReadKey;
>
> ReadMode 3;
> $key = "";
> print "Your input? [(Y)es|(N)o|(Q)uit]: ";
> while ($key !~ /^[y|n|q]$/i)
> {
> $key = ReadKey 0;
> }
> printf "\nYou entered $key\n";
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
> Actually this is probably what I _should_ have been trying
> to come up with. Incorrect responses are not echoed on
> screen; a correct response is processed.
>
> What I was _trying_ to get was the behavior that this script
> provides, with incorrect respones being echoed onscreen,
> with the list of incorrect respones growing towards the right
> until a correct resonse is eventually given. But this is probably
> a more sensible implementation.
>
> But if anyone knows how to implement this script with the
> incorrect responses echoed on screen, I would like to see it.
>
> Thanks
> -Mark
>
>
use Term::ReadKey;
ReadMode 3;
my $key;
my $continue = 1;
while ($continue) {
print "Your input? [(Y)es|(N)o|(Q)uit]: ";
$key = ReadKey 0;
if ($key =~ /^([^ynq])$/i) {
print "You pressed $key\n";
} else {
$continue = 0;
}
}
ReadMode 0;
--
paduille.4060.mumia.w@earthlink.net
------------------------------
Date: Mon, 20 Nov 2006 07:45:03 -0800
From: "Mark" <anon40629@hotmail.com>
Subject: Re: Fetching input character without newline?
Message-Id: <1164037501.563020@bubbleator.drizzle.com>
"robertospara" <robertospara@gmail.com> wrote:
> It's your code. How can we solve problems from your post when there
> were to many mistakes in it?
http://www.geocities.com/p_v_nikitin/Photos/Troll.JPG
------------------------------
Date: Mon, 20 Nov 2006 07:49:23 -0800
From: "Mark" <anon40629@hotmail.com>
Subject: Re: Fetching input character without newline?
Message-Id: <1164037759.911295@bubbleator.drizzle.com>
"Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net> wrote:
>
> use Term::ReadKey;
> ReadMode 3;
> my $key;
> my $continue = 1;
>
> while ($continue) {
> print "Your input? [(Y)es|(N)o|(Q)uit]: ";
> $key = ReadKey 0;
> if ($key =~ /^([^ynq])$/i) {
> print "You pressed $key\n";
> } else {
> $continue = 0;
> }
> }
>
> ReadMode 0;
Hmm. . .this echoes the incorrect response and then reprints the prompt
on the next line. Still not quite what I had been looking for. Good try
though.
-Mark
------------------------------
Date: Mon, 20 Nov 2006 07:52:28 -0800
From: "Mark" <anon40629@hotmail.com>
Subject: Re: Fetching input character without newline?
Message-Id: <1164037944.900847@bubbleator.drizzle.com>
<anno4000@radom.zrz.tu-berlin.de> wrote:
>
> Don't use printf() when you mean print(). What would happen if
> the user entered '%'?.
Oops...typo. I never (intentionally) use printf in Perl.
I do use sprintf() though.
>>
>> But if anyone knows how to implement this script with the
>> incorrect responses echoed on screen, I would like to see it.
>
> Just add your own echoing:
>
> print "Your input? [(Y)es|(N)o|(Q)uit]: ";
> my $key = '';
> ReadMode 3;
> while ( $key !~ /^[y|n|q]$/i ) {
> print( $key = ReadKey 0);
> }
> ReadMode 0;
> print "\n";
> print "User chose $key\n";
Cool! That did it. Thanks.
-Mark
------------------------------
Date: Mon, 20 Nov 2006 15:04:55 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <ruj8h.1220$tM1.25@newsread1.news.pas.earthlink.net>
On 11/20/2006 01:27 AM, R Krause wrote:
> I know that $/ is the input record separator. But that doesn't seem to
> affect any change in the behavior of regular expressions in normal and
> multi-line mode.
>
> For example, this returns false since we end the string with a CR
> instead of a LF:
>
> $var = "Hello\r";
> return 1 if( $var =~ m/^Hello$/ );
>
> How does one change the default newline character used in pattern
> matching operations? Is there a Perl variable that can be set?
>
> TIA,
> --Randall
>
There is no Perl variable for that; you would have to match the \r yourself:
m/^Hello\r/
--
paduille.4060.mumia.w@earthlink.net
------------------------------
Date: 20 Nov 2006 07:10:05 -0800
From: "R Krause" <rkrause@searstower.org>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <1164035405.224078.19860@m7g2000cwm.googlegroups.com>
Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> R Krause
> <rkrause@searstower.org>], who wrote in article <1164007677.453234.10380@k70g2000cwa.googlegroups.com>:
> > $var = "Hello\r";
> > return 1 if( $var =~ m/^Hello$/ );
>
> > How does one change the default newline character used in pattern
> > matching operations?
>
> Usually, one won't need to do this. My bet is that you do something
> in a very far from optimal way
[..]
> P.S. Do not forget that (in //m mode) $ is just a shortcut for
> (?=\n|\z), and ^ for (?:\A|(?<=\n)). Likewise for no //m.
Thanks. It's mostly theoretical. After all '$' and '^' and '\Z' do
exist for convenience as you've shown in the hint above. I was testing
my code and it occured to me that this behavior cannot be changed. As
far as being optimal, it is curious why Perl has certain predefined
variables that can be changed at all since, to be fair, programmers
should never have to modify '$/', '$\', or '$,' to perform any I/O
operations. Yet, they exist for efficiency when needed.
Likewise, Perl's presumption that a newline in pattern matching is
always '\n' is heavily machine dependent which is unusual since I
thought that functions like chomp( ) were created to correct for this
mistaken notion. Yet, now I realize that Perl's regexps still encourage
chop( )-like behavior, which is the poor-man's solution for processing
the end-of-line.
--Randall
------------------------------
Date: 20 Nov 2006 06:28:00 -0800
From: "Kuna" <kunanu@gmail.com>
Subject: How to post back the data by selecting a value from drop down list
Message-Id: <1164032880.243807.46560@f16g2000cwb.googlegroups.com>
Hi All,
I have a problem in populating data by selecting a value from a drop
down list I do not have the sample code for this, so I am extremly
sorry but I can explain my problem.
I have a HTML form and I will convert the form to a .pl (PERL) script.
In the form I have a drop down list which will have the values 1 to 5
to allow me enter that much number of information in some trext fields
like First Name:, Last Name:, Phone Number:. Hence I need the form will
reload after selecting a value from the drop down only it suppose to
generate the fields according to the numbers I had selected. So pease
help me, its urgent for me. I will be grateful to you all.
Thanks in Advance,
Kuna :)
------------------------------
Date: 20 Nov 2006 06:40:34 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to post back the data by selecting a value from drop down list
Message-Id: <1164033634.499066.46310@j44g2000cwa.googlegroups.com>
Kuna wrote:
> I have a problem in populating data by selecting a value from a drop
> down list I do not have the sample code for this
That is nonsensical. If you have a problem that you're currently
working on, you have the code. You say as much later on - that you
"have a HTML form".
> , so I am extremly
> sorry but I can explain my problem.
>
> I have a HTML form and I will convert the form to a .pl (PERL) script.
HTML cannot be converted to Perl. That is also nonsensical. Do you
mean that the action of the form is a CGI script written in Perl?
> In the form I have a drop down list which will have the values 1 to 5
> to allow me enter that much number of information in some trext fields
> like First Name:, Last Name:, Phone Number:. Hence I need the form will
> reload after selecting a value from the drop down only it suppose to
> generate the fields according to the numbers I had selected.
This has NOTHING to do with Perl. It has everything to do with HTML
and Javascript. If you want something to happen client-side when you
select an option on the <select> tag, you need to use Javascript.
That's true whether what you want to happen is either A) populate or
manipulate the form inputs directly or B) submit the form to the CGI
script, which will process the posted data and output a new HTML form.
> So pease
> help me, its urgent for me. I will be grateful to you all.
This kind of notation is likely to get you *less* help, not more. An
urgency for you is a failure to plan on your part, not an emergency on
ours.
To maximize the help you can get from this group, please read the
Posting Guidelines, posted here twice each week.
Paul Lalli
------------------------------
Date: 20 Nov 2006 06:53:27 -0800
From: "Kuna" <kunanu@gmail.com>
Subject: Re: How to post back the data by selecting a value from drop down list
Message-Id: <1164034407.382761.48120@h48g2000cwc.googlegroups.com>
Paul Lalli wrote:
> Kuna wrote:
> > I have a problem in populating data by selecting a value from a drop
> > down list I do not have the sample code for this
>
> That is nonsensical. If you have a problem that you're currently
> working on, you have the code. You say as much later on - that you
> "have a HTML form".
>
> > , so I am extremly
> > sorry but I can explain my problem.
> >
> > I have a HTML form and I will convert the form to a .pl (PERL) script.
>
> HTML cannot be converted to Perl. That is also nonsensical. Do you
> mean that the action of the form is a CGI script written in Perl?
>
> > In the form I have a drop down list which will have the values 1 to 5
> > to allow me enter that much number of information in some trext fields
> > like First Name:, Last Name:, Phone Number:. Hence I need the form will
> > reload after selecting a value from the drop down only it suppose to
> > generate the fields according to the numbers I had selected.
>
> This has NOTHING to do with Perl. It has everything to do with HTML
> and Javascript. If you want something to happen client-side when you
> select an option on the <select> tag, you need to use Javascript.
> That's true whether what you want to happen is either A) populate or
> manipulate the form inputs directly or B) submit the form to the CGI
> script, which will process the posted data and output a new HTML form.
>
> > So pease
> > help me, its urgent for me. I will be grateful to you all.
>
> This kind of notation is likely to get you *less* help, not more. An
> urgency for you is a failure to plan on your part, not an emergency on
> ours.
>
> To maximize the help you can get from this group, please read the
> Posting Guidelines, posted here twice each week.
>
> Paul Lalli
Thanks Paul,
I got your point that we can only use JavaScript for this purpose. I
was new to these so I am not familiar with all those things so I am
sorry again for the less information I had provided. I will must go
through the posting guidelines before posting my next post.
Thanks again,
Kuna :)
------------------------------
Date: Mon, 20 Nov 2006 16:24:00 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to post back the data by selecting a value from drop down list
Message-Id: <4sdvkiFv4oc0U1@mid.individual.net>
Kuna wrote:
> I got your point that we can only use JavaScript for this purpose.
That's not what Paul told you.
Actually I just posted some Perl code at
http://www.thescripts.com/forum/thread566345.html
> I will must go
> through the posting guidelines before posting my next post.
Yeah, you'd better do that. But even more imporant is that you stop
multi-posting: http://lipas.uwasa.fi/~ts/http/crospost.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 9987
***************************************