Jan 19, 2005, 4:13 PM
Post #24 of 33
Re: [sfo_sc] Read a file from a specific line and extract something to another file
[In reply to]
Thank you very much for your detail explaination. This is really helpful for a new perl coder like myself.
Actually, I just get into another problem when I am writing this script.
Notice there is a empty line after "Caused by: ..." line. I want to have the code when ever it sees the empty line, push that line to the file or something. By using the =~ m/\n/, it didn't catch the empty line. I also try to use <null>, it also failed. Can any one tell me how do I compare the empty string match?
I'm not sure why you wpould want to push an empty line into an array, but you could just skip empty lines. Normally when looping through lines of text you chomp them, which removes the newline charater, then you can check if a line is empty with a regexp and use the next command to go to the next line
next if ($string /^$/);
as Dave said, you do not have to use the "m" operator for a match, it is implied, so my exmple does not have it. If you are not using an implict variable such as $string, you can just say:
next if (/^$/);
The "^" is the start of string anchor and the "$" is the end of string anchor. So using ^$ with nothing between is an empty line. If you think there might be some spaces only, you could do this:
next if (/^\s*$/);
which is a line with only zero or more spaces in it.
Pay particular attention to anything Dave has to say, he is not only an experienced perl programmer, he can also explain perl better than anyone I have ever come across on the internet, and he will not talk down to or be insulting to newbies like some people on other forums are. He is an invaluable resource, and I mean that sincerely.