CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
adding characters

 



muluwork
Novice

Apr 25, 2011, 6:28 AM

Post #1 of 3 (382 views)
adding characters Can't Post

I tried to write a script (see below) to add dots at the end of each line below @ and + and the number of characters in the modified lines shall be 51 for the line below @ and 50 for the line below + . But the script doesn't give me the intended result. Would you please help me?
#!/usr/bin/perl -w
use strict;
use warnings;
my $file;
my $line;
open IN, shift;
INPUT:
while ($file = <IN>) {
chomp( my $line = <IN>);
if ($line = ((!/^@/)||(!/^+/))
{
s/$/................................................../;
$line=substr($line,0,51);
}
{
print $file, $line, "\n";
}
}
close IN;
END;

Example

input

@1279_47_201
T23002212222100023000100003231123220122000222022120
+
%7,-'%=#$##;%#,$;+#)#:'*,#2##$#(%#*5$#&%$,$,##&#,,
@1279_47_358
T22313210002
+
=>><:<676<;
@1279_47_489
T31122223233231023303010303231120122011122222020120
+
&&416.&.4++&53'4+24%6),5'*)59&.)+7&-(4*)+''8%&*%,&
@1279_47_526
T22332201333332112320001111223101223220211112122110
+
)&1)'1#'*6%9#&0128%#$*/-/)(0#$#'(&&)3$&&%'*)%%-)$'


Output

@1279_47_201
T230022122221000230001000032311232201220002220.....
+
%7,-'%=#$##;%#,$;+#)#:'*,#2##$#(%#*5$#&%$,$,#.....
@1279_47_358
T22313210002.......................................
+
=>><:<676<;.......................................
@1279_47_489
T31122223233231023303010303231120122011122222020120
+
&&416.&.4++&53'4+24%6),5'*)59&.)+7&-(4*)+''8%&*%,&
@1279_47_526
T223322013333321123200011112231....................
+
)&1)'1#'*6%9#&0128%#$*/-/)(0#$....................


miller
User

Apr 25, 2011, 9:10 AM

Post #2 of 3 (376 views)
Re: [muluwork] adding characters [In reply to] Can't Post

The logic portion of the script. You'll have to add the file processing:


Code
while (<DATA>) { 
print;
if (/^[@+]/) {
$_ = <DATA>;
chomp;
$_ .= '.' x (50 - length $_) if length $_ < 50;
print "$_\n";
}
}

__DATA__
@1279_47_201
T23002212222100023000100003231123220122000222022120
+
%7,-'%=#$##;%#,$;+#)#:'*,#2##$#(%#*5$#&%$,$,##&#,,
@1279_47_358
T22313210002
+
=>><:<676<;
@1279_47_489
T31122223233231023303010303231120122011122222020120
+
&&416.&.4++&53'4+24%6),5'*)59&.)+7&-(4*)+''8%&*%,&
@1279_47_526
T22332201333332112320001111223101223220211112122110
+
)&1)'1#'*6%9#&0128%#$*/-/)(0#$#'(&&)3$&&%'*)%%-)$'



muluwork
Novice

Apr 28, 2011, 12:33 AM

Post #3 of 3 (350 views)
Re: [miller] adding characters [In reply to] Can't Post

Thanks Miller

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives