in reply to Re^2: Parsing a text file
in thread Parsing a text file
I realised as I woke up that it could be that the ^M in your code could be actual ^M characters and not the ^M that I had mistaken them for. Now that that's clear, I'd still use an explicit escape sequence e.g. \x0D (or the divinely retro \015).
I fear I didn't get the point across re the for loop... push takes a LIST of things to push onto the ARRAY. So in push @chunks, split(/\cM/, $_) the entire list returned by split is pushed onto @chunks all in one go.
The caveat about trailing separators and split can be seen in
see split. I fear I confused the issue by addressing two points in one paragraph, for which I will now do penance and hope for forgiveness from the gods of clear English.print map("'$_' ", split(/:/, 'a:b:c:::') ), "\n" ; # 'a' 'b' 'c' print map("'$_' ", split(/:/, 'a:b:c:::', -1)), "\n" ; # 'a' 'b' 'c' +'' '' ''
I note that the problem is now fixed. Since the code as posted worked on my machine, I'm particularly curious as to what the problem was.
|
|---|