Accepting user input and arguments in PERL

Hi All,

Can we pass arguments while calling the perl script and as well as ask user input during execution of the script?

My program is as below:
I am passing arg1 and arg2 as argements to test.pl
]./test.pl arg1 arg2

Inside the test.pl I have :

print "Do you want a name ? (y/n) : ";
my $YN = <>;
chomp $YN;
print "YN = $YN \n";

On execution it by passing arguments gives me some junk values in $YN where as with out arguments it waits to ask the input.

Any solutions?

Thanks in advance
JS

Change

my $YN = <>;

to

my $YN = <STDIN>;
2 Likes

Thank you so much .. its working :slight_smile: