On Thu, 21 Nov 2002, David Buddrige wrote:

> 
> Hi all,
> 
> I am writing a 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 below.
> 
> 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?
> 
> thanks heaps
> 
> David Buddrige.
> 
> sub format_docpp_comment
> {
>      my @doc_comment;
>      my $comment_line;
>      my $single_comment_line;
> 
>      @doc_comment = $_[0]; # give a friendly name to the array

If you are passing an array into the subroutine, this should be
@doc_comment = @_;

If it is a array reference that you are passing, this should be
@doc_comment = @{$_[0]};

> 
> 
>      foreach $comment_line ( @doc_comment )
>      {
>       chomp $comment_line;
>       $single_comment_line = $single_comment_line . $comment_line;
>      }

You can do away with the foreach loop here, this should do
chomp (@doc_comment);
$single_comment_line = join ('', @doc_comment);

perldoc -f chomp
perldoc -f join

> 
>      # At this point we have a single string that contains our entire
>      # doc++ comment.
>      # we can now use simple pattern matching to parse it.
> 
>      # for now output it so we can see what it looks like:
>      print $single_comment_line;
>      print "\n";
> }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to