A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia
September 3rd, 2008

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

Leave a Reply

You can use some basic tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
To get pretty code, use <code lang='php' > (or 'css' or 'perl' or whatever)