Reputation: 83
I'm trying to split a $string that is inputted into a webform made using CGI.pm
The split is on '>' and I have it working from the command line using shift to get the file into the script however using the webform doesn't work - i.e. I get no output. This works from the command line using shift to get the read in the file as follows:
my $inFile = shift;
open (IN, "$inFile");
$/ = ">";
while ( my $record = <IN> ) {
chomp $record;
my ($defLine, @seqLines) = split /\n/, $record;
my $sequence = join('',@seqLines);
however, using the code below in a cgi script does not work - I guess the cgi script is forcing a $string? but I'm not sure how to proceed
use CGI qw(:cgi-lib :standard);
print "Content-type: text/html\n\n";
my $seq = param('sequence');
$/ = ">";
chomp $seq;
my ($defLine, @seqLines) = split /\n/, $seq;
any advice, greatly appreciated
Upvotes: 1
Views: 188
Reputation: 385657
What you have for a file:
local $/ = ">";
while (my $record = <IN>) {
chomp($record);
my ($defLine, @seqLines) = split /\n/, $record;
my $sequence = join('',@seqLines);
...
}
Equivalent for a string:
for my $record (split />/, $sequence) {
my ($defLine, @seqLines) = split /\n/, $record;
my $sequence = join('',@seqLines);
...
}
Upvotes: 2