subr01 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script which needs to read an array from a/bcd/sample/array.list How can I pass this list file as an argument to a function in my perl script?

  • Comment on Passing arguments from a different directory.

Replies are listed 'Best First'.
Re: Passing arguments from a different directory.
by choroba (Cardinal) on Jun 04, 2015 at 08:05 UTC
    Passing a file path is just passing a string:
    sub get_path { my $path = shift; # Retrieve the argument. print STDERR "DEBUG: Got '$path'"; # Show you got it correctly. } get_path('a/bcd/sample/array.list'); # Pass the argument.

    Or, did you mean something else? See How do I post a question effectively?, show us what you tried and how it failed.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Passing arguments from a different directory.
by Anonymous Monk on Jun 04, 2015 at 08:06 UTC

    I have a script which needs to read an array from a/bcd/sample/array.list How can I pass this list file as an argument to a function in my perl script?

    Pass from where, starting where?

    perl foo.pl a/bcd/sample/array.list ...

    #!/usr/bin/perl -- # foo.pl use strict; use warnings; use Path::Tiny qw/ path /; Main( @ARGV ); exit( 0 ); sub Main { my( @files ) = @_; for my $file ( @files ){ my $stuff = path( $file )->slurp_raw; ...; } }

    Path::Tiny, @ARGV, Writing subroutines...