Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

vstring strings not "ordinary" #3429

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#5837 (status was 'resolved')

Searchable as RT5837$

p5pRT commented 23 years ago

From vicki.brown@barclaysglobal.com

The Camel states on p. 671 that "ordinary string comparisons can be used to determinewhether the Perl interpreter executing your script is in the right range of versions" (this may be a "bug in the book").

The example is

  warn "No 'our' declarations!\n" if $^V lt v5.6;

which does\, in fact work under Perl 5.6.0

However\, I expect string comparisons to work when quoted; I'm not a fan of barewords. Consequently\, I was surprised that

  warn "No 'our' declarations!\n" if $^V lt "v5.6";

and

  warn "No 'our' declarations!\n" if $^V lt 'v5.6';

do not act as expected (that is\, the if test fails).

Steps to reproduce

  print "Running Perl version $]\n";   print "Running Perl version ";   printf ("%vd\n"\, $^V); # uninitialized var in 5.004 and 5.00503  
  warn "1 No 'our' declarations!\n" if $^V lt v5.6;   warn "2 No 'our' declarations!\n" if ($^V lt v5.6);   warn "3 No 'our' declarations!\n" if $^V lt "v5.6";   warn "4 No 'our' declarations!\n" if ($^V lt "v5.6");   warn "3 No 'our' declarations!\n" if $^V lt 'v5.6';   warn "4 No 'our' declarations!\n" if ($^V lt 'v5.6');

prints

Running Perl version 5.006 Running Perl version 5.6.0 3 No 'our' declarations! 4 No 'our' declarations! 3 No 'our' declarations! 4 No 'our' declarations!

Perl Info ``` Flags: category=core severity=low Site configuration information for perl v5.6.0: Configured by jacobc at Tue Jun 13 16:36:22 PDT 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=solaris, osvers=2.6, archname=sun4-solaris uname='sunos aa-backup1 5.6 generic_105181-15 sun4u sparc sunw,ultra-2 ' config_args='-Dprefix=/usr/local/tools/perl-5.6.0' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='cc', optimize='-O', gccversion= cppflags='-I/usr/local/include' ccflags ='-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' stdchar='unsigned char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib -L/usr/local/SUNWspro/SC4.2/lib ' libpth=/usr/local/lib /usr/local/SUNWspro/SC4.2/lib /lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec libc=, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-KPIC', lddlflags='-G -L/usr/local/lib -L/usr/local/SUNWspro/SC4.2/lib' Locally applied patches: @INC for perl v5.6.0: /usr/local/tools/perl-5.6.0/lib/5.6.0/sun4-solaris /usr/local/tools/perl-5.6.0/lib/5.6.0 /usr/local/tools/perl-5.6.0/lib/site_perl/5.6.0/sun4-solaris /usr/local/tools/perl-5.6.0/lib/site_perl/5.6.0 /usr/local/tools/perl-5.6.0/lib/site_perl . Environment for perl v5.6.0: HOME=/ext203/home/browvic LANG (unset) LANGUAGE (unset) LC_COLLATE=en_US LC_CTYPE=en_US LC_MESSAGES=C LC_MONETARY=en_US LC_NUMERIC=en_US LC_TIME=en_US LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=~/bin/perlbin:/ext203/home/browvic/bin:/ext203/home/browvic/nib:/usr/local/bin:/usr/ucb:/usr/bin:/bin:/etc:/sbin:/usr/sbin:/usr/games:.:/net/asg-sf03/prod/sybase/bin:/usr/lib/lp/postscript:~/Work/bagelbin:~/Work/Bins PERL_BADLANG (unset) SHELL=/bin/tcsh ```
p5pRT commented 23 years ago

From @tamias

On Fri\, Feb 16\, 2001 at 01​:13​:37PM -0800\, vicki.brown@​barclaysglobal.com wrote​:

However\, I expect string comparisons to work when quoted; I'm not a fan of barewords. Consequently\, I was surprised that

warn "No 'our' declarations!\n" if $^V lt "v5.6";

and

warn "No 'our' declarations!\n" if $^V lt 'v5.6';

do not act as expected (that is\, the if test fails).

They act as I expected...

perldoc perldata​:

  A literal of the form v1.20.300.4000 is parsed as a string composed   of characters with the specified ordinals. This provides an   alternative\, more readable way to construct strings\, rather than use   the somewhat less readable interpolation form   "\x{1}\x{14}\x{12c}\x{fa0}".

Ronald