in reply to undefined subroutine

YAML::LoadFile is exportable, but you didn't export it.

use YAML qw(LoadFile);

or fully qualify the call:

my $config = YAML::LoadFile($fh);

Replies are listed 'Best First'.
Re^2: undefined subroutine
by molv (Initiate) on Apr 07, 2016 at 13:21 UTC

    Thanks for replying with assistance. I've attempted both of these changes and am still receiving the same error. I must be doing something wrong, could you explain further if you don't mind?

      Sure. I don't know what you've done to your script, but here's one which runs to completion and gives no such error message.

      #!/usr/bin/env perl use strict; use warnings; use YAML qw/LoadFile/; open my $fh, '<', '/dev/null'; my $config = LoadFile ($fh);

      Examine this code and compare it to your code. Start altering this code one line at a time to make it ever closer to your code, running it after each addition. If you hit a problem you will then know precisely which change caused the problem.

      This code works fine for me.

      use strict; use warnings; use YAML qw(LoadFile); use Data::Dumper; # step 1: open file open my $fh, '<', 'config.yml' or die "can't open config file: $!"; # step 2: convert YAML file to perl hash ref my $config = LoadFile($fh); print Dumper($config), "\n";

      Although I have my doubts this is the reason, you could try upgrading your YAML.

      Note that YAML's own documentation recommends switching to YAML::XS.

        That's probably the best choice, thanks for you input.

      Are you really getting this error?

      "Undefined subroutine &main::LoadFule called at test.pl line 18."

        Sorry, that's a typo.