Date: Sat, 22 Sep 2001 19:22:17 GMT From: laura_fairhead@my-deja.com (laura fairhead) Subject: Re: extra newline in s command Message-Id: <3bace3a7.94715075@news.cis.dfn.de> On Sat, 22 Sep 2001 17:54:29 GMT, friedman@math.utexas.edu (Chas Friedman) wrote: >On Sat, 22 Sep 2001 17:23:40 GMT, laura_fairhead@my-deja.com (laura >fairhead) wrote: > >>Hi, >> >>Can anyone explain to me why I'm getting extra >>newlines inserted with the s/// command in this >>script; >> >>open(FILE,qq[patternfile]) >>@k=(qq[0000],) >>while(<>){ >> /(\d{4})/&& $1<=$#k && s/$1/$k[$1]/ >> print >> } >> >> >>Every line that has an s/// done on it has >>an extra newline and I don't see why it's >>doing that. >> >>It is suppossed to replace occurances of 4 digit >>numerics with what is on that line in 'patternfile' >>This is my 1st attempt at 'perl' so pleaze be >>easy on me.... is this a reasonable way of doing >>this or is there a better one? Also, can I read a file >>into an array in just one command? >> >>thanx >> >>-- >>: ${L:-aura} # http://lf.8k.com:80 >> >Well, your code won't even compile, because several semicolons are >missing. >Assuming your actual code doesn't have this problem, you are >probably getting the newlines from the lines in patternfile. > chas Okay. I found out a solution using 'chop' although it means that I had to increase the first array element by 1 character (there is no way to do a 'chop()' and put it in the list is there? ) open(FILE,qq[K]); chop(@k=(qq[0000x],)); while(<>){ /(\d{4})/&& $1<=$#k && s/$1/$k[$1]/; print ; } byefornow, -- : ${L:-aura} # http://lf.8k.com:80