Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Count and print in perl

by Corion (Patriarch)
on Apr 17, 2017 at 09:53 UTC ( [id://1188114]=note: print w/replies, xml ) Need Help??


in reply to Count and print in perl

Maybe you can show us what code you have already written and where you are stuck?

It's hard to give good advice when we don't know where you are actually encountering problems.

Is your problem in reading the file?

Is your problem in splitting up the parts of the file?

Is your problem in printing out the parts of the file?

Replies are listed 'Best First'.
Re^2: Count and print in perl
by kanikas16 (Initiate) on Apr 17, 2017 at 11:25 UTC
    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.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188114]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-23 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found