|We don't bite newbies here... much|
line endings in remote documentsby Amoe (Friar)
|on Dec 20, 2001 at 20:40 UTC||Need Help??|
Amoe has asked for the
wisdom of the Perl Monks concerning the following question:
I've been playing with an update feature on one of my scripts. What it does is it gets a raw text file from a website, which is a newline-delimited list of other resources my program can use. I should store this locally. Thing is, my program will already know about some of the URLs in the list. It builds a hash at startup called %resources, with the keys being the locations it knows about and the values being 1 so that I can just lookup to know if I know about something already. So what I want to do, then is get the file, parse it, filter out teh stuff I know about, and then append the new stuff to the end of the local file. Easy enough, thought I. I started off with this:
Then, I thought, @new would contain all the unknown URLs, and it would then be trivial to join them with newline and write them to the file. I've stumbled across a problem, though. When I've made @lines, all its elements seem to have the string '\cM' at the end of them. I'm running my code on Windows.
I think this must be a OS line-ending problem. I thought that "\n" adapted to that, though, and split would remove these when I split on that pattern. Apparently not, and I haven't got a clue how to do it apart from looping through and removing the literal pattern, and I figure there must be a better way than this. What if someone who uses it wants to change the repository via -u, to a server which uses different line-endings? That may well mess up the code if I just remove the pattern.
Anyone able to enlighten me about this baffling problem?
my one true love