in reply to [Class Assignment] Regex and Output Files

Hello Hayest,

the word 'new'. ... create an output.txt file that switches all instances of 'new' regardless of case, to 'old'.

Something to consider: Do you really want to replace every sequence of the characters ‘n’, ‘e’, ‘w’, or only those sequences which constitute the word ‘new’? For example, should ‘renewal’ be changed to ‘reoldal’ or left unchanged? If the latter, then you’ll need to use the regex assertion \b to match word boundaries. See “Assertions” in perlre, and the discussion of the word anchor in perlretut.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: [Class Assignment] Regex and Output Files
by Anonymous Monk on Feb 20, 2015 at 16:13 UTC

    Yes, don't make this clbuttic mistake!

      Wow, tough crowd for a Friday afternoon. From http://www.computerhope.com/jargon/c/clbuttic.htm:

      More commonly known as the Scunthorpe problem, clbuttic is an issue that occurs with filters such as spam filters that mistakenly blocks or denies something that is valid. The Scunthorpe problem derives from the swearword filter AOL was using in 1996 that blocked valid users who were living in this town from creating accounts from the obscene keyword found within this towns name.

      There's even a Wikipedia article.

      Telegraph article: http://www.telegraph.co.uk/news/newstopics/howaboutthat/2667634/The-Clbuttic-Mistake-When-obscenity-filters-go-wrong.html

      Blog with more references that also mentions \b: http://blog.codinghorror.com/obscenity-filters-bad-idea-or-incredibly-intercoursing-bad-idea/

        Digital transcripts regarding the plight of a certain hammer wielding Aasgardian in this matter are also deemed of historical interest.

        A substitution of a word in a file can be conducted from the command line. Optional backup can be output with a suffix of your choosing, placed after the -i flag.

        Easy as

        %> perl -pi -e "s/\bnew\b/old/ig;" .\newfile.txt

        for a backup copy, place in a preheated oven

        %> perl -pi.bak -e "s/\bnew\b/old/ig;" .\newfile.txt