Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Hi,

    Using a URL, how can I parse one line of variables from a multi-line tab-delimited text file?

    For instance:

    http://www.domain.com/cgi-bin/read.pl?order=12345

    should pull

    12345 date name email

    from this text file

    12345 date name email
    12346 date name email
    12347 date name email
    12348 date name email
    12349 date name email
    12350 date name email

    and print on a new page.

    Thanks in advance!
    Jerry

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jerryran View Post
    Hi,

    Using a URL, how can I parse one line of variables from a multi-line tab-delimited text file?

    For instance:

    http://www.domain.com/cgi-bin/read.pl?order=12345

    should pull

    12345 date name email

    from this text file

    12345 date name email
    12346 date name email
    12347 date name email
    12348 date name email
    12349 date name email
    12350 date name email

    and print on a new page.

    Thanks in advance!
    Jerry
    the simplest way is by writing your code in read.pl, in fact is the single one i know, maybe somebody else could infirm this.

    best regards

  • #3
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, I thought that was implied.

    to be clear, I'm looking for help with the code that will perform this task.

  • #4
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jerryran View Post
    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;
    hmm, this is something else,
    You don't know how to get the 'order' and it's value from url?
    use the CGI module:
    Code:
    use CGI;
    my $cg = CGI->new;
    print $cg->param('order');
    let me know if this is what you ask.

    see perldoc or man page for CGI, and post 'clear' question when you need,

    Edit: i forget, you need to push the lines into a array first and sort after, before display

    Edit: use please [ code] and [ /code] tags to wrap code, thank you,

    best regards
    Last edited by oesxyl; 03-17-2011 at 09:58 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •