Perl slurping
September 3rd, 2008It 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 <code> blocks from a file. I can simply do the following:
perl -e '$string = do {local( $/ ); <> }; $string=~s/<code>.*?<\/code>//gs; print $string;' < infile > outfile











