Extracting values from a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nife
    New Member
    • May 2007
    • 2

    Extracting values from a text file

    (perl)

    hi guys,

    ive searched many places for a solution and cant find one.

    problem:

    i need to extract information about an image that is stored in a text file.

    this information and the image is displayed on a html paged created by the same program.

    i managed to create brokencar.html, and insert the image in.

    this is just a small portion of my program

    perl:

    open HTML2, ">c:/cygwin/home/nife/$imageName.html ";
    print HTML2 "<head><title>$ imageName.html</title></head>";
    print HTML2 "<tr><td><cente r><img src='$imagesPat h$images'></center></td></tr>";
    close HTML2;


    brokencar.txt:

    Dimensions=> 800x600
    Title=> Broken Car
    Thu Nov 20 21:50:00 WST 2007=> "How shall I ever get home!


    how do i grab "800x600", "Broken Car".
    and display the comments, which may be multiple.

    edit: i believe that the use of match & split maybe necessary.

    please advice. time is of the essence.


    thanks & cheers
  • nife
    New Member
    • May 2007
    • 2

    #2
    no worries guys,

    i think ive got it.

    [CODE=perl]
    open (INFO, "$captionsPath$ imageName.txt") or die "SCREWED!!! ";

    while ($thisLine = <INFO>) {
    if ($thisLine =~ /Dimensions=>/){
    ($garbage,$picS ize) = split(/>/,$thisLine);
    ($width,$height ) = split(/x/,$picSize);

    } elsif ($thisLine =~ /Title=>/){
    ($garbage,$titl e) = split(/>/,$thisLine);
    print HTML2 "<body><center> <H1>$title</H1>";

    } else{
    print HTML2 "$thisLine\ n";
    }
    }
    [/CODE]

    needs some tweaking though, please excuse the "messiness"
    Last edited by miller; May 23 '07, 04:37 PM. Reason: Code Tag and ReFormatting

    Comment

    Working...