May 26, 2005 #1 rotis23 Programmer Aug 29, 2002 121 GB Hi All, How do I find the size (in bytes) of a scalar? Specifically, I want to find the size of a string (including control chars etc) in memory. Thanks, rotis23
Hi All, How do I find the size (in bytes) of a scalar? Specifically, I want to find the size of a string (including control chars etc) in memory. Thanks, rotis23
May 26, 2005 #2 stevexff Programmer Mar 4, 2004 2,110 GB Code: length($myscalar); Note this gives the length in characters, not bytes. But it should include the control characters, if any. Upvote 0 Downvote
Code: length($myscalar); Note this gives the length in characters, not bytes. But it should include the control characters, if any.
May 26, 2005 Thread starter #3 rotis23 Programmer Aug 29, 2002 121 GB Thansk stevexff. What if I had some binary or object data? How could I determine the size (in bytes) used in memory? Upvote 0 Downvote
Thansk stevexff. What if I had some binary or object data? How could I determine the size (in bytes) used in memory?
May 26, 2005 #4 ishnid Programmer Aug 29, 2003 1,422 IE This maybe? Code: require bytes; print bytes::length( $myscalar ); Upvote 0 Downvote
May 26, 2005 Thread starter #5 rotis23 Programmer Aug 29, 2002 121 GB Thanks ishnid. That only works with scalars. Need to be able to size arrays (I guess I could cycle through) and other non-scalar entities. Upvote 0 Downvote
Thanks ishnid. That only works with scalars. Need to be able to size arrays (I guess I could cycle through) and other non-scalar entities.
May 26, 2005 #6 KevinADC Technical User Jan 21, 2005 5,070 US yes you can loop through: Code: my @file = qw(one two three four five six); { use bytes; my $bytes = 0; for (@file) { $bytes += (length $_); } print "$bytes"; } Upvote 0 Downvote
yes you can loop through: Code: my @file = qw(one two three four five six); { use bytes; my $bytes = 0; for (@file) { $bytes += (length $_); } print "$bytes"; }
May 27, 2005 #7 mlibeson Programmer Mar 6, 2002 311 US Another way instead of looping: Code: require bytes; print bytes::length( join("",@myscalar) ); Michael Libeson Upvote 0 Downvote
Another way instead of looping: Code: require bytes; print bytes::length( join("",@myscalar) ); Michael Libeson