Basic idea:

  1. read in two-line chunks (read one line, then another)
  2. Join the lines.
  3. Strip out the leading zero, and any excess whitespace (including newlines).

open FILE, "file.txt" or die "Can't open file.txt:$!\n"; while(my $firstline = <FILE>) { $secondline = <FILE> or die "Ran out of lines!\n"; # how to join the lines is left as an exercise for the # reader: hint ... Dot knows much. }

For the second part, you can use a regular expression. Here's a hint: /^a/ matches an a at the beginning of a string. Here's another hint: \s{7,} matches seven whitespace (space, tab, newline) characters. The general syntax for a search-and-replace (substitution) pattern match is $string =~ s/tick/arthur/;, and the /g modifier on the end of a regular expression tells the system to perform each match it finds (instead of just the first).

The rest is left as an exercise for the reader. Study materials: perlre, perlretut.

HTH

Update theorbtwo pointed out I hadn't closed my ordered list tag.

If not P, what? Q maybe?
"Sidney Morgenbesser"


In reply to Re: How can I remove 0 from first line and empty space from the start of the following line and join them by arturo
in thread How can I remove 0 from first line and empty space from the start of the following line and join them 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.