[plug] Re: Perl Question.
David Buddrige
buddrige at wasp.net.au
Thu Nov 21 15:12:32 WST 2002
levsky at rave.iinet.net.au writes:
> 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?
Didn't know about join. Thanks, that's much easier. 8-)
>> 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.
Thanks. Been using C++ tool long, where passed references can be used like
a normal variable... 8-)
> How's about something like
>
> sub format_docpp_comment
> {
> my ($doc_comment)=@_;
>
> foreach $comment_line (@$doc_comment) {
> blah blah;
> }
>
> print $single_comment_line;
> }
yep. taa. that works perfectly now.
cheers
David.
>
> 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