Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

CGI perl reading input from webform in order to split

by neemie (Initiate)
on Dec 02, 2014 at 19:08 UTC ( [id://1109023]=perlquestion: print w/replies, xml ) Need Help??

neemie has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: CGI perl reading input from webform in order to split
by GrandFather (Saint) on Dec 02, 2014 at 21:00 UTC

    Don't guess. Add a print statement to your code and see what you are actually getting. '>' is special in HTML and is generally encoded as &gt;. Maybe you are getting an encoded string where you expect an decoded string?

    Perl is the programming world's equivalent of English
Re: CGI perl reading input from webform in order to split
by CountZero (Bishop) on Dec 02, 2014 at 21:04 UTC
    Are you sure that $seq contains anything?

    Why don't you do a split />/, $seq directly? Globally changing $/ is not advised as it can have unexpected side-effects.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: CGI perl reading input from webform in order to split
by Anonymous Monk on Dec 02, 2014 at 21:25 UTC
    #!/usr/bin/perl -- use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI qw/ param escapeHTML header /; Main( @ARGV ); exit( 0 ); sub Main { my( $headers, $body ) = SequencePage(); print $headers, $body; } sub SequencePage { my( $defLine, @seqLines ) = split />/, param('sequence'); my $body = escapeHTML( $defLine ); $body .= "<br>".escapeHTML( $_ ) for @seqLines; return header(), $body; }
Re: CGI perl reading input from webform in order to split
by wazat (Monk) on Dec 02, 2014 at 21:04 UTC

    I've never been a heavy CGI.pm user, but one question that comes to mind is if 'sequence' is actually a file upload instead of a normal form parameter. If so, I think you need to treat param('sequence') as a filehandle.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1109023]
Approved by Laurent_R
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found