Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Finding pattern in a file

by swl (Parson)
on Apr 14, 2020 at 06:29 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-03-29 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found