|
|
| Do you know where your variables are? | |
| PerlMonks |
Re: Removing white-lines...by saintly (Scribe) |
| on Apr 06, 2007 at 02:35 UTC ( [id://608590]=note: print w/replies, xml ) | Need Help?? |
|
Should work. On an unrelated note: The 'open' command is very prone to failure on UNIX systems for lots of reasons (you don't have access to the file, it's not readable, the file's really a directory, etc...), so getting in the habit of checking it is a plus. If you use scalar filehandles, you can use them with 'my' to keep them local to your block. local $/ = undef; tells perl that newlines shouldn't be considered the 'end of input'. If you want to look at the whole file instead of individual lines, you can turn it off inside the block and the next read on the filehandle will give you the whole thing. The 's' option after the substitution regex tells perl to not treat newlines as the end of the string in a regular expression. Then you can treat them as normal characters and remove them when there are a few in a row. If lines have spaces on them (and you want to remove those 'empty' lines too), then: should work. You can do this task from the command line: Although that's technically a line-by-line approach. Update: Fixed typo ($/ not $\); Update 2:Arr! Fixed problem #2 (parens around open, cause I don't like to use 'or' instead of '||');
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||