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?

- 325
- 2
- 11
-
2Read [Command switches in perlrun](http://perldoc.perl.org/perlrun.html#Command-Switches) – zdim Mar 27 '17 at 05:18
-
1http://perldoc.perl.org/perlrun.html – Robby Cornelissen Mar 27 '17 at 05:18
-
I believe your question is answered here http://stackoverflow.com/questions/6302025/perl-flags-pe-pi-p-w-d-i-t – uzr Mar 27 '17 at 05:20
-
No, I am asking about capital i option. I have seen the link that you have give but i did not get solution from that link. – vaishali Mar 27 '17 at 05:29
-
@vaishali Is there a problem with looking at _Perl documentation_ that I linked for you in the first comment? It's right there. – zdim Mar 27 '17 at 05:40
-
sorry now only I have found this. Thank you . – vaishali Mar 27 '17 at 07:58
3 Answers
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
-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

- 6,512
- 3
- 31
- 38
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.

- 325
- 2
- 11