Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Calculating/adding byte counts of array elements

by kcott (Archbishop)
on Aug 07, 2013 at 07:55 UTC ( [id://1048282]=note: print w/replies, xml ) Need Help??


in reply to Calculating/adding byte counts of array elements

G'day Dr Manhattan,

I see ++choroba has provided the solution to your posted problem.

Here's another way to go about this using Scalar::Util's dualvar() function:

$ perl -Mstrict -Mwarnings -e ' use Scalar::Util qw{dualvar}; my @string_array = ( "Hello, my name is John", "How are you?", "blah (blah)", ); my @count_array; my $last_count = 0; for (@string_array) { push @count_array => dualvar $last_count, $_; $last_count += length; } printf "%08d %s\n" => $_, $_ for @count_array; ' 00000000 Hello, my name is John 00000022 How are you? 00000034 blah (blah)

-- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-19 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found