Problem using some delimiters in s///x

P

parv

I am using Perl 5.8.5 in which there seems to be problem w/ some
delimiters in s///. If not_ok* subs are uncommented (or equivalent
statements are used elsewhere), perl quits w/ the following error
message...

Substitution replacement not terminated at \
<file name> line <line number>.


Below is small test program...

# 'polka' should be transformed to 'PeeOLCa' if not_ok* subs & their
# usage are not commented
#
use warnings;
use strict;
my $p = 'polka';

ok_bra();
ok_par();

#not_ok_ex();
#not_ok_com();

print $p;

sub ok_bra { $p =~ s{k} /C/x; }
sub ok_par { $p =~ s(p) /Pee/x; }

#sub not_ok_ex { $p =~ s!o! /O/x; }
#sub not_ok_com { $p =~ s,l, /L/x; }


Perl version...

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
Platform:
osname=freebsd, osvers=4.9-release-p11, archname=i386-freebsd-64int
uname='freebsd moo.holy.cow 4.9-release-p11 freebsd 4.9-release-p11 #4: thu jul 1 23:37:18 edt 2004 (e-mail address removed):miscsrc-4.9sysbovine i386 '
config_args='-sde -Dprefix=/misc/local -Darchlib=/misc/local/lib/perl5/5.8.5/mach -Dprivlib=/misc/local/lib/perl5/5.8.5 -Dman3dir=/misc/local/lib/perl5/5.8.5/perl/man/man3 -Dman1dir=/misc/local/man/man1 -Dsitearch=/misc/local/lib/perl5/site_perl/5.8.5/mach -Dsitelib=/misc/local/lib/perl5/site_perl/5.8.5 -Dscriptdir=/misc/local/bin -Dsiteman3dir=/misc/local/lib/perl5/5.8.5/man/man3 -Dsiteman1dir=/misc/local/man/man1 -DDEBUGGING -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Doptimize=-O -pipe -g -march=pentiumpro -Duseshrplib -Dccflags=-DAPPLLIB_EXP="/misc/local/lib/perl5/5.8.5/BSDPAN" -Ud_dosuid -Di_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DAPPLLIB_EXP="/misc/local/lib/perl5/5.8.5/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include',
optimize='-O -pipe -g -march=pentiumpro',
cppflags='-DAPPLLIB_EXP="/misc/local/lib/perl5/5.8.5/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='2.95.4 20020320 [FreeBSD]', 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='cc', ldflags ='-Wl,-E -L/usr/local/lib'
libpth=/usr/lib /usr/local/lib
libs=-lgdbm -lm -lcrypt -lutil -lc
perllibs=-lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-R/misc/local/lib/perl5/5.8.5/mach/CORE'
cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING USE_64_BIT_INT USE_LARGE_FILES
Built under freebsd
Compiled at Aug 14 2004 20:35:57
%ENV:
PERL5LIB=".:/home/parv/comp/perl/dist-test/modules"
@INC:
 
U

Uri Guttman

p> I am using Perl 5.8.5 in which there seems to be problem w/ some
p> delimiters in s///. If not_ok* subs are uncommented (or equivalent
p> statements are used elsewhere), perl quits w/ the following error
p> message...

p> sub ok_bra { $p =~ s{k} /C/x; }
p> sub ok_par { $p =~ s(p) /Pee/x; }

p> #sub not_ok_ex { $p =~ s!o! /O/x; }
p> #sub not_ok_com { $p =~ s,l, /L/x; }

from perlop s///:

If the PATTERN is delimited by bracketing quotes, the
REPLACEMENT has its own pair of quotes, which may or may not be
bracketing quotes, e.g., "s(foo)(bar)" or "s<foo>/bar/".

in the first two cases you start with paired delimiters so you can use
any kind of delimiter for the replacement part. in the latter two cases
you start with a non-paired delimiter so you must use 3 of them as with
s///. the /x has nothing to do with this (other than you must escape the
closing delimiter EVEN in comments when under /x). and the sub stuff has
nothing to do with this either. you could have had shown the s///
operations all by themselves and gotten the same errors

and the paired (called bracketing in the docs) delimiters are obviously
{}, [], () and <>.

uri
 
P

parv

p> If not_ok* subs are uncommented (or equivalent
p> statements are used elsewhere), perl quits w/ the following error
p> message...

p> sub ok_bra { $p =~ s{k} /C/x; }
p> sub ok_par { $p =~ s(p) /Pee/x; }

p> #sub not_ok_ex { $p =~ s!o! /O/x; }
p> #sub not_ok_com { $p =~ s,l, /L/x; }

from perlop s///:

If the PATTERN is delimited by bracketing quotes, the
REPLACEMENT has its own pair of quotes, which may or may not be
bracketing quotes, e.g., "s(foo)(bar)" or "s<foo>/bar/".

in the first two cases you start with paired delimiters so you can
use any kind of delimiter for the replacement part. in the latter
two cases you start with a non-paired delimiter so you must use 3
of them as with s///.

I do not consider the quoted perlop portion to be clear enough; i
will have to remember that.

Sorry for the noise generation.

the /x has nothing to do with this

Well, that is how i discovered this non-problem. Otherwise, there
would have been three [!,].

the sub stuff has nothing to do with this either. you could have
had shown the s/// operations all by themselves and gotten the
same errors

I know; i had already noted that in OP in the very first paragraph.


Thanks for clarifying the issue.


- parv
 
U

Uri Guttman

p> I do not consider the quoted perlop portion to be clear enough; i
p> will have to remember that.

it seems clear to me. the pattern part delimiters determines what can be
the delimiters of the replacement part. your failing cases didn't have
paired delims so they must use that delim to close the s///.

and i don't recommend using odd (!,#) delims for s/// and m///. like
damian conway i prefer paired delims with / can't (shouldn't) be
used. his choice is {} and i generally use them now.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top