For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > February 2005 > Addendum: Content_Length.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Addendum: Content_Length.
Sara

2005-02-03, 3:55 pm

Why the length is not coming out? Any ideas?

########################################
#########

my @aho = ("fgfgfgf", "fgfgfgfgf", "fgfgfgfg");

my $length += length($_) for @aho;

print "Content-type: text/plain\n\n";
print "$length";

########################################
#########

Thanks,
Sara.




Bob Showalter

2005-02-03, 3:55 pm

Sara wrote:
> Why the length is not coming out? Any ideas?
>
> ########################################
#########
>
> my @aho = ("fgfgfgf", "fgfgfgfgf", "fgfgfgfg");
>
> my $length += length($_) for @aho;


A perl "gotcha". The 'for' modifier creates a loop, and the 'my' is scoped
to the body of that loop (I think; I may not be exactly correct here). You
need to write it like this:

my $length;
$length += length($_) for @aho;
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com