Hi Perl Monks,

I am a beginner in perl programming. Can you help me to sort out a simple problem in perl script writing? I have used a map function in the middle of a program i.e.

say $_ for map {sprintf (“%d”, length)} split/$motif/, $string;

It works nicely in command prompt in Windows XP and shows the results correctly. But I want the results of this line (e.g. 0 6 7 8 4 etc. ) printed in a .txt or .docx page as output. So, I need to assign the result of this code to a variable like $a or @a for use in print command like print ”$a or @a”;.

I searched for references in Google but those references have not worked in my program. I shall appreciate if any perl monk can help me sort out this problem by assigning a suitable variable to the output of this code to get the result as print ”$a or @a “; in my program.


In reply to Request to sort out a problem in perl program for getting result as print "@a or $a" of a map function code by supriyoch_2008

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.