Perl slurping

It seems like whenever I go to slurp in a whole file into a string in Perl, I have to search around to remember the exact syntax. So I decided to put it here for myself, so I won’t have to search any further than my own site. In this particular instance, I am trying to remove any <span> blocks from a file. I can simply do the following:

perl -e '$string = do {local( $/ ); <> }; $string=~s/<span>.*?<\/span>//gs; print $string;' < infile > outfile
This entry was posted in perl. Bookmark the permalink.

Comments are closed.