Ethen has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I want to read a file and copy the data into an array. The file whose contents needs to be copied is below:
Now see the code below that stored the file content into an array and further to Hash(Associative array.)#File name: auto.txt #! usr/bin/perl -w $Srvr_mngr = `C:\Siebel\WebClient\Bin\srvrmgr.exe`; $Server_name = "server"; $User_name = "user"; $Password = "password"; $List_of_Values = `C:\Siebel\WebClient\Bin\ListOfValues.ifb`; $Row_id = "Session id";
Now I have the contents of the "auto.txt" in associative array "%edit". I want to assign keys to the elements of the file copied. Do I need to define the hash and assign each key to the variables. e.g#! /usr/bin/perl if(open(INFILE,"auto.txt")){ #Add the file contents to an array @data = <INFILE>; %edit = @data } else { print "No such file or directory\n"; }
or is there any other way to assign keys to the elements of the file "auto.txt". Please assist Cheers!! Ethen ---------------------- Hi, Thanks for the assitance, I have tried to do now this way. PFB first the contents of file "para.txt".%edit = (e101 => 'Srvr_mngr ', e102 => 'Server_name', e103 => 'User_na +me ', e104 => 'Password').......;
Now I need to invoke a command line from my script. I have tried something like this.#para.txt #this file contains the paramters to be used in the #command line. SRVMNGR = "E:\siebel\siebsrvr\bin\srvrmgr " GATEWAY = "gateway server name" ENTERPRISE SERVER = "enterprise server name" SERVER = "server name" USER = "user" PASSWORD = "password" SYSTEM_NAME = "WfProcMgr"
Now, it is required that when this command line is invoked in “migrate.pl”, lets say e.g SRVMNGR should automatically fetch its value from “para.txt” file which is "E:\siebel\siebsrvr\bin\srvrmgr". Same case with other parameters in the command line. How shall I invoke the command line in the script? Please suggest a clear alternative. Also, Once I got the contents of para.txt in "key" and "value", will the command line automatically picks up the values from them? Sorry for the long query but i would be greatful if someone provides me a solution. Let me knw if further details are required. Cheers!! Ethen#File name: "migrate.pl" #This file will fetch the data from "para.txt" and use #them to invoke + the command line open(INFD, "para.txt") or die "Error reading the file.....Please try a +gain\n"; @str = <INFD>; $i=0; $edit = {}; while($i <= $#str) { $line = $str[$i]; chop($line); @lineContents = split(/=/, $line); $edit->{$lineContents[0]} = $lineContents[1]; # print "one = $lineContents[0], two = $lineContents[1]\n"; $i++; } foreach $i (keys (%$edit)) { print "Key = $i Val = $edit->{$i}\n"; } @str1 = `SRVMNGR – g GATEWAY –e ENTERPRISE SERVER –s USER –p PASSWORD +–c”Run Task for comp SYSTEM_NAME processName="UDA Batch Deployment", +RowId=”Captured Session Id”`; print @str1; #I doubt if this will invoke the command line
Back to
Seekers of Perl Wisdom