Hi Monks, I want to merge a couple of files and sort the output. I have stored the files to be merged in separate lists and I want to add a number to each element of each list with map. The numbers are to be used later by 'sort' to put the lines in a particular order. Perhaps an example...
@newsent = map {if ($i == 0){$i + 1} elsif ($i % 10 == 0){$i += 10 +}; $i," ",$_} @testsent; @newfillers = map {$j % 2 == 0 && $j % 10 != 0;$j," ", $_} @fillers +; @newfoils = map {unless ($k == 1){$k % 2 != 0 && $k % 5 != 0}; $k, +" ",$_} @foils; @newwords = map {$l % 5 == 0; $l," ",$_} @words;
Unfortunately, no number was put in the new list. I thought that I had to initialize a value for $i to $l, but when I do that the part of map that says which numbers should be added seems to be ignored. Here's my question(s): Do I have to initialize a value, and if so, where? Is map the best solution to my problem. Should I use a hash, and if so, why and how? best, Ruben van de Vijver

In reply to merging files using map by epistrophy

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.