Ignoring the module issue for the moment because you don't show what's in it, there are a few things to improve with your code as it stands:

#!/usr/bin/perl use strict; use warnings; my $filename = "record.gb"; open my $fOut, '>', $filename or die "Failed to create $filename: $!\n +"; print $fOut <<STR; LOCUS some guff ORIGIN Another line of guff // STR close $fOut; open my $fIn, '<', $filename or die "Failed to open $filename: $!\n"; #use the input seperator //\n to read a entire file to scalar my $record = do {local $/ = "//\n"; <$fIn>}; #to seperate the annotation from sequence $record =~ /^(LOCUS.*ORIGIN\s*\n)(.*)\/\/\n/s or die "Malformed record + '$record'\n"; my ($annotation, $dna) = ($1, $2); print "$annotation, $dna\n";

Prints:

LOCUS some guff ORIGIN , Another line of guff

The first block of file related stuff is just to create a file containing some test data. If you want people to be able to reproduce your issues you have to provide all the bits required. Using the script itself to generate any files you may need helps with that.

Notice that the variables are declared where they are first needed and generally they are assigned a real value at that time. Always declare variables where they are needed and no sooner so it's easy to see how they are used.

Notice that the file open statements use lexical file handles (my $fIn) and three parameter open (see open). It's also generally a good idea to die for I/O errors and report the file you were opening and the error generated by the system.

The my $record = do {local $/ = "//\n"; <$fIn>}; line localises $/ so that it can be changed within the do {} block without affecting the value of $/ outside the block. That makes changing $/ much safer and the scope of the change completely clear.

The root of your "Use of uninitialized value" error is that the match didn't find anything to match. Again, use die to report the error and give the context so figuring out what broke is easier.

Notice that annotation and dna variables are declared as a list and are assigned the values of match variables 1 and 2 after a successful match.

Premature optimization is the root of all job security

In reply to Re: Error Unitialized value and use by GrandFather
in thread Error Unitialized value and use by tryingnottofailmytes

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.