Hi, I have the following code which currently searches for specific substrings within an input file (DNA sequence):
use warnings; use strict; use File::Basename; my $name = basename($0); my $usage = "\nUsage (OSX Terminal/Windows Cmd-Prompt): perl <$name> < +.FASTA or.FA File> <Results Directory>\n\n"; #Scanning for restriction sites and length-output my $infile1 = shift or die $usage; open(my $in, "<", shift); open(my $out, ">", shift); my $DNA = read_fasta($in); my $len = length($$DNA); print "\n FASTA/Sequence Length is: $len bp \n"; my @pats=qw( GATCR GGCC ); for (@pats) { s/K/[GT]/g; s/M/[AC]/g; s/Y/[CT]/g; s/S/[CG]/g; s/W/[AT]/g; s/B/[CGT]/g; s/V/[ACG]/g; s/H/[ACT]/g; s/D/[AGT]/g; s/X/[AGCT]/g; s/R/[AG]/g; s/N/[AGCT]/g; } for (@pats) { my $m = () = $$DNA =~ /$_/gi; print "\n Total DNA matches to $_ are: $m \n"; } my $pat=join("|",@pats); my @cutarr = split(/$pat/, $$DNA); for (@cutarr) { my $len = length($_); print $out "$len \n"; } close($out); close($in); #Subfunction - Reading formatted FASTA/FA files sub read_fasta { my ($in) = @_; my $sequence = ""; while(<$in>) { my $line = $_; chomp($line); if($line =~ /^>/){ next } else { $sequence .= $line } } return(\$sequence); }
I'm not familiar much at all with user-input in Perl as I never usually bother however in this case it's required. What would be the best way to incorporate user-input into this such that the user can type in the search patterns (GATCR GGCC) etc. Thanks!

In reply to Searching for strings specified via user input by TJCooper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.