Not_a_Number has asked for the wisdom of the Perl Monks concerning the following question:
use CGI; print 'Your input: '; my $var = <STDIN>; chomp $var; print "\$var is '$var'"; # Output: 'var is 'foo
What's happening here? I can work around the problem by changing the chomp line to:
$var =~s/\s+$//; # Output (as expected): $var is 'foo'
I also have no problem when the scalar doesn't come from STDIN, eg:
chomp ( my $var = "foo\n" );ActiveState perl v5.8.8 (build 819) on WinXP Pro, CGI.pm version 3.20.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI, STDIN and chomp problem: bug?
by kyle (Abbot) on Jul 14, 2007 at 14:51 UTC | |
by Not_a_Number (Prior) on Jul 14, 2007 at 15:21 UTC | |
by tye (Sage) on Jul 14, 2007 at 16:25 UTC | |
by Not_a_Number (Prior) on Jul 14, 2007 at 17:23 UTC | |
by daxim (Curate) on Jul 14, 2007 at 19:54 UTC | |
by moritz (Cardinal) on Jul 15, 2007 at 13:56 UTC | |
by Not_a_Number (Prior) on Jul 15, 2007 at 15:21 UTC |