|
I'm an American teacher of English living in a small city 40 miles northwest of Barcelona. My website visca.com, mostly in Catalan, uses Perl and CGI.pm for a host of interactive pages. I've been using Perl since the Matt Wright days (How was a poor newbie to know?) and learned it mostly from comp.lang.perl.misc and the Camel book. Besides using Perl for interactive pages, I find it to be very useful munging text files. Since this textarea is quite large, I suppose I'm encouraged to give an example of how Perl makes life easier for me:
I have 350 lines of text like this:
I want them to be like this:9) burst into [suddenly enter] — entrar d'un cop a. ex.: He burst into + the room. 10) call for — 1 [demand] exigir. ex.: He called for an end of the war +. 2 [pick up] anar a recollir. ex.: I'll call for you at six. 3 [be t +he occasion for] ser ocasió de. ex.: This calls for an investigation +/ for a celebration.
This is the heart of what I came up with:9) <b>burst into</b> [suddenly enter] — entrar d'un cop a. ex.: <b>He +burst into the room.</b><br> 10) <b>call for</b> — 1 [demand] exigir. ex.: <b>He called for an end +of the war.</b> 2 [pick up] anar a recollir. ex.: <b>I'll call for yo +u at six.</b> 3 [be the occasion for] ser ocasió de. ex.: <b>This cal +ls for an investigation / for a celebration.</b><br>
If it weren't for perl I wouldn't have a clue how to do this except by hand. 350 lines!!while (<F>) { chomp; if (m~ 1 ~) { s~\) (.+) \—~) <b>$1</b> —~g; } else { s~\) (.+) \[~) <b>$1</b> [~; } s~(exs?)\.: (.+?)\.~$1.: <b>$2</b>.~g; s~([A-Z].+?(\.|\?|\!))~<b>$1</b>~g; print G "$_<br>\n"; }