# “Now get Cost Data from a Database!”

- ## Original Code

##

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

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

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

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

## . . .

##

- ## New Code

## $costs = $cost_db->prepare('SELECT prod,cost FROM costs');

## $costs->execute;

## while ( ($prod, $cost) = $costs->fetchrow_array ) {

## . . .

- ##

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

Notes:

Here we have changed just 4 lines to fetch the costs from the database.