Solved

I need to get some code to concat string

Posted on 2008-10-02
3
547 Views
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!
0
Comment
Question by:EmadGirgis
  • 2
3 Comments
 

Author Comment

by:EmadGirgis
Comment Utility
I guess I found the answer.

It is


Print @param

Am I right
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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".



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


0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
> Print @param;
should be
print @param;
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

772 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

9 Experts available now in Live!

Get 1:1 Help Now