in reply to Check if a variable contains only one letter?
Use eq instead of a regex: use warnings; use strict; while (<DATA>) { chomp; print "ERROR $_\n" unless $_ eq 'X'; } __DATA__ X XA XB [download]
use warnings; use strict; while (<DATA>) { chomp; print "ERROR $_\n" unless $_ eq 'X'; } __DATA__ X XA XB [download]
agreed, I also wasted time answering another question. :(
> Check if a variable contains only one letter DB<106> $str='A B C' => "A B C" DB<107> @matches= $str=~/([A-Z])/g => ("A", "B", "C") DB<108> scalar @matches => 3 [download] DB<115> $str='A B C' => "A B C" DB<116> $str !~ /[A-Z].*[A-Z]/ => "" DB<117> $str=" A " => " A " DB<118> $str !~ /[A-Z].*[A-Z]/ => 1 [download]
> Check if a variable contains only one letter
DB<106> $str='A B C' => "A B C" DB<107> @matches= $str=~/([A-Z])/g => ("A", "B", "C") DB<108> scalar @matches => 3 [download]
DB<115> $str='A B C' => "A B C" DB<116> $str !~ /[A-Z].*[A-Z]/ => "" DB<117> $str=" A " => " A " DB<118> $str !~ /[A-Z].*[A-Z]/ => 1 [download]
Cheers Rolf
( addicted to the Perl Programming Language)