0

I'm trying to use 'cat file' in my Perl module like below,

my $batch_dir = '/home/lsubramaniyam/xxx';
    my $receive_file = $batch_dir->catfile("Recieve_file.txt");

But, on executing the script, I'm getting error as

Can't call method "catfile" without a package or object reference

I have included packages related to the file handles and OOPS,

 use IO::All;
    use IO::Socket;
    use IO::Socket::SSL;
    use Moo;
    use MooX::HandlesVia;
    use MooX::Options (
        protect_argv       => 0,
        prefer_commandline => 1,
    );
    use MooX::Types::MooseLike::Base
        qw(Bool Enum HashRef Int InstanceOf Maybe Str);
    use File::Spec;

Please help me on steps to proceed further. Any help is appreciated.

Logunath
  • 477
  • 1
  • 8
  • 20

2 Answers2

1

You should read the documentation more carefully. Lines 4 and 5:

use File::Spec;
$x=File::Spec->catfile('a', 'b', 'c');
choroba
  • 231,213
  • 25
  • 204
  • 289
1

You're calling catfile() as a method here. Methods can only be called on classes or objects. $batch_dir is just a string. You can't call methods on a string (that's what your error is saying).

The documentation for File::Spec shows catfile() being called as a class method. So you want something like this:

my $batch_dir = '/home/lsubramaniyam/xxx';
my $receive_file = File::Spec->catfile($batch_dir, 'Recieve_file.txt');
Dave Cross
  • 68,119
  • 3
  • 51
  • 97