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

I have a flat file data.txt christine|colorado10|colorado-pc|10/09/08|XP tom|california12|go49ers-pc|09/12/08|vista how do i create view.pl so i can see a table in html with 1. field 1 is name like christine , tom 2. file 2 is a link http://colorado:5810 , http://california:5812 3. field 3 pc name 4. field 4 is OS Thanks

Replies are listed 'Best First'.
Re: Separate word and number
by Erez (Priest) on Jan 17, 2008 at 08:42 UTC

    Here are some ideas to get you going: read the file into a while loop and split it into an array using the '|' as a delimiter.
    If the data is consistent (i.e. the name is always the first, the date is always 4th), you can call the array items by index ($array[0] is the name, $array[3] is the date, etc.). If not, some regex validation may be in order.

    Turning it into an HTML can be done by many ways, and the best one depends on what you want to do with the info. As mentioned, more information will help.

    Software speaks in tongues of man; I debug, therefore I code.
    Stop saying 'script'. Stop saying 'line-noise'.

Re: Separate word and number
by ady (Deacon) on Jan 17, 2008 at 06:56 UTC
    Welcome Britney!
    Before we proceed: what have you tried? -- show us your program, that's not working and for which you need help.
    Consider Show your work
    Best Regards
    Allan Dystrup
more like, how2seperate line and render as html Re: Separate word and number
by rgiskard (Hermit) on Jan 17, 2008 at 12:47 UTC
    With some hash data to describe what should link to where, you could always do something like this to each line of the file and ultimately render the page (as follows):
    my @links = ('colorado-pc','http://colorado:5810', 'pm', 'http://www.perlmonks.org'); my %linkHash = @links; my @linkKeys = keys %linkHash; my @lines = ('christine|colorado10|colorado-pc|10/09/08|XP tom|califor +nia12|go49ers-pc|09/12/08|vista', 'pm'); my $htmlPage = '<html><table>'; foreach my $line (@lines) { # substitute links foreach my $link (@linkKeys) { my $tmpLink = aWrap($linkHash{$link},$link); $line =~ s/$link/$tmpLink)/g; } #split the | into table delimeters $line =~ s/\|/<\\td><td>/g; # tack on table html code $line = '<tr><td>'.$line.'</td></tr>'; #add 2 page $htmlPage .= $line; } $htmlPage .= '</table></html>'; print $htmlPage."\n"; sub aWrap { my $ref = shift; my $title = shift; return "<a href='$ref'> $title </a>" }
    It's a bit wordy, but you get the idea.
    Update This isn't the best way, but to do that I'd have to know more about what you've already tried/what libs are you using. Till then, this is A way to do things.