Scalar Data

The chop and chomp functions

Let us now try get the values for the protocol.pl program from the user.

Test the following (get_volume1.pl):

#!/usr/bin/perl

print "please enter final volume (ml) ";
$final_vol = <STDIN>;

print "Final volume is $final_vol ml\n";
                                #to check if we get it right
The result
Final volume is 6
 ml
Contains an unwanted newline, which originated from the Return key pressed by the user when he/she entered the final volume number.

Correction (get_volume2.pl):

#!/usr/bin/perl

print "please enter final volume (ml) ";
$final_vol = <STDIN>;
chomp ($final_vol);            # get rid of the newline

print "Final volume is $final_vol ml\n";

which nicely results in:
Final volume is 6 ml

Table of Contents.
Next | Next.