Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Finding pattern in a file

by swl (Priest)
on Apr 14, 2020 at 06:29 UTC ( #11115502=note: print w/replies, xml ) Need Help??

in reply to Finding pattern in a file

It's close, although your code does not specify the mode to open the file with, and has the if condition outside the while loop, so won't work.

It's also better to use lexical file handles.

Untested modified code is below. I've also done some minor formatting changes, but avoided too many as it can become a matter of aesthetics.

my $fname = "file,fasta"; open my $fh, '<', $fname or die "Cannot open $fname, $!"; while (my $line = <$fh>) { chomp $line; if ($line =~ /CDECGKEFSQGAHLQTHQKVH/) { print "The protein contains the domain"; } else { print "The protein doesn't contain the domain"; } }

See also open and perlvar.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2020-10-21 14:02 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (217 votes). Check out past polls.