Prev: FAQ 9.11 How do I redirect to another page?
Next: FAQ 7.18 How can I access a dynamic variable while a similarly named lexical is in scope?
From: ccc31807 on 7 Aug 2010 08:59 On Aug 7, 7:35 am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: > How did you get that idea? "#" is a very common comment character in > config files and code like > > while (<$config_h>) { > chomp; > s/#.*//; > my ($key, $value) = split(/\s*=\s*/, $_, 2); > next unless $key; > ... > } > > is a common way to ignore the comments. And now you have a config file > Obviously that's not exactly what happened in Carter's case, because he > mentioned only "lines beginning with #", so he probably has an even simpler The line of code was: next if /^#/; The input file looks like this: #User's name username=Joe #User's password password=secret The input file is constructed from user input reading from a script like this: print "Enter your user name: "; chomp($username = <STDIN>); print "Enter your password: "; chomp($password = <STDIN>); My 'fix' was to make a double sharp (##) the comment character. Some day, a user will enter a value beginning with a double sharp, and that will be another 'bug' that testing didn't uncover. CC.
From: sln on 7 Aug 2010 12:30
On Sat, 7 Aug 2010 05:59:01 -0700 (PDT), ccc31807 <cartercc(a)gmail.com> wrote: >On Aug 7, 7:35�am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: >> How did you get that idea? "#" is a very common comment character in >> config files and code like >> >> � � while (<$config_h>) { >> � � � � chomp; >> � � � � s/#.*//; >> � � � � my ($key, $value) = split(/\s*=\s*/, $_, 2); >> � � � � next unless $key; >> � � � � ... >> � � } >> >> is a common way to ignore the comments. And now you have a config file >> Obviously that's not exactly what happened in Carter's case, because he >> mentioned only "lines beginning with #", so he probably has an even simpler > >The line of code was: > >next if /^#/; > >The input file looks like this: > >#User's name >username=Joe >#User's password >password=secret > >The input file is constructed from user input reading from a script >like this: > >print "Enter your user name: "; >chomp($username = <STDIN>); >print "Enter your password: "; >chomp($password = <STDIN>); > >My 'fix' was to make a double sharp (##) the comment character. Some >day, a user will enter a value beginning with a double sharp, and that >will be another 'bug' that testing didn't uncover. > >CC. next if "#User's password" =~ /^#/; passes next if "password=#secret" =~ /^#/; fails -sln |