Hi, I want to read a file and copy the data into an array. The file whose contents needs to be copied is below:
#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 see the code below that stored the file content into an array and further to Hash(Associative array.)
#! /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"; }
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
%edit = (e101 => 'Srvr_mngr ', e102 => 'Server_name', e103 => 'User_na +me ', e104 => 'Password').......;
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".
#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 I need to invoke a command line from my script. I have tried something like this.
#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
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

In reply to How to copy an array to a hash? by Ethen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.