[plug] Perl Question.

levsky at rave.iinet.net.au levsky at rave.iinet.net.au
Thu Nov 21 15:01:03 WST 2002


On Thu, Nov 21, 2002 at 02:45:24PM +0800, David Buddrige wrote:
> Hi all, 
> 
> I am writing a perl subroutine which is intended to take an array of 
> strings, and concatenate each string in the array into a single [very long] 
> string. 
> 
> The subroutine is listed at the end of this email. 

Firstly, why can't you use join to do this?

> My problem is that for some reason when I print out the variable 
> "$single_comment_line", rather than getting a very long string, I get 
> something like: 
> 
> ARRAY(0x8118e34) 
> 
> printed out instead.  Can anyone see why this is happening? 
> 
> I am calling the subroutine by passing it a reference to an array of 
> strings like this: 
> 
> 	format_docpp_comment( \@doc_comment ); 

It's because you're passing an array reference to the subroutine and then
treating it if it's an array, rather than as a scalar which is what it is.

How's about something like

sub format_docpp_comment 
{
	my ($doc_comment)=@_;

	foreach $comment_line (@$doc_comment) {
		blah blah;
	}

	print $single_comment_line;
}

Cheers

Mark

-- 
Perl is designed to help people learn the bits of programming they need 
right now without forcing them to learn the techniques they aren't ready 
for. But when they are ready for them, Perl tries to be there too. We just 
don't tell the beginners that the speedometer on their golf cart wraps 
around several times.    - Larry Wall





More information about the plug mailing list