Help for this page

Select Code to Download


  1. or download this
    print("$line_num $rest\n");
    printf("%03d %s\n", $line_num, $rest);
                               12345678901
    
  2. or download this
    $ perl -e'my $i=0; while (<>) { print ++$i, " $_" }' file
    1 foo
    2 bar
    3 baz
    4 qux
    
  3. or download this
                    1 234
    $ perl -e'my $i="000"; while (<>) { print ++$i, " $_" }' file
    ...
    002 bar
    003 baz
    004 qux
    
  4. or download this
    $ perl -e'while (<>) { print "$. $_" }' file
    1 foo
    2 bar
    3 baz
    4 qux
    
  5. or download this
    $ perl -e'while (<>) { printf "%03d %s", $.,  $_ }' file
    001 foo
    002 bar
    003 baz
    004 qux