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
|