Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: searching characters

by citromatik (Curate)
on Jun 17, 2009 at 14:40 UTC ( #772416=note: print w/ replies, xml ) Need Help??


in reply to searching characters

You can use the tr operator:

return 0 if (($line =~ tr/$base/$base/) >= $limit);

citromatik


Comment on Re: searching characters
Download Code
Replies are listed 'Best First'.
Re^2: searching characters
by ikegami (Pope) on Jun 17, 2009 at 14:51 UTC
    tr/// doesn't interpolate. You could use m// or s/// instead.
    return 0 if ( () = $line =~ /\Q$base/g ) >= $limit;
    return 0 if ( $line =~ s/\Q$base//g ) >= $limit;
Re^2: searching characters
by JavaFan (Canon) on Jun 17, 2009 at 14:46 UTC
    tr doesn't do interpolation:
    my $line = "ABABABAB"; my $limit = 3; my $base = "A"; say "Yes 1" if $line =~ tr/$base/$base/ >= $limit; say "Yes 2" if eval "\$line =~ tr/$base/$base/" >= $limit; __END__ Yes 2
    You need an eval to interpolate.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772416]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2015-07-31 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (275 votes), past polls