?
Solved

Simple TEXT Script

Posted on 1998-12-31
4
Medium Priority
?
182 Views
Last Modified: 2010-03-05

 Hi!
 I like to make a simple script that will help me solve a simple problem.
 
 here is some data from some FILES:

 alexander:data1|data29|data888
 stacey:data4|data01
 james:data8
 rick:data456|data of 27
 dan:data of 22|data of 34

 were everything need to considered as text;

 *** ALSO ***

 alexander:data1|data29|data888 -- exist in a file called a.data

 rick:data456|data of 27 -- exist in a file called r.data
etc...

 I want to do the following:

 <FORM><TEXTAREA> + SUBMIT for example "rick" with POST method(from an HTML form posted through a browser) the script will first chop "r" to go to r.data file and lookup for data for "rick" and later display on the browser this:
 
 [ Data for "rick" is: data456, data of 27 ]
 
 how can I do it in perl(text grepp)?
 is it possible ONLY in Perl; Please no shell access is available; ONLY Perl and file access is available;
 
 thank you,
 
0
Comment
Question by:elvaaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1207223
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
print header,
      start_html('Simple TEXT Script'),
      start_form,
      textfield('name'),p,
      submit,
      end_form,
      hr;
if( param() ){
    $name = param('name');
    $file = substr($name,0,1).".data";
    open FILE,"<$file" or die "can't open $file $!";
    while( <FILE> ){
        if( (split':')[0] eq $name ){
            @data=split'\|',(split':')[1];
            print qq([ Data for "$name" is: ),(join', ',@data)," ]<br>";
        }
    }
}
print end_html;

0
 

Accepted Solution

by:
tribal9 earned 200 total points
ID: 1207224
#!/usr/bin/perl

use Barecgi;
%formdata = Barecgi::parse_form();

print "Content-type: text/html\n\n";

if(!$formdata{name}) { print "No name passed to program.<br>"; }
else {

open(file, "$formdata[name][0].data");
@filedata = <file>;
chomp(@filedata);
close(file);

for($C = 0; $formdata[$C]; $C = $C + 1)
{
      ($name, $data) = split(/:/, $filedata[$C], 2);
      ($data1, $data2) = split(/|/, $filedata[$C], 2);
      if($name eq $formdata{name})
      {
             print "Match found! Data for $name is $data1 and $data2.<br>";
      }
}


               


0
 

Expert Comment

by:tribal9
ID: 1207225
Some fixes:

 ($data1, $data2) = split(/|/, $data, 2);

If name is passed, but not found in the file, then you'll get an internal server error because no HTML was sent to the browser.  Just put in something like "Thank you for using my program." at the very bottom.
0
 

Author Comment

by:elvaaa
ID: 1207226
thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question