Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re: sql output header printing question.

Status
Not open for further replies.

qyllr

MIS
Joined
Mar 8, 2001
Messages
131
Location
US
the sql output contains headers for each row returned from a query. sometimes these headers do not appear on the top of the query result-they appear in the middle.

The following is the header print section of the script I wrote:

# PRINT THE FIRST 2 LINE
# OPEN REPORT FOR READING
open (FP,&quot;</usr/home/xxxx/sql.out&quot;) || die (&quot;\oops: can't read\sql.out\&quot; -$!\n\n&quot;);
# PROCESS EACH LINE IN THE FILE
while ($line=<FP>) {
if ($line =~ /NAME.*ADDRESS.*TEL.*DATE/) {
$header1 = $line;
next;
}
# GRAB ANY LINE THAT BEGINS WITH A '-'
if ($line =~ /^ -/) {
$header2 = $line;
}
}
# CLOSE THE FILE HANDLE
close (FP);

# PRINT OUT RESULTS
print OUTPUT_FILE &quot;$header1\n$header2\n&quot;;

The output of this is the following:

NAME ADDRESS TEL DATE
------ ---------- --------------- --------- -----------

question: how can i add EMP# in front of NAME without moving the NAME so that the lines do not become misaligned - is there a way to do this without doing a format?

e.g.

EMP# NAME ADDRESS TEL DATE
------ ---------- --------------- --------- -----------

thanks
 
Sorry, I don't have time to give the syntax. See >perldoc -f sprintf

Hope this helps....


keep the rudder amid ship and beware the odd typo
 
goboating thanks for the recommendation...i used the following regex instead...:

$header1 =~ s/^\s+//;

q.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top