Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: =~ matches non-existent symbols

by rnewsham (Curate)
on Nov 16, 2014 at 08:58 UTC ( #1107336=note: print w/replies, xml ) Need Help??


in reply to =~ matches non-existent symbols

Another way could be to use Tie::File and grep.

use strict; use warnings; use Tie::File; die "File does not exist" unless -f $ARGV[0]; tie my @file, 'Tie::File', $ARGV[0] or die "Could not tie file"; if ( grep !/^[actg]+$/i, @file ) { print "BAD\n"; } else { print "OK\n"; }

Update: Inefficent see below update by ikegami

Replies are listed 'Best First'.
Re^2: =~ matches non-existent symbols
by ikegami (Pope) on Nov 18, 2014 at 17:38 UTC
    What a waste. This will slow down the program by so much and it'll use up so much more memory than needed. You could simply use
    use strict; use warnings; my $bad = 0; while (<>) { if (!/^[actg]+$/i) { ++$bad; last; } } print $bad ? "BAD\n" : "OK\n";

      You are correct, I had not considered how inefficent that method is. Thanks for pointing it out.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2020-12-06 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?