2

i have an array which contain (head , b , v , . , b, v, end).
i try to find and get the ".", and do sth after that (example: print out ).

for unknown reason i can't get the "."

so i did a simple code to count occurence of char inside the array. here's the code:

$stylefile="log2.style";
open ("styles", $stylefile) or die ("can't open file");

while (<styles>)
{
$temp = $_;
chomp($temp);
push @style,$temp;
}    
print @style;
# here is the array "headbv.bvend"

@bar = grep(/v/i, @style);
print @bar;
# it prints out vv

@fullstop = grep(/./i, @style);
# it prints out the entire array values.

any clue how to get occurences of "." ?

3 Answers 3

6

Use /[.]/ instead of /./ to match a full stop.

man perlre for more details.

Sign up to request clarification or add additional context in comments.

Comments

4

You also could use /\./ to match a full stop.

Test program:

$ perl -e ' $_ = "a.b.c"; @f = m/(\.)/g; print "@f\n" '
. .

Comments

1

The dot is a special character in regular expressions. It matches any character - which explains the behaviour you are seeing.

To make a special character just match itself you need to escape it with a backslash.

@fullstop = grep(/\./i, @style);

You should probably read the Perl regular expression tutorial (or reference)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.