Gossamer Forum
Home : General : Perl Programming :

Content Length.

Quote Reply
Content Length.
Need to determine "character count" for a couple of input strings.

$string1 = "$form{'string1'}";

$string 2 = .........

$string3 = ...... and So on.

I tried this thing.

@total = ('$string1' , 'string2' , 'string3')

$length += length($_);

print "$length";

But its not working. Any help?
Quote Reply
Re: [zeshan] Content Length. In reply to
Quote:
@total = ('$string1' , 'string2' , 'string3')

$length += length($_);

A few things wrong here...firstly you have prevented your variables being interpolated by single quoting them so say you had:

my $string1 = 'hello';

Then:

@total = ('$string1');

...then printing $total[0] would print $string1 and not "hello" as you probably expected.

Second thing is you are trying to count the length of $_, but what did you think was contained in $_ ?

Anyhow, try this...

Code:
my $total = [$string1, $string2, $string3];
my $length;
$length += length($_) for (@$total);