format and newline

C

cmic

Hello.
I have the following snippet :

#!/usr/local/bin/perl
use strict;
use warnings;
my @array=(2, 3, 5, 1, 5);;
my ($a, $b, $c);
format STDOUT =
@>>>>>>>>|@<<<|@<<<<<
$b, $a, $c
..
foreach (@array) {
$a=$_; $b=$a+100;$c=$a*2;
write ;
print "VAlue " . $a . "\n";
}

.... which prints :
102|2 |4
VAlue 2
103|3 |6
VAlue 3

but and I want my script to print this instead :
102|2 |4 VAlue 2
103|3 |6 VAlue 3

How to do this ? Or must I use sprintf instead ?
TYA
 
S

Sébastien Cottalorda

cmic a écrit :
Hello.
I have the following snippet :

#!/usr/local/bin/perl
use strict;
use warnings;
my @array=(2, 3, 5, 1, 5);;
my ($a, $b, $c);
format STDOUT =
@>>>>>>>>|@<<<|@<<<<<
$b, $a, $c
.
foreach (@array) {
$a=$_; $b=$a+100;$c=$a*2;
write ;
print "VAlue " . $a . "\n";
}

... which prints :
102|2 |4
VAlue 2
103|3 |6
VAlue 3

but and I want my script to print this instead :
102|2 |4 VAlue 2
103|3 |6 VAlue 3

How to do this ? Or must I use sprintf instead ?
TYA

Hi,

You can use sprintf on $c value (be careful on the length) or create
another column like this

#!/usr/local/bin/perl
use strict;
use warnings;
my @array=(2, 3, 5, 1, 5);;
my ($a, $b, $c);
format STDOUT =
@>>>>>>>>|@<<<|@<<<<< @<<<<<<<<<
$b, $a, $c, "VAlue $a"
..
foreach (@array) {
$a=$_; $b=$a+100;$c=$a*2;
write ;
}

Hope this helps.

Sebastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top