Advertisement

04.04.2008 at 02:52PM PDT, ID: 23297548
[x]
Attachment Details

Perl script to process .ini file

Asked by leegin in Perl Programming Language

here is what I am trying to accomplish.
1. Process an ini file (ghost) to search for each one of the headings -> [code]
    and build a menu off of these. (so far this looks like it works)
2. next below each one of the headings there will be list of entrys like so
    7400=c:\somepath\ each one of these items should apear in a menu with the part to the left of the = sign        
    being the menu item, and the stuff to the right of the = sign be the value.( this is were I am stuck)
3. once the user selects the item from the second menu then the program should run a windows command
    that will launch another program.

is this possible. I have attached the code that I have sofar. to this point I am only able to read the ini file and build the first menu. you will see from the code.
I have also attached a copy of my ini file. the ini file needs to be in the root of the C drive.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
#!C:\Perl\bin\perl.exe
 
	use File::Copy;
	use File::DosGlob;
	use Config::INI::Simple;
	
	$cnt = 0;
	$num = 1;
	$cnt2 = 0;
	
	my	$ini = 'C:/ghost.ini';
	
	open( INFILE, $ini);
		@inLines = <INFILE>;
	close( INFILE );
	
	# Parse all MainMenu Items
	foreach $line (@inLines)
	{
		@chars = split(//,$line);
		
		if ($chars[0] eq "[")
		{
			$MainMenu[$cnt] = $line;
		}
		else
		{
			if($line eq "\n")
			{
				$trash = $line;
			}
			else
			{
				$Item[$cnt] = $line;
			}
		}
			$cnt++;		
	}
	
	# Build MainMenu now
	foreach $I (@MainMenu)
	{
		@L = split(//,$I);
		
		foreach $y (@L)
		{
			if($y eq "[" or $y eq "]")
			{
				$trash = $y;
				$cnt2++;
			}
			else
			{
				$w[$cnt2] = $y;
				$cnt2++;
			}
		}	
	}
	
	# Write character array to file
	open(INFO, ">C:/menu.tmp");
		print INFO @w;
	close(INFO);
	
	# Build new Array for MainMenu
	open(MENU, "<C:/menu.tmp");
		@MAINMENU = <MENU>;
	close(MENU);
	
		
	system('cls');			
	
	# Display Menu
	print "\n";
	print "*****   Welcome to the Leegin Ghost Server!!   *****\n\n";
	foreach $x (@MAINMENU)
	{
		print "\t" . $num . " " . $x;
		$num++;
	}
	print "\n";
	print "****************************************************\n";
	print "Please select the brand. ";
	$ans = <>;
	# Done with menu
Attachments:
 
change extension to .ini for it to work
 
 
Loading Advertisement...
 
[+][-]04.04.2008 at 03:13PM PDT, ID: 21286009

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 03:34PM PDT, ID: 21286121

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 06:35PM PDT, ID: 21286798

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.06.2008 at 10:22PM PDT, ID: 21294490

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628