Basic idea:
- read in two-line chunks (read one line, then another)
- Join the lines.
- 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" |