in reply to Parse one line of variables in multi-line tab delimited text file

Have you tried anything thus far mate?

Just read up on CGI for the web aspect to the problem, and do basic file processing like below for searching for the record.

use strict; use warnings; while (<DATA>) { chomp; my @vals = split "\t"; if ($vals[0] == 12345) { print "Bingo"; last; } } __DATA__ 12345 date name email 12346 date name email 12347 date name email 12348 date name email 12349 date name email 12350 date name email
  • Comment on Re: Parse one line of variables in multi-line tab delimited text file
  • Download Code

Replies are listed 'Best First'.
Re^2: Parse one line of variables in multi-line tab delimited text file
by jerryran (Initiate) on Mar 17, 2011 at 19:53 UTC
    This is REAL close, thank you.

    Instead of "Bingo," though, I would like it to print out all of the variables on that line:

    12345 date name email
      EUREKA!

      open (FILE, "<$ORDERS");
      while (<FILE>) {
      chomp;
      my @vals = split "\t";
      $order = $vals[0];
      $Date= $vals1;
      $name= $vals2;
      $email= $vals3;

      if ($vals[0] == $order) {
      print "$order";
      print "$Date";
      print "$name";
      print "$email";
      last;
      }

      }
      close (FILE);
      exit;

      THANK YOU!
Re^2: Parse one line of variables in multi-line tab delimited text file
by jerryran (Initiate) on Mar 17, 2011 at 19:44 UTC
    Thanks, I have the web part figured out. I just would like help with the code that actually stores these values in a string.

    Here's what I have so far, but it only prints out a dump of the entire text file:

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

    $ORDERS="../../orders.txt";

    open (FILE, "<$ORDERS");
    while (<FILE>) {
    chomp;
    ($number, $Date, $name, $email) = split("\t");
    print "Order: $number\n";
    print "Date of Order: $Date\n";
    print "Name: $name\n";
    print "Email: $email\n";
    print "---------\n";
    }
    close (FILE);
    exit;