Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: =~ matches non-existent symbols

by Laurent_R (Canon)
on Nov 17, 2014 at 22:02 UTC ( [id://1107490]=note: print w/replies, xml ) Need Help??


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

It looks it will work, but only insofar you have only one long line in your file. If your file comes with more than one line, you're in trouble. I would use a loop or some other mechanism to make sure it will still work fine the day I get two or more lines. Below, I localized $/ (the input record separator) so that the whole file will be slurped into the scalar.

As a side note, there are some commonly agreed best practices in the Perl community. Among them:

  • use the use warnings; pragma rather than the -w flag
  • Use lexical filehandles rather than bareword filehandles
  • Use the three-argument syntax for the open function
Putting all this together, this a possible (untested) rewrite of your script:
#!/usr/bin/perl use strict; use warnings; my $infile = shift; open my $INPUT_FILE, "<", $infile" or die "can't open $infile: $!"; local $/; # the whole file will be slurped, even if it has several lin +es my $dna = <$INPUT_FILE>; if ( $dna =~ m/[^actg\s]/i ) { print "File contains something besides actg sequence.\n"; } else { print "good!\n"; } close $INPUT_FILE;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found