Hi, I am writing a Perl script that reads some kind of INI file. I cannot use Config::INI or install any new modules due to some restriction so am reading the whole INI text file one line at a time and storing them into an array. Here are what on my INI files:
FTP_USER=FTPUser FTP_PASSWORD=FTPUser FTP_MODE=binary FTP_TARGET_SERVER=FTPSERVER FTP_ACTION_DIR=C:\FtpAction FTP_LOGPATH=C:\Temp NUM_OF_DIRS=2 DEFAULT_TARGET_DIR=C:\Temp SOURCE_DIR1=D:\Study\Perl\MyFtp SOURCE_DIR2=D:\Study\Perl TARGET_DIR1=C:\Dir1 TARGET_DIR2=C:\Dir2 Because I cannot install new modules, am not using Net::Ftp as well and instead creating an FTP batch file which I then execute as #system "ftp -v -n -i -w:8192 -s:$FTP_BATCHFILE"; So far so good. Now I want to change my Perl script so that I can parse the path of the source file and whether it matches SOURCE_DIR1 or SOURCE_DIR2 and if so use TARGET_DIR1 or TARGET_DIR2 respectively on the FTP Server otherwise use DEFAULT_TARGET_DIR. I am running the script as MyFtp.pl "D:\Study\Perl\Myftp\Test1.JPG", so I check if ARGV[0] matches the string of SOURCE_DIR1 and if so use C:\Dir1 as the target directory when I create the FTP batch file. At the moment, I am hardcoding the checks as something like ... if path = $SOURCE_DIR1 then TARGET_DIR=$TARGET_DIR1 elif path = $SOURCE_DIR2 TARGET_DIR=$TARGET_DIR2 else TARGET_DIR=$DEFAULT_TARGET_DIR Of course, the above is not the program code but am sure the gurus understand what I mean. Unfortunately, if I have to add two more directories to check for example, SOURCE_DIR3, SOURCE_DIR4 .... SOURCE_DIR[N] and TARGET_DIR3, TARGET_DIR4 ... TARGET_DIR[N], then I have to check my Perl script. So, what I want to be able to know is if it is possible to load the values of SOURCE_DIR1 to SOURCE_DIR[N] into an array, and if so, how? I want to know if I can create a dynamic variables $SOURCE_DIR$[N] that I can load into the array, I know what is the final [N] since I have NUM_OF_DIRS=2. I am wanting to do something that will look like this: my $count=1; my $source_array=() my $target_array=() while ( $count le $NUM_OF_DIRS ) { $source_array[$count]=$SOURCE_DIR$count; $target_array[$count]=$TARGET_DIR$count; #print $count . "\n"; #print $regex . "\n"; #if ($path =~ m/$regex/) { # print 'match'; #} else { # print 'no match'; #} $count++; } Then somewhere down the code, I do my $count=1; while ( $count le $NUM_OF_DIRS ) { if ($path =~ m/$source_array[$count]/) { TARGET_DIR=$target_array[$count]; } else { TARGET_DIR=$DEFAULT_TARGET_DIR; } $count++; } Obviously, this is not working at the moment, can someone on the list please advise if what I am trying to achieve is possible or not. If it is possible but am not creating or parsing the variables correctly, please advise on how I should be doing it. I have no problem evaluating each value of the INI files, i.e. I can parse $SOURCE_DIR1, $SOURCE_DIR2, $NUM_OF_DIRS etc., I just want to know how I can dynamically create a variable $SOURCE_DIR1 to $SOURCE_DIR[N] and store them into an array or perhaps how to check if a variable has been defined or not? Thanks in advance. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>