[perl #23131] warning from perl faq that strips C and C++ comments

[email protected] (Slaven Rezic)
Newsgroups perl.perlfaq.workers
Message-ID <[email protected]>
[dcd - Sat Jul 26 11:38:47 2003]:

> 
> This is a bug report for perl from david.dyck <!--c--> <i>at</i>
<!--a--> fluke.com,
> generated with the help of perlbug 1.34 running under perl v5.9.0.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> I would think that the examples in the perl faq
> should be "warning clean", unless otherwize noted,
> or obvious from the context?
> 
> When I use the code directly from the perlfaq to remove comments
> (including C++ comments) from perlfaq6.pod
> 
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
> as the source of the perl program using perl -w ( I actually used perl
> -pwl and use the expression as the whole program) I get warnings when
> it removes both C and C++ comments from input lines.
> 
> My work around is to add a
> 	no warnings qw(uninitialized);
> line around the substitution that triggers the warning.
> 
> Even the Fred Curtis's expanded expression triggers the warning.
> 
> Perhaps a note in that faq to suggest that the user may
> want to add the above no warnings line would be appropriate.
> 

Or just check the definedness of $2, like in the attached patch.
This also fixes a missing ";" in the first code example.

Regards,
    Slaven



> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
>     category=docs
>     severity=medium
> ---
> Site configuration information for perl v5.9.0:
> 
> Configured by dcd at Tue Jul 22 08:31:10 PDT 2003.
> 
> Summary of my perl5 (revision 5.0 version 9 subversion 0 patch 20179)
>    configuration:
>   Platform:
>     osname=linux, osvers=2.4.22-pre7, archname=i686-linux
>     uname='linux dd 2.4.22-pre7 #4 sat jul 19 18:40:10 pdt 2003 i686 '
>     config_args='-Dmksymlinks -Dinstallusrbinperl -Uversiononly
>    -Dusedevel -Doptimize=-O3 -g -de -Dcf_email=david.dyck <!--c-->
<i>at</i> <!--a--> fluke.com'
>     hint=recommended, useposix=true, d_sigaction=define
>     usethreads=undef useithreads=undef usemultiplicity=undef
>     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
>     use64bitint=undef use64bitall=undef uselongdouble=undef
>     usemymalloc=n, bincompat5005=undef
>   Compiler:
>     cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing
>    -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
>     optimize='-O3 -g',
>     cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include'
>     ccversion='', gccversion='egcs-2.91.66.1 19990314/Linux (egcs-
>    1.1.2 release)', gccosandvers=''
>     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
>     d_longlong=define, longlongsize=8, d_longdbl=define,
>    longdblsize=12
>     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
>    lseeksize=4
>     alignbytes=4, prototype=define
>   Linker and Libraries:
>     ld='cc', ldflags =' -L/usr/local/lib'
>     libpth=/usr/local/lib /lib /usr/lib
>     libs=-lgdbm -ldbm -ldb -ldl -lm -lc
>     perllibs=-ldl -lm -lc
>     libc=/lib/libc.so.5.4.44, so=so, useshrplib=false,
>    libperl=libperl.a
>     gnulibc_version=''
>   Dynamic Linking:
>     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-
>    rdynamic'
>     cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
> 
> Locally applied patches:
>     DEVEL20173
> 
> ---
> @INC for perl v5.9.0:
>     /usr/local/lib/perl5/5.9.0/i686-linux
>     /usr/local/lib/perl5/5.9.0
>     /usr/local/lib/perl5/site_perl/5.9.0/i686-linux
>     /usr/local/lib/perl5/site_perl/5.9.0
>     /usr/local/lib/perl5/site_perl/5.8.0/i686-linux
>     /usr/local/lib/perl5/site_perl/5.8.0
>     /usr/local/lib/perl5/site_perl
>     .
> 
> ---
> Environment for perl v5.9.0:
>     HOME=/home/dcd
>     LANG (unset)
>     LANGUAGE (unset)
>     LD_LIBRARY_PATH (unset)
>     LOGDIR (unset)
>    
PATH=/home/dcd/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/usr/local/samba:/home/hobbes/tools/scripts:/home/hobbes/tools/linux:/usr0/hobbes/tools/scripts:/usr0/dcd/bin:/apps/general/bin:/usr/public
>     PERL5_CPANPLUS_CONFIG=/home/dcd/.cpanplus/config
>     PERL_BADLANG (unset)
>     SHELL=/bin/bash
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.