Xref: utzoo comp.lang.perl:5410 comp.sources.bugs:2925 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!kepler1!jwu From: jwu@kepler.com (Jasper Wu) Newsgroups: comp.lang.perl,comp.sources.bugs Subject: Re: BUG in interpolating and/or substituting NULs in strings? Message-ID: <589@kepler1.kepler.com> Date: 21 May 91 16:51:50 GMT References: Reply-To: jwu@kepler.com (Jasper Wu) Followup-To: comp.lang.perl Organization: Kepler Financial Management, Ltd., Setauket, NY. Lines: 70 Greg, from perl manpage on s///: ...If the PATTERN evaluates to a null string, the most recent successful regular expression is used instead.... In article gnb@bby.oz.au (Gregory N. Bond) writes: >#! /usr/local/bin/perl > >$NUL = "\0"; >$SOH = "\1"; >$STX = "\2"; >$ETX = "\3"; > >$_ = "data a${STX}data b${ETX}cc${NUL}${SOH}"; > > $p = $_; > $p =~ s/$ETX//og; > $p =~ s/$STX//og; > $p =~ s/$SOH//og; > $p =~ s/$NUL//og; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > print "[$p]\n"; > > $p = $_; > $p =~ s/$NUL//og; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > $p =~ s/$SOH//og; > $p =~ s/$STX//og; > $p =~ s/$ETX//og; > print "[$p]\n"; > both lines have $NUL evalualtes to null string, and happened to be equivalent to $p =~ s/$SOH//og; that's why you got the (undesirable) result. >leo% perl t.perl >[data adata bcc^@] >[data adata bcc^@] > To get what you want, simply not to evaluate the pattern to null string. You can either 1) change those two lines to $p =~ s/\0//og; or (preferrably) 2) change the first four lines to $NUL = \0; $SOH = \1; $STX = \2; $ETX = \3; (ie, no double quote) and keep rest of the program intact. Both ways worked fine when i tested it on my machine. Hope this helps. >Greg. >-- >Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia >Internet: gnb@melba.bby.oz.au non-MX: gnb%melba.bby.oz@uunet.uu.net >Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb --jasper ============================ Jasper Wu jwu@kepler.com