in reply to Re: search for '\' in perl
in thread search for '\' in perl

Hello monks, Thanks for your fast response. after taking your suggestions i did the following changes in code
#!/usr/bin/perl -w use strict; use warnings; my $count; my @list = 'C:\username\Sources'; chomp @list; #print OUTPTR "$_\n" foreach @list; foreach my $arrchar (@list) { print "array char = $arrchar"; if($arrchar =~ m/\\/) { print "\nfound one \n"; $count += 1; } else { print"\n i am in else \n" } } print "value of count = $count";

the result is

array char = C:\username\Sources

found one

value of count = 1

i am expecting count = 2. again i am not sure why it is not working properly.

regards,

kumeperl

Replies are listed 'Best First'.
Re^3: search for '\' in perl
by Anonymous Monk on Dec 13, 2011 at 13:30 UTC
Re^3: search for '\' in perl
by TJPride (Pilgrim) on Dec 13, 2011 at 14:32 UTC
    I read that page a while ago, threw me off because the $count = (my pattern matching) format didn't seem to work. But apparently, $count = () = pattern match does, cool! I learn something new every day:

    use strict; use warnings; open (HANDLE, 'C:\username\Sources') || die; $_ = join '', <HANDLE>; my $c = () = m/\\/g; print "Found $c matches!";