The use warnings; Statement in Perl

Adding this statement to the begining of our code will trigger warnings for our code wherever relevant. Adding ‘use warnings Fatal => ‘all’; to our code will promote all warnings to errors and die immediately on the first warning.

#!/usr/bin/perl

use strict;
use warnings;

my %currencies = (

    USD     =>  4.1,
    EURO    =>  4.4,
    GBP     =>  6.7

);

my $currency = 'GBP';

if (not exists $currencies{$currency}) {
    print("$currency doesnot exist");
} else {
    print("$currency exists");
}

Share:

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences