in reply to search for a sequence of chars in a string
#/usr/bin/perl my $search = 'TTGACA'; open FILE, $ARGV[0] or die "can't open file\n"; local $/; $data = <FILE>; $data =~ s/[^GNUCAT]//g; # or similar ;-) close FILE; my $count = () = $data =~ m/$search/g; print "String $search occured $count times\n\n";
Oh you should get into the habit of closing your files after you open them. Also use strict and use warnings are good habits. Use string warnings and diagnostics or die Hard to justify for trivial cases like this but add another 50 lines and you will be glad you did.
Zaxo's index method is far more memory efficient and almost certainly faster way to do this (for an exact match).
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|