On 2/6/02 4:11 AM, Terje Bremnes <[EMAIL PROTECTED]> wrote: > Hi,
Hey Terje, > I am a beginner in writing Perl-cgi scripts, and hope you can help me > with the following problem. I have been writing a script that uses > the Unix "grep" function to search for a word posted to the script from > a web form, and return the search results to a web page. > > The script works well, but I am not satisfied with the layout of the > returned website. When typing the grep command in a Unix terminal I > get the results nicely lined up under eachother, i.e. one file per > line, like this : > > Testfile1 > Testfile2 > .... > > However, when printing to the web page, the resulting files are printed > next to eachother, only separated by a blank space, like this: > > Testfile1 Testfile2 ... > > > The essence of the code is as follows : > >> $testvalue=$value[0]; >> $word = `grep -inlsh $testvalue *`; >> print "The string $testvalue was found in these files : <p>$word</p>"; > > > Thus, what I need is a procedure that splitsthe parameter word, which stores > the result as a vector of filenames, into separate values. I image I must > use some kind of for-loop to do this, but exactly how I do not know... > > Any help would be greatly appreciated! > > Sincerely, > Ted This is an HTML issue, not a Perl issue. Remember that HTML displays all blocks of whitespace, regardless of how large or what kind, in the same way. To get this to display correctly you could do something like this: $word = `grep -inlsh $testvalue *`; $word =~ s/\n/<br>\n/g; print "The string $testvalue was found in these files : <p>$word</p>"; The second line simply replaces all occurrences of "\n" with "<br>\n". Another way to do it would be to split up $word into an array (as you suggested) and print it out with a "<br>" at the end of each line. It's bulkier, but worth it if you need all your values in an array: $word = `grep -inlsh $testvalue *`; @lines = split(/\n/,$word); print "The string $testvalue was found in these files : <p>\n"; foreach $line (@lines){ print "$line<br>\n"; } print "</p>\n"; I'll also note that either way, you end up putting an <br> right before your </p>, which is unnecessary, but not worth the trouble to prevent, in my opinion. Hope that helps, -- Michael Kelly [EMAIL PROTECTED] http://www.jedimike.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]