Here is a self-contained version. As pan64 noted, you need to get your lines of input from somewhere (this is why $_ is uninitialized). You should just be able to use while (<>) { to read in from your python.txt file.
use warnings; use strict; my $chap; my $sect; while (<DATA>) { if (/^(\d+)/) { $chap = $1; $sect = 0; } else { $sect++; s/^/$chap.$sect /; } print; } __DATA__ 1. Operators Performing simple arithmetic Operating on bitwise values Comparing values Operating on Boolean values Operating on parts of a container with the slice operator Understanding operator precedence 2. Regular Expressions Using the re module Searching with regular expressions
See also: perlintro
In reply to Re: numbering lines problem
by toolic
in thread numbering lines problem
by WisDomSeeKer34
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |