Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that takes a text file created in Access and prints it out.

Example of my text file:
97 Ford Mustang|Red|46000|9990.00 99 Chevy Blazer|Black|19000|17000.00
I have a script that creates a list like:

97 Ford Mustang
99 Chevy Blazer

Now comes the tricky part. I want each item in the list above to be a link to another page that dispalays the specifics for that car. So when you click on 97 Ford Mustang another page is created:

Make & Model: 97 Ford Mustang
Color: Red
Mileage:46000
List Price: $9990.00


Kinda like e-bay where you have a list of titles and when you click on the title all the specifics come up. Any suggestions on how to do it from a single file? or perhaps where I would find a script to do this?

Thanks
Scott

Edit by tye, title, unhide line breaks

Replies are listed 'Best First'.
Re: Perl question
by Anonymous Monk on Mar 13, 2000 at 11:46 UTC
    Note: the backend to this site seems to interpret left and right square brackets... so anywhere you see a number after @temp_data, put brackets around it.

    I'm a bit unclear about the structure of the original text file.

    Are the entries separated by a carriage return or just a space?

    The above script looks fine. I think the line that clears @temp_data is unnecessary. I'm also confused about what the print line does b/c it contains html that my web browser is interpretting ... perhaps the poster should have previewed it first. (btw, single quotes are necesary around it or perl will get confused.) It also might be nicer to save each link as, for example, 97FordMustang.html instead of 0.html do:

    $filename = (join '', (split @temp_dataŤ0])) . '.html';
    This script also just makes the links, not the html files themselves. to fix this, at the top of the script, add:
    open (INDEX, ">list.html");
    change the print ... to print INDEX ...

    then on the inside, after the print line (after the $filename mentioned above) do:

    open (CAR, ">$filename"); print CAR "Make and Model: @temp_data[0]\n"; print CAR "Color: @temp_data[1]\n"; etc.
    you don't need to close either of these filehandles. perl is smart enough.

    I don't have an account here (yet) but feel free to mail me at psack@tivoli.ihatespam.com.

    Edit by tye, formatting

RE: Perl question
by Anonymous Monk on Mar 13, 2000 at 09:53 UTC
    I am no expert on perl like alot of these guys, but heres what I would do. make the access file easier to parse. I would have the entries something like this:
    0001:97 Ford Mustang:Red:46000:9990.00 0002:99 Chevy Blazer:Black:19000:17000.00
    where this is an actual newline character between each entry. also, not the first field, which you did not have. This is just a number, but basically it needs to be unique for each car, and then the car will have the html file called 0001.html for example that shows its info. I am not sure if you didnt want to have to have a seperate webpage for each car already made or whatever, but this is what I can think of. Then do something like this:
    @car_data = `cat data.file`; foreach (@car_data) { @temp_data = ""; # clear this array @temp_data = split(/:/,$_); # split the current line by semi-colin + into the array @temp_data print "<a href="http://yoursite/$car_data[0].html">$car_data[1]</a +>\n"; # prints the link }
    so you'd have, for these two examples:
    97 Ford Mustang
    99 Chevy Blazer
    
    thats all I got. I am sure this advice is subpar, and the experts here will quickly correct me.

    Edit by tye, formatting

Re: making pages?
by PipTigger (Hermit) on Mar 14, 2000 at 16:50 UTC
    Maybe I'm weird here but it seems that such simple pages (ie. with just a vehicle, small info, small pic, etc.) would be good to make dynamically... instead of OPENing CAR and PRINTing to it as described above, make a separate cgi script or just a separate section of your original which tests the name/value of your submit button (which called the script in the first place)... this way, the default script could list all vehicles available and print them as a table or whatever (make sure to include all relevant info in the line item for each)... then on the list page, instead of just a simple link, each would have it's own submit button or graphic something like:
    <form action="/cgi-bin/$NameOfYourScript.cgi"> <input type="hidden" name="WhichOne" value="97FordMustang"> <table><tr><td>YEAR<td>MAKE<td>MODEL<td>PRICE<td>GRAPHIC<td>ETC.<td>DE +TAILS <tr><td>97<td>Ford<td>Mustang<td>$17000<td>IMG tag goes here <td>etc...<td><input type="submit" name="Detailed" value="Show Det +ails"> </table></form>
    I don't know of a script to do similar stuff automatically for you... I know what I've described is probably more work but then you won't have to worry about managing a million html files all over the place (and designing some filing scheme for them etc.) ... and you can make simple changes to the table layout, colors, graphics, etc. and all of them will immediately propagate to every page viewed off a submission from there on without having to create a ton of tiny pages again either. If I haven't described this clearly enough, I apologize. Just ask and I'll try to clarify if someone else doesn't beat me to it. TTFN & Shalom.

    -PipTigger