Consider the following code:
sub somefunction { while (expression) { . . $concatstring = &concat ($string1, $string2, $string3); print “$concatstring\n”; } } sub concat { }
I wish to write a function “concat” such that the variable $concatstring will contain a concatenation of the three string variables listed. The function needs to be called from within various functions, and the name $concatstring may not be the same each time. Each of the string variables will require either one or two \t characters adding to it before concatenation, depending on the length of the string. This code is to be executed within the concat subroutine. I wish to achieve an output that looks something like the following:
longstring longstring X X X longstring X longstring longstring
My problem comes because I do not know how to return the finished string from the concat function. I have no problem with the basic logic of appending \t to a string. Any help would be greatly appreciated.

edited: Sun Jan 19 00:35:04 2003 by jeffa - title change (was: Help with subroutines)


In reply to Concatenating strings with tabs between and returning the result by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.