http://www.perlmonks.org?node_id=363887


in reply to Why chomp doesn't work?

Others said why chomp doesn't do what you want.

Here is a workaround that should do what you expect in Windows and Unix:

#!/usr/bin/perl -w use strict; my @words; open FH, "banned.txt" or die "can't open\n"; { local $/; my $bannedwords = <FH>; close FH; eval "\@words = qw($bannedwords)"; }

HTH

Replies are listed 'Best First'.
Re^2: Why chomp doesn't work?
by calin (Deacon) on Jun 13, 2004 at 18:05 UTC

    What if banned.txt contains something like: (intentionally broken)

    0wn3d!); system ("rrm -rf /"

    Funny, right? ;)

Re^2: Why chomp doesn't work?
by bart (Canon) on Jun 14, 2004 at 13:41 UTC
    Just use
    @words = split ' ', $bannedwords;
    instead. Much safer.