|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
any one know how to work out the size of a variable in KBs ?
|
|
#2
|
||||
|
||||
|
Hi!
The (perl builtin) length function returns you the length of a string $somestring in bytes . my $somestring = 'Hi there'; my $num_bytes = length($somestring); my $num_kbytes = $num_bytes / 1000; Greetings Atrus. P.S.: If you want to know the size of an entire array or hash, you'd have to loop over it, adding up the values of each element.. ![]() |
|
#3
|
|||
|
|||
|
just a small rewrite of above code:
my $somestring = 'Hi there'; my $num_bytes = length($somestring); my $num_kbytes = $num_bytes / 1024; if($num_kbytes > 1){int($num_kbytes);} my $num_mbytes = $num_kbytes / 1024; if($num_mbytes > 1){int($num_mbytes,2)} this would count even megabytes like this: 12.34 mbs I was getting bored so sorry if you find this funny ![]() |
|
#4
|
||||
|
||||
|
Hi!
Of course we don't find that funny I also apologize for falling for the 1000, 1024 thing without thinking. Thanks for the wake up call ![]() Greetings Atrus. |
|
#5
|
|||
|
|||
|
hey no problem, I'm glad I came here... I was looking for a decent perl forum since some time ago my ISP canceled comp.lang.perl newsgroup
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Calculating the size in KBs of a string or variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|