RE: [perl #18114] [no subject] BUG: "-4\n".."0\n" is not DWIM but "-4\n".."-0\n" is!

------_=_NextPart_001_01C28007.C953E480
Content-Type: text/plain;
	charset="iso-8859-1"

>> J Kimball (via RT) on Tuesday, October 29, 2002 8:49 AM 
>> On Mon, Oct 28, 2002 at 08:18:24AM -0000, a.shankar@ti.com 
>> (via RT) wrote:
>> 
>> > I wrote the following program:
>> >
>> > $w1=<STDIN>;
>> > $w2=<STDIN>;
>> > @numlist = ($w1 .. $w2);
>> > print @numlist;
>> >
>> > [run]
>> > -4 (first input)
>> > 0  (second input)
>> >
>> > it prints nothing!
>>
>> I see that you are running Perl on Windows.  Try printing a blank line
>> before you print anything else:

Im pretty sure that this is not the cause of the problem.

To which Abhishek Shankar said on  29 October 2002 04:34
> The print("\n"); is not solving the problem. In fact a new 
> problem has comes up. Under Windows if any of the inputs is 0 the program 
> fails. In Unix the input -4 and 0 prints the required list of numbers. But
the 
> inputs 0 and 4 fail to print anything.

I agree that this is a bug.  It appears to be because the strings '0\n' and
'-4\n' are not being interpreted in numeric context in the .. operator.
(Although I can't duplicate your problem with "0".."4" under unix I suspect
the solution is the same, see below.)

At first I thought this was due to the documented behaviour of the ..
operator. In that "0\n" .. "-4\n" gets evaluated.  Since neither have been
used in numeric context they are treated as strings.  Since they dont match
the rules for string increment nor for numeric arguments the range operator
returns an empty list.  Unfortunatley this explanation doesn't wash:

  E:\Bin>perl -e "print qq{-4\n}..qq{-0\n}"
  -4-3-2-10
  E:\Bin>perl -e "print 0+qq{-4\n}..0+qq{0\n}"
  -4-3-2-10

Which is more or less DWIM i think.  But this sure isnt:

  E:\Bin>perl -e "print qq{-4\n}..qq{0\n}"

  E:\Bin>

So, my vote is that this is a bug. (it works with ("-4\n".."-0\n") but not
("-4\n".."0\n") !!?) Oh, and stripping the "\n" out doesnt change the
results.

  V:\perl\lib\CPAN>perl -e "print qq{-4}..qq{0}"

  V:\perl\lib\CPAN>perl -e "print 0+qq{-4}..0+qq{0}"
  -4-3-2-10

Luckily the workaround is trivial indeed.  Simply coerce numeric context. 

  @numlist = (0+$w1 .. 0+$w2);

or

  $w1=0+<STDIN>;
  $w2=0+<STDIN>;

HTH.

Yves
ps 

Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX',
    optimize='-O1 -MD -DNDEBUG',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release
-libpath:"E:\Perl\lib\CORE"  -machine:x86'
    libpth="E:\DotNet\FrameworkSDK\Lib\" "E:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib ol
eaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.li
b oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
-libpath:"E:\Perl\lib\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEXT
PERL_IMPLICIT_SYS
  Locally applied patches:
        ActivePerl Build 633
  Built under MSWin32
  Compiled at Jun 17 2002 21:33:05



------_=_NextPart_001_01C28007.C953E480--
0
yves
10/30/2002 11:30:45 AM
perl.perl5.porters 48287 articles. 1 followers. Follow

1 Replies
776 Views

Similar Articles

[PageSpeed] 8

"Orton, Yves" <yves.orton@mciworldcom.de> writes:

> Content-type: text/plain ; charset = "iso-8859-1"
> 
> >> J Kimball (via RT) on Tuesday, October 29, 2002 8:49 AM 
> >> On Mon, Oct 28, 2002 at 08:18:24AM -0000, a.shankar@ti.com 
> >> (via RT) wrote:
> >> 
> >> > I wrote the following program:
> >> >
> >> > $w1=<STDIN>;
> >> > $w2=<STDIN>;
> >> > @numlist = ($w1 .. $w2);
> >> > print @numlist;
> >> >
> >> > [run]
> >> > -4 (first input)
> >> > 0  (second input)
> >> >
> >> > it prints nothing!
> >>
> >> I see that you are running Perl on Windows.  Try printing a blank line
> >> before you print anything else:
> 
> Im pretty sure that this is not the cause of the problem.
> 
> To which Abhishek Shankar said on  29 October 2002 04:34
> > The print("\n"); is not solving the problem. In fact a new 
> > problem has comes up. Under Windows if any of the inputs is 0 the program 
> > fails. In Unix the input -4 and 0 prints the required list of numbers. But
> the 
> > inputs 0 and 4 fail to print anything.
> 
> I agree that this is a bug.  It appears to be because the strings '0\n' and
> '-4\n' are not being interpreted in numeric context in the .. operator.
> (Although I can't duplicate your problem with "0".."4" under unix I suspect
> the solution is the same, see below.)
> 
> At first I thought this was due to the documented behaviour of the ..
> operator. In that "0\n" .. "-4\n" gets evaluated.  Since neither have been
> used in numeric context they are treated as strings.  Since they dont match
> the rules for string increment nor for numeric arguments the range operator
> returns an empty list.  Unfortunatley this explanation doesn't wash:
> 
>   E:\Bin>perl -e "print qq{-4\n}..qq{-0\n}"
>   -4-3-2-10
>   E:\Bin>perl -e "print 0+qq{-4\n}..0+qq{0\n}"
>   -4-3-2-10
> 
> Which is more or less DWIM i think.  But this sure isnt:
> 
>   E:\Bin>perl -e "print qq{-4\n}..qq{0\n}"
> 
>   E:\Bin>
> 
> So, my vote is that this is a bug. (it works with ("-4\n".."-0\n") but not
> ("-4\n".."0\n") !!?) Oh, and stripping the "\n" out doesnt change the
> results.
> 
>   V:\perl\lib\CPAN>perl -e "print qq{-4}..qq{0}"
> 
>   V:\perl\lib\CPAN>perl -e "print 0+qq{-4}..0+qq{0}"
>   -4-3-2-10
> 
> Luckily the workaround is trivial indeed.  Simply coerce numeric context. 
> 
>   @numlist = (0+$w1 .. 0+$w2);
> 
> or
> 
>   $w1=0+<STDIN>;
>   $w2=0+<STDIN>;
> 
> HTH.
> 

There is a special handling for numeric strings beginning with a "0".
This is to allow things like "01".."31" to preserve the leading zero
for one-digit numbers.

The special handling is triggered if either the left or right operand
starts with "0". For left operands this is OK but I cannot think of a
useful case where only a right operand with leading zero triggers this
handling.

OK:

$ perl -e 'print join(",", "01" .. "02"), "\n"'
01,02

Strange:

$ perl -e 'print join(",", "1" .. "02"), "\n"'
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99

With the patch below, Yves' new test cases pass (and all other tests)
and the output from the example below looks better:

$ ./perl -e 'print join(",", "1" .. "02"), "\n"'
1,2

Regards,
	Slaven

--- /usr/local/src/bleedperl/pp_ctl.c	Tue Oct 22 20:14:24 2002
+++ ./pp_ctl.c	Wed Oct 30 15:45:46 2002
@@ -946,7 +946,7 @@ PP(pp_flop)
 	if (SvNIOKp(left) || !SvPOKp(left) ||
 	    SvNIOKp(right) || !SvPOKp(right) ||
 	    (looks_like_number(left) && *SvPVX(left) != '0' &&
-	     looks_like_number(right) && *SvPVX(right) != '0'))
+	     looks_like_number(right)))
 	{
 	    if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
 		DIE(aTHX_ "Range iterator outside integer range");


-- 
Slaven Rezic - slaven.rezic@berlin.de

    tknotes - A knotes clone, written in Perl/Tk.
    http://ptktools.sourceforge.net/#tknotes
0
slaven
10/30/2002 3:22:36 PM
Reply:

Similar Artilces:

RE: "\r\n\r\n" or "\n\n" or "\r\n" or "\n"... What is the term / name for this?
Escape characters that refer to: \r = carriage return \n = newline -----Original Message----- From: LI NGOK LAM [mailto:perl@reborn.org] Sent: Saturday, July 26, 2003 02:16 PM To: beginners@perl.org Subject: "\r\n\r\n" or "\n\n" or "\r\n" or "\n"... What is the term / name for this? Does anyone have a code snippet or a module for converting the IIS log = file format to NCSA Common? Cheers, Nigel ...

"\r\n\r\n" or "\n\n" or "\r\n" or "\n"... What is the term / name for this?
------=_NextPart_000_0011_01C353E5.0AE4D150 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable ------=_NextPart_000_0011_01C353E5.0AE4D150-- ...

Swap a "1" or "0" for a "Y" or "N"
I have a sql query that returns rows of data and one field returns a 1 (which means yes) or a 0 (which means no).  On my vb.net page, how do I replace the 1 with a Yes and the 0 with a No?  Or do I do this in the sql?  How do I do this in sql?Never make important decisions on a Monday! By default, VB.Net can understand 1 as Yes and 0 as No.I believe you are using those DB values for your Boolean Operations.Try to use If <DBValue> then <Operation>. If you are really need Yes/No .... Declare boolean variable in VB.net and set those variables. Thanks and R...

about "\r\n" or "\n"
Hello,=0A=0AI created a script for checking HTTP like below:=0A=0Ause stric= t;=0Ause IO::Socket;=0A=0Amy $host =3D shift || '127.0.0.1';=0Amy $port =3D= shift || 80;=0A=0Amy $sock=3DIO::Socket::INET->new(PeerAddr =3D> $host,=0A= PeerPort =3D> $port,=0A = Proto =3D> 'tcp');=0Aunless (defined $sock) {=0A exit -1;=0A}= =0A=0A=0Aprint $sock "GET / HTTP/1.0\n\n";=0A=0A...=0A=0AFor above line, if= the remote server OS is Windows, should I send "GET / HTTP/1.0\r\n\r\n" in= stea...

Blue "N"/Red "N"
While troubleshooting a Win2k workstation running v4.9 of the Novell client, I noticed something. At the login prompt, after entering the ID/password, the animated "N" that indicates a connection attempt was blue instead of red. What does the blue "N" indicate? Mike Michael, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been resolved? If not, you might try one of the following options: - Do a search of our knowledgebase at http://supp...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

[ID 20000407.003] print \@foo=~/^ARRAY/?"yes\n":"no\n" changes behaviour in 5.6.0
This is a bug report for perl from stephen.mulcahy@compaq.com, generated with the help of perlbug 1.28 running under perl v5.6.0. ----------------------------------------------------------------- [Please enter your report here] The following codes behaviour has changed moving to 5.6.0. While accepting that ref is the correct way to do this, is this change intentional or accidental? $ perl5.6.0 -e 'print \@foo=~/^ARRAY/?"yes\n":"no\n"' no $ perl5.00503 -e 'print \@foo=~/^ARRAY/?"yes\n":"no\n"' yes Note that the follow...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

Web resources about - RE: [perl #18114] [no subject] BUG: "-4\n".."0\n" is not DWIM but "-4\n".."-0\n" is! - perl.perl5.porters

Subject (grammar) - Wikipedia, the free encyclopedia
According to a tradition associated with predicate logic and dependency grammars , the subject is the most prominent overt argument of the predicate. ...

'Filthy' Perth Chinese restaurant kitchen had been subject to health complaints
A Perth Chinese restaurant which shocked a renovation crew - and WAtoday readers - with its filthy state had twice been the subject of health ...

Rich student, poor student: what your VCE subjects say about you
&nbsp;Rich VCE students study Latin and receive bonus marks while their poor counterparts study food technology and their results are scaled ...

"And now Mary’s aggression on this subject is getting a lot less passive!"
"You two love birds keep doing what you’re doing, which is enjoying the physical aspects of the sex act without true emotional intimacy! We have ...

Self-driving cars could be subject to tough new rules
California rolls out plan to require a driver behind the wheel and other safety measures

Donald Trump Changes The Subject
Yesterday morning, I was on TV talking about Barack Obama’s anemic speech in the Oval Office, and I was promoting my latest column, titled: “How ...

‘Sicario’ Director Denis Villeneuve: “It’s Tough To Make A Movie About A Dark Subject Matter” – AwardsLine ...
Known for his dark, white-knuckle films made within the last five years, including Incendies , Enemy and Prisoners , Denis Villeneuve has secured ...

How to Secure Containers Is Still Subject to Debate
NEWS ANALYSIS: Experts agree that security is paramount when it comes to containers. Yet how to properly secure containers is still a matter ...

AP Report: U.S. Power Grid Subject To Repeated Foreign Hacks
... Press found there have been at least a dozen cyberattacks against the U.S. power grid over the last decade. The U.S. power grid is subject ...

Lord Rose And Britain In Europe Are Entirely Ignorant On The Subject Of Brexit, The EU And Trade
That we expect people to be a little free with the truth in discussions about whether Britain should leave or stay in the European Union is true. ...

Resources last updated: 12/26/2015 5:07:01 AM