# Writing the New Report

## open COST, "<cost.txt" or die "open cost.txt: $!";

## while ($line = <COST>) {

## next unless $line =~ m/^\d/;

##

## ($prod, $cost) = unpack 'A4 @20 A7', $line;

##

## $cost *= $prod_margin{$prod} || 1.10;

## $note = $prod_notes{$prod} || 'n/a';

##

## write; # using format with $prod, $cost and $note

## }

Previous slide | Next slide | Back to first slide | View graphic version

Notes:

Here we read each line from the costs text file,

skip lines that don't start with digits,

extract the product and cost,

apply the margin (or a default),

apply the note (or a default),

and write the output.

Again: very few lines of code and just about every line directly related to the task.