Results 1 to 5 of 5

Thread: Fun parsing problem

  1. Fun parsing problem

    I am trying to have a program, script or code that will do the following for me:

    The code will read a Word doc, look for headings such as "Year of Release: " and then save the text following into a variable. It'll then use the variable to take the document's title and add a page link to the specific year page.

    Probably easier to make an example of it.

    A word doc has a review of a movie in it, say, Beowulf, released in 2007. I would want a script that will read the word doc, scan it for "Year of Release: " and then save the year (2007) that proceeds that as a variable. It would then take the title of the movie as a seperate and a form webpage link such as:

    <a href="../MovieNameVariable-review.html">MovieNameVariable Review</A>
    into
    <a href="../beowulf-review.html">Beowulf Review</A>

    And add that to a specific spot in the page put together for all movies released in 2007. It would use the year variable to know what page to add the review to. I have other fields to parse as well (by reviewer, by genre), but I can adapt the code for each function.

    It seems simple enough but I am code retarded sadly. This is to facilitate cataloging a single review into multiple grouping pages. Thanks guys...
    Quote Originally Posted by Yoshi View Post
    STFU GTFO

  2. Use Perl. Parsing is really easy if you know how to read Word files (I don't).

  3. Code:
    open (INFILE, $worddoc)
    
    while ($line = <INFILE>) {
       chomp $line;
       if ($line =~ /Year of Release:/){
          @release_line = split(/:/,$line);
          $year = @release_line[1];
          $year =~ s/ //;
       }
    }
    That gets you the year in a variable from a plain text file. I'd have to see the format of the input to do more. It reads the input line by line searching for Year of Release, then assuming that is the only thing on the line will split $line into an array at the ':'. I put the year in $year and then delete the white space.

    Sorry for the sloppy code, I'm sure it could be done in way fewer lines. 6 months ago I was the man at this. I need a refresher.

  4. That works! Thanks stormy. So with the year saved, can I then have perl read the variable and write a template piece of code to the appropriate grouping page (i.e. for the specific year)?
    Quote Originally Posted by Yoshi View Post
    STFU GTFO

  5. If it has to do with text Perl can do it. I think you just want to open a file with $year in the title and start writing to that one right? Shouldn't be a problem. Use '>>' to append to the current file, '>' will start over with an empty file.

    Something like:
    Code:
    open (OUTFILE, '>>${year}.txt');
    print OUTFILE "blah blah blah ${movie_title}\n";
    close (OUTFILE);

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Games.com logo