Hi,
I need to check if string contains comma...
Wrote like ~ m/\,/ but no luck...
Also taken comma in variable and checked with ~ m/($comma)/ but this also doesn't help....
Please advise
Hi,
I need to check if string contains comma...
Wrote like ~ m/\,/ but no luck...
Also taken comma in variable and checked with ~ m/($comma)/ but this also doesn't help....
Please advise
my $var;
while(1)
{
$var=<>;
if($var=~/,/)
{
print $var;
last;
}
}
Hi , darshakraut your method also should work if your string is valid.
Try this,
if($string=~m/,/)
see the following regular expression.
if ( $val =~ m/[,]/)
[or]
if ( $val =~ m%,%)
you can change the delimiter instead of "/" like %, #, !, | etc.,
what about with a grep
if
sample="hello,fool"
then
echo "$sample" | grep -c ","
returns 1
while
sample1="not here"
echo "$sample1" | grep -c ","
returns 0
and the result could be put to a variable.