wolverina has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File glitch
by tachyon (Chancellor) on Dec 21, 2003 at 00:38 UTC | |
Any Idea's? Your code is broken? Seriously how on earth is anybody supposed to help you? Here is your question with some annotation I have a script that process several files.. all work fine except for one. Fine we got that but do you think that a) Showing some details of the script and b) Showning some details of the files you are parsing, particularly the one that does not work might be helpful? The end of the line is cut off- mysite.com/stuff/file.htm Eh, you have half a link (no http) and the trailing section of some javascript on 2 lines by the look of it. You call it cut off but the first line is complete and the second line is rubbish. This link is placed in a javascript and results in an error. And this is a suprise? If i insert the cutoff portion on the end of the line- mysite.com/stuff/file.htm";}//--> the link works fine in a javascript. You must be using a different version to the rest of us as what you posted is not valid JS. However I can guess that what you really have is something like:
So what you really mean is that you have found that quoted strings in javascript can't have real newlines embedded in them (unlike perl where you can do that). In fact you could have been helpful an said that the error you get is Unterminated String Constant. Although this error message evidently does not ring any bells with you it will with other people. Seems to me the line should process regardless of whether it's cut off or not. It has noting to do with the line being cut off per se, it is the illegal embedded newline you are including that is breaking it. Working with crappy data is a process called DATA VALIDATION and certainly something you strive for. If you want a quick fix do this. Note your underlying issues will remain but it will appear FIXED (if you define fixed as compiles OK) - this is called a KLUDGE
I would really like to know in gerneral why.. though the syntax on the link is correct, it's deemed incorrect by javascript.. The syntax is not correct. It is invalid. It is invalid in a specific way. The specific nature of the error is contained in the specific error message. As noted it is generally worthwhile to include the specific error message. It tells you/us what the compiler sees the error as. So why not ask a decent question? You might actually get a decent answer. Something like: I have the following script which is designed to extract ?links from HTML?. Here is the relevant section (show shortest possible snippet of code). Mostly it works but on this file (show file) it breaks in the following way (show way). I am using this data to insert into some Javascript I am generating with Perl. Because the data is broken this breaks. Describe how. Show sample. How can I 1) fix my parser so I get valid data and 2) add some data validation so if I still get bad data it does not explode?
cheers tachyon | [reply] [d/l] [select] |
| |
|
Re: File glitch
by b10m (Vicar) on Dec 20, 2003 at 23:29 UTC | |
I don't know much about Javascript, so I couldn't tell you wheter it mattered if there was a carriage return in the link (I think it does matter in Javascript). Also don't I know anything about the files you parse, nor the code that parses it, but I'd say a chomp might solve the problems. | [reply] |