in reply to Re: Creating a Menu List
in thread Creating a Menu List

Hi shmem
Thanks for your response it was really helpful.
I thought I would send you all my code with your suggestion attached
what is, I think is happening is its starting from the first entry in the array which is 0.
However no matter which selection I use it can’t seem to change to that user directory which does exist.
Any further help would be greatly appreciated.
#!/usr/bin/perl -w use Cwd; my $dir = getcwd; my $userhome = $ENV{HOME}; my $hdir = "/export/home"; my $userlist = "/$userhome/etc/userlist.cfg"; open(MYFILE, "$userlist") || die "Cant open File $userlist: $!\n"; my @ulist=<MYFILE>; foreach my $file (@ulist) {eval { print "\n"; $n++; print $n; print " $file\n"; }} print " Please select which user you would like to...\n"; my $number = <STDIN>; chomp $number; die "Invalid Selection\n" if $number =~ /\D/; die "Number given is too big\n" if $number > scalar(@ulist); my $user = $ulist[$number]; chdir("$hdir/$user") || die "Cant Change to directory $hdir/$user: $!\ +n"; &first; sub first { system("su - $user -c whatsrunning"); } sub second { print "Would you like to see the options again?\n"; my $answer = <STDIN>; chomp $answer; if ($answer eq "Y" || $answer eq "y" || $answer eq "yes") { system("su - $user -c whatsrunning"); &second; } else {exit 0; }} &second;

Replies are listed 'Best First'.
Re^3: Creating a Menu List
by lostjimmy (Chaplain) on Sep 16, 2008 at 16:03 UTC

    As already stated, it would be wise to add a use strict to the beginning of your script. You'll then have to add a my $n = 0 before the foreach loop.

    I think you're going to have to either decrement $number, since your menu starts at one, or instead start your menu at zero.

      Hi
      After playing around a while i have managed to get it working.
      Thankyou for all your help