#!/usr/bin/perl -w use strict; use Text::Wrap; use CGI qw(:standard); use DBI(); CGI::ReadParse(); $Text::Wrap::columns = 58; my $dbh = DBI->connect("DBI:mysql:database=somedb;host=xyz.net", "username", "password", {'RaiseError' => 1}); my $text_id = param('iid'); my $textfinal; my $retrieve = $dbh->prepare("SELECT text FROM texts where id=$text_id"); $retrieve->execute(); while (my $ref = $retrieve->fetchrow_hashref()) { $textfinal = $ref->{'text'}; } $retrieve->finish(); # Disconnect from the database. $dbh->disconnect(); my $initial_tab = "\t"; # Tab before first line my $subsequent_tab = ""; # All other lines flush left my @text = split(/\n/, $textfinal); my $newtext = fill($initial_tab, $subsequent_tab, @text); my @newtext = split(/\n/, $newtext); foreach my $gettext(@newtext) { print "$gettext\n"; }