Code:
use IO::Handle;
use File::Spec;
use CPAN;
use Win32::Registry;
You do not need to use any of those modules.
Quote:
system ('C:\Perl\eg\htpasswd.exe -b logg user passwd'); #this one works but i would like to be more flexible and do it like this:
$str = 'C:\Perl\eg\htpasswd.exe -b logg user passwd';
system ($str);
#this one doesn't work, WHY ?
|
There is no difference between the two. However, the better way to do it would be along the lines of
Code:
$program = 'C:\\Perl\\eg\\passwd.exe'; # there's not a difference between '\b' and '\\b', but there is a difference between '\\' and '\'
@params = qw/-b logg user password/;
system ($program, @params);
This is more efficient because it does not require perl to pass the command to a command interpreter (cmd).
If you get an error along the lines of
Quote:
Global symbol "$str" requires explicit package name at funktion.pl line 15.
Execution of funktion.pl aborted due to compilation errors.
|
this is because you are 'use'ing strict vars (this is good). Define $str like 'my $str = ...' instead.