Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: =~ matches non-existent symbols

by AnomalousMonk (Archbishop)
on Nov 17, 2014 at 22:27 UTC ( [id://1107495]=note: print w/replies, xml ) Need Help??


in reply to Re: =~ matches non-existent symbols
in thread =~ matches non-existent symbols

if ( <INPUT_FILE> =~ m/[^actgACTG\s]/ ) {
    ...

Are there any potential problems with this code?

The character class  \s includes  ' ' (space, 0x20) and IIRC  \t \n \r \f other whitespace characters. Your test allows the string read from the file to have any number of any combination of these characters. Please see perlrecharclass.

I must say that I don't understand your desparate, last-ditch efforts to avoid the use of chomp, for it seems very likely that the line you're reading from your file is newline-terminated (whatever a newline happens to be in your OS). Here's how I might handle the file-read-and-validate portion of your program (untested):

use warnings; use strict; die "no filename given" unless @ARGV; my $filename = $ARGV[0]; open my $fh_input, '<', $filename or die "opening '$filename': $!"; my @lines = <$fh_input>; die "no lines read from '$filename': $!" unless @lines; close $fh_input or die "closing '$filename': $!"; chomp @lines; die "more than one line in '$filename'" unless @lines == 1; my $line = $lines[0]; die "'$filename' contains something other than ACTG sequence" if $line =~ m{ [^actgACTG] }xms; my $result = do_something_with($line); print "result is: 'result'"; exit; sub do_something_with { ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found