Solved

I need to get some code to concat string

Posted on 2008-10-02
3
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:EmadGirgis
ID: 22631187
I guess I found the answer.

It is


Print @param

Am I right
0
 
LVL 84

Expert Comment

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



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
ID: 22631606
> Print @param;
should be
print @param;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

734 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