cgi - Perl create byte array and file stream -
i need able send file stream , byte array response http post testing of product. using cgi perl end, not familiar perl yet, , not developer, linux admin. sending string based on query strings easy, stuck on these 2 requirements. below script return page correct or incorrect depending on query string. how can add logic return filestream , byte array well?
#!/usr/bin/perl use cgi ':standard'; print header(); print start_html(); $query = new cgi; $value = $env{'query_string'}; $number = '12345'; if ( $value == $number ) { print "<h1>correct value</h1>\n"; } else { print "<h1>incorrect value, said: $value</h1>\n"; } print end_html();
glad see new people dabbling in perl sysadmin field. precisely how started.
first off, if you're going use cgi.pm module suggest use advantage throughout script. you've inputted <h1>
can use cgi object you. in end, you'll end cleaner, more manageable code:
#!/usr/bin/perl use cgi ':standard'; print header(); print start_html(); $value = $env{'query_string'}; $number = '12345'; if ( $value == $number ) { h1("correct value"); } else { h1("incorrect value, said: $value"); } print end_html();
note comparison operator (==
) work if number. make work strings well, use eq
operator.
a little clarification regarding mean regarding filestreams , byte arrays ... file stream, mean want print out file client? if so, easy as:
open(f,"/location/of/file"); while (<f>) { print $_; } close(f);
this opens file handle linked specified file, read-only, prints content line line, closes it. keep in mind print out file as-is, , not pretty in html page. if change content-type header "text/plain" more within lines of you're looking for. this, modify call prints http headers to:
print header(-type => 'text/plain');
if go route, you'll want remove start_html()
, end_html()
calls well.
as byte array, guess i'll need little bit more information being printed, , how want formatted.
Comments
Post a Comment