RE: How to measure Array or Hash's byte size ?

2003-04-05 Thread Scott R. Godin
Vincent Bufferne wrote: What's about: my @foo = ( '1', '2' ,'3' ); my $size = $#foo + 1; print table size $size\n; Ouput: table size 3 print Table size: , scalar(@foo), \n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: How to measure Array or Hash's byte size ?

2003-04-04 Thread BUFFERNE,VINCENT (HP-France,ex1)
What's about: my @foo = ( '1', '2' ,'3' ); my $size = $#foo + 1; print table size $size\n; Ouput: table size 3 Vincent -Original Message- From: Li Ngok Lam [mailto:[EMAIL PROTECTED] Sent: Thursday, April 03, 2003 5:14 PM To: [EMAIL PROTECTED] Subject: How to measure Array or Hash's

Re: How to measure Array or Hash's byte size ?

2003-04-04 Thread Li Ngok Lam
What's about: my @foo = ( '1', '2' ,'3' ); my $size = $#foo + 1; you can simplify this by : $size = scalar @foo; print table size $size\n; Ouput: table size 3 TIA, but this is not what I want... because each element is assumpted not in same length... ie.. I am not going to get the

Re: How to measure Array or Hash's byte size ?

2003-04-04 Thread Rob Dixon
Li Ngok Lam wrote: What's about: my @foo = ( '1', '2' ,'3' ); my $size = $#foo + 1; you can simplify this by : $size = scalar @foo; You can simplify even this by : $size = @foo :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: How to measure Array or Hash's byte size ?

2003-04-04 Thread Shawn
That's not what he was asking. On Thu, 2003-04-03 at 10:07, BUFFERNE,VINCENT (HP-France,ex1) wrote: What's about: my @foo = ( '1', '2' ,'3' ); my $size = $#foo + 1; print table size $size\n; Ouput: table size 3 Vincent -Original Message- From: Li Ngok Lam [mailto:[EMAIL

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread Rob Dixon
Li Ngok Lam wrote: My method sounds stupid, but still works : my @array = ('123', 'abc', 'def', 1..9); my $len_of_array = 0 ; foreach my $elem(@array) {$len_of_array += length($elem) } print $len_of_array ; # I got '18' my %hash = (1=2, 2=3, 3=4); foreach my $key(keys(%hash)) {

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread Paul Johnson
Rob Dixon said: Li Ngok Lam wrote: My method sounds stupid, but still works : my @array = ('123', 'abc', 'def', 1..9); my $len_of_array = 0 ; foreach my $elem(@array) {$len_of_array += length($elem) } print $len_of_array ; # I got '18' my %hash = (1=2, 2=3, 3=4); foreach my

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread John W. Krahn
Li Ngok Lam wrote: My method sounds stupid, but still works : my @array = ('123', 'abc', 'def', 1..9); my $len_of_array = 0 ; foreach my $elem(@array) {$len_of_array += length($elem) } print $len_of_array ; # I got '18' my %hash = (1=2, 2=3, 3=4); foreach my $key(keys(%hash))

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread Li Ngok Lam
I don't know if it is better or faster, but it is shorter. :-) $ perl -le' my @array = ( 123, abc, def, 1 .. 9 ); my $len_of_array = do { local $; length @array }; print $len_of_array; ' 18 $ perl -le' my %hash = ( 1 = 2, 2 = 3, 3 = 4 ); my $len_of_hash = do { local $; length

Re: How to measure Array or Hash's byte size ?

2003-04-03 Thread R. Joseph Newton
Li Ngok Lam wrote: My method sounds stupid, but still works : my @array = ('123', 'abc', 'def', 1..9); my $len_of_array = 0 ; foreach my $elem(@array) {$len_of_array += length($elem) } print $len_of_array ; # I got '18' my %hash = (1=2, 2=3, 3=4); foreach my $key(keys(%hash)) {