in reply to numbering lines problem
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: numbering lines problem
by WisDomSeeKer34 (Sexton) on Nov 19, 2014 at 14:30 UTC |