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
> --
> cmic
>
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
|