0

In perl program I have found this line #!/usr/bin/perl -I Directory_name So I searched in net about the option -I in perl but i have not find the correct explaination.Can anyone tell me that what is the use of this option?

vaishali
  • 325
  • 2
  • 11

3 Answers3

2

There is a problem with your question, not the fact that you are just asking a researchable question, but the fact that you specify file_name in:

#!/usr/bin/perl -I file_name

the above is incorrect as -I searches a given directory for packages and you are specifiying a filename. The below switches will work, but each performs a different function.

#!/usr/bin/perl -i file_name
#!/usr/bin/perl -I DIR

There is a difference between -i and -I in perl.

So short answer:

-i: Modifies your input file in-place (making a backup of the original). Handy to modify files without the {copy, delete-original, rename} process.

-I: Directories specified by -I are prepended to the search path for modules (@INC )

Source of more detail perlrun

0

-I includes a directory to search for packages. See perldoc perlrun.

Here is an example, notice that we use Bar instead of use Foo::Bar:

test.pl
Foo/Bar.pm

test.pl

#!/usr/bin/perl -I Foo

use warnings;
use strict;

use Bar qw( frobnicate ); # Foo/Bar.pm

my $output =  frobnicate('hello');
print $output . "\n";

Foo/Bar.pm

package Bar;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(munge frobnicate);  # symbols to export on request
1;

sub munge {
    my ($txt) = @_;
    return join '*', sort split //, $txt;
}

sub frobnicate {
    my ($txt) = @_;
    return join '....', sort split //, $txt;
}

Output

./test.pl
e....h....l....l....o
xxfelixxx
  • 6,512
  • 3
  • 31
  • 38
0

We can also find the short description of perl command line options using the below command. So there is no necessary to install perldoc.

perl --help 

The above command gives an short description of each options which are may not find in man pages.

vaishali
  • 325
  • 2
  • 11