develooper Front page | perl.beginners | Postings from October 2009

Building a fmt line for printf with a carriage return

Thread Next
From:
Wagner, David --- Senior Programmer Analyst --- CFS
Date:
October 23, 2009 04:46
Subject:
Building a fmt line for printf with a carriage return
Message ID:
95901ECAC1DC3C41BFD61B4A5875932401AB62ED@phexsrv07.fxfeast.freight.fedex.com
	I thought I had done this before, but I guess not. I build a formt line for printf like:
		q[%-3s%-4s%5s%6s];
	But I want to insert a carriage return after say %-4s( I have a nubmer of fields and depending on the size, it is not a constant after column 2, but could be column 3 or 23.
	
	I have tried:
		q[%-3s%-4s] . qq[\\n] . q[%5s%6s]
	or
		q[%-3s%-4s\n%5s%6s]

	But no matter what I do, it does not generate the carriage return. Shows up in the line. I know I am missing some very basic point, but has escaped me.

	Here is the sample script I was playing with:
#!/usr/bin/perl

use strict;
use warnings;

my $MyLine1 = q[%2d  %5s  %6s];
my $MyLine2 = q[%2d  %5s \n%6s];

printf "${MyLine1}\n",
                2,
                q[abc],
                q[def];
                
printf "$MyLine2\n",
                2,
                q[abc],
                q[def];
                
         Thanks.
 
Wags ;)
David R. Wagner
Senior Programmer Analyst
FedEx Freight Systems
1.719.484.2097 Tel
1.719.484.2419 Fax
1.408.623.5963 Cell
http://fedex.com/us 



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About