Solved

Simple TEXT Script

Posted on 1998-12-31
4
180 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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

739 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