[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Splice troubles



On Wed, Nov 25, 1998 at 02:59:44PM -0000, lachlan.scott@dresdner-bank.com wrote:
} Hi all
} 
} &stdNewbieApologies; #;-)
} 
} I'm using a plain-text file (eg 'file.dat') as a simple database, and 
} reading the text into an array such that each line becomes an new array 
} item. (Learning Perl p56)
} So far so good, but I want to remove an array item (eg 
} @recordSet[$lineNumber]) from the file and thought I could use something 
} like:
} 
} open (APPEND, "+<file.dat");
} @arrayOfLines = <APPEND>;
} 
} print APPEND (splice (@arrayOfLines, 2));
} 
} #which in my stumbling Perl is supposed to say
} #remove the line with index 2 from the file
} 
} and which <irony>strangely enough,<\irony> isn't working....

What does "isn't working" mean?  Is the script doing something that
you don't want it to do?  What is it doing, and what do you want it to
do?  "My script isn't working" is not a good way to report a problem.
The first step is to give us the script or an example, which you've
done.  But you should also provide or at least describe the output
that it's giving and the output that you expected and/or wanted.

I just tried your script, and it did exactly what you're telling
it to do, appended all but the first two lines of @arrayOfLines to the
end of file.dat.  If you want to append all but line two, you have to
do it differently.  One way is this:

splice(@arrayOfLines,1,1);  #ignore the returned value

print APPEND @arrayOfLines;

(Always remember that splice modifies the @array you feed it.)

But if the criteria become more complicated, I'd just use an old
fashioned for loop:

for (@arrayOfLines) {
	print APPEND if something;
}

} 
} Can someone help?
} 
} 
} Lachlan Scott
} 
} p.s. if they were only running that Perl course in Boulder next month, 
} I'd go. But it's one thing to want to study programming in Boulder, and 
} quite another to go to *Chicago* in mid-December... >;-)
} 
} ------------------------------------------------------------
} 
} Lachlan Scott
} Global Markets Research (GMR)
} Jurgen Ponto Platz, 1. (26.110)
} Tel:	+49 (0)69 263 12903
} Fax:	+49(0)69 263 17723
} Email:	lachlan.scott@dresdnerbank.com
} 
} 

--
Paul Schinder
schinder@pobox.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch