Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > format and newline

Reply
Thread Tools

format and newline

 
 
cmic
Guest
Posts: n/a
 
      08-11-2006
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

 
Reply With Quote
 
 
 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      08-11-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert newline before date in yyyy-mm-dd format Kevin Walzer Perl Misc 2 12-02-2012 03:29 AM
Newline with HTMLEncode in Div and Label versus ASP .Net 6 11-28-2007 08:51 AM
Labels and NewLine Samuel Shulman ASP .Net 3 11-27-2006 08:58 PM
string.split and Environment.NewLine question. =?Utf-8?B?QXNoYQ==?= ASP .Net 1 12-30-2004 09:33 AM
fgets and newline Mike Mimic C++ 4 05-15-2004 06:19 AM



Advertisments