I have written a very simple perl script for Linux to determine the current user logged on. However I keep getting the following error when trying to run it:
bash: use: command not found
bash: my: command not found
bash: ./test.pl: line 9: syntax error near unexpected token `else'
bash: ./test.pl: line 9: `} else {'
This is my code:
#!/usr/bin/perl
use strict;
my $loginName = '';
if ($^O =~ /MSWin/i)
{
$loginName = getlogin;
} else {
#else it is unix
$loginName = getpwuid($<);
}
print $loginName;
I have tried to google this but I dont see what I am doing wrong with my if statement? It works fine on Windows.
Thank you