in reply to Re: Count and print in perl
in thread Count and print in perl

my problem is how to split the file and how to print in defined format. I have tried this <$str_len = length($line1); if($str_len > 72){ my @split_line = unpack("(A32)*" , $line1); > But it is not solving my problem.because after 11 count one character is incrementing so not printing aligned format.

Replies are listed 'Best First'.
Re^3: Count and print in perl
by 1nickt (Canon) on Apr 17, 2017 at 11:35 UTC

    ... because after 11 count one character is incrementing so not printing aligned format ...

    See sprintf.

    perl -Mstrict -Mwarnings -E ' my @x = qw/ 123 1234567890 12345678901 /; say sprintf("%-11s length %s", $_, length $_) for @x; '
    Output:
    123 length 3 1234567890 length 10 12345678901 length 11

    Hope this helps!



    The way forward always starts with a minimal test.