in reply to Isolating DNA cont.

Your OPed question has been well and truly answered. Here are some general comments on your posted code.

In sum, I might have written the program as follows. Again, many of the programming choices represent personal preferences; take them as you find them.

use warnings; use strict; my $usage = <<"EOT"; usage: perl $0 dna_datafile.name EOT die $usage unless @ARGV >= 1; my $filename = $ARGV[0]; my $rx_dna = qr{ \b [ATCGatcg]+ \b }xms; open my $filehandle, '<', $filename or die "opening '$filename': $!"; SEQ: while (my $seq = <$filehandle>) { next SEQ unless my ($dna) = $seq =~ m{ \A ($rx_dna) \s* \z }xms; (my $revcom = reverse $dna) =~ tr/ACGTacgt/TGCAtgca/; print "dna -> reverse complement \n"; print "'$dna' -> '$revcom' \n\n"; } close $filehandle or die "closing '$filename': $!"; exit; # define any subroutines here ######################################## +#
(See autodie to get rid of all the explicit  ... or die "...: $!"; expressions.)

Data file dna.dat:

ACTG catgataaatttccc not dna tgac

Output:

c:\@Work\Perl\monks\undergradguy>perl rev_comp_2.pl dna.dat dna -> reverse complement 'ACTG' -> 'CAGT' dna -> reverse complement 'catgataaatttccc' -> 'gggaaatttatcatg' dna -> reverse complement 'tgac' -> 'gtca'
The next step: Put the reverse complement functions into a  .pm module with an accompanying Test::More  .t file. :)

Update 1: It's true that  -w on the command line enables warnings globally (see  $^W special variable in perlvar). However,  -Mstrict on the command line still only has lexical scope, in this case the scope of the code in the  -e "..." switch. Given a module Unstrict.pm

# Unstrict.pm 22dec18waw package Unstrict; # use strict; # module will not compile with strictures enabled $string = bareword; sub func { return $string; } 1;
consider
c:\@Work\Perl\monks\undergradguy>perl -Mstrict -le "use Unstrict; print Unstrict::func(); " bareword c:\@Work\Perl\monks\undergradguy>perl -Mstrict -le "use Unstrict; print Unstrict::func(), $x; " Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. c:\@Work\Perl\monks\undergradguy>perl -wMstrict -le "use Unstrict; print Unstrict::func(); " Unquoted string "bareword" may clash with future reserved word at Unst +rict.pm line 7. bareword


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Isolating DNA cont.
by undergradguy (Novice) on Dec 21, 2018 at 20:08 UTC
    Thank you for taking the time to look at my code and make suggestions. I will look at them and learn from them. I am grateful that this community exists.