I need to get some code to concat string

Posted on 2008-10-02
Last Modified: 2012-05-05
      my $message;
      for ($i = 0 ; $i  <= $#param ; $i++ )
            print $param[$i], "\n";
            $message = join ( $message, $param[$i]);
print $message, "\n";

I am novice in perl. Here is my problem. the print line prints every part of the array
$message prints the last string in the array!

Why! How to fix it! please. I want solution before I get to work tomorrow!
Question by:EmadGirgis
  • 2

Author Comment

ID: 22631187
I guess I found the answer.

It is

Print @param

Am I right
LVL 84

Expert Comment

ID: 22631599
perldoc -f join
       join EXPR,LIST
               Joins the separate strings of LIST into a single string with
               fields separated by the value of EXPR, and returns that new
               string.  Example:

                   $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);

               Beware that unlike "split", "join" doesn't take a pattern as
               its first argument.  Compare "split".

 $message = join ( "",$message, $param[$i]);
might do what you want, although
 $message = $message . $param[$i];
 $message .= $param[$i];
would be simpler
  $message = join ( "",@param );
 $message = join ( "\n",@param );
 print $message;
will join all the elements of @param

LVL 84

Accepted Solution

ozo earned 500 total points
ID: 22631606
> Print @param;
should be
print @param;

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now