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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    72
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Scan a .txt file

    Hi

    I have a .txt file with contains fields separated by ;
    as below

    name; city; course; address; etc


    I want to built a CGI script based on the algorithm below
    to look if have a student is enrolled in a course

    ************************************************
    scan the .txt file from top to bottom

    If line contains $student_name and $student_course

    print '<p align="left"><font face="Arial">Found: '$student_name '</big></font></p>'."\n" ;

    continue the scan

    If line contains $my_name and $my_city

    print '<p align="left"><font face="Arial">Found: '$student_name '</big></font></p>'."\n" ;


    *****************************************************

    I came from visual foxpro with little experience in web languages


    Moises

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,912
    Thanks
    2
    Thanked 164 Times in 159 Posts
    What have you tried?

    What part of the task do you not know how to do or is giving you trouble?

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    72
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    What have you tried?

    What part of the task do you not know how to do or is giving you trouble?
    Hi

    There are two steps

    1) I would like to import the txt file into an array where each field of the
    txt (separated by semicolon) will be a column of the arry, and each line of the .txt
    will be a line of the array

    2) I would like to scan the array looking for situations where two columns
    of the array match the variables I am lookig for

    For example: If colunm1 = $city and column2 = $student

    write: Studend $student found





    Moises

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,912
    Thanks
    2
    Thanked 164 Times in 159 Posts
    That doesn't answer my question and this looks like your homework assignment.

    1) You need an Array-of-Arrays. See:
    perldoc perldsc
    http://perldoc.perl.org/perldsc.html#ARRAYS-OF-ARRAYS

    perldoc -f open
    http://perldoc.perl.org/functions/open.html

    2) You need to loop over the array and test the desired fields.


  •  

    Posting Permissions

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