Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converstion from array to

Status
Not open for further replies.

jeyyu

Technical User
Joined
Jun 1, 2007
Messages
3
Location
US
Hi, I am trying to figure out how to write a script to convert the following below from

!
probe blah http
request method head url /blah/blah.html
expect status 200
interval 20
retries 2
failed 60
port 80

to
add lb monitor <blah> HTTP -url </blah/blah.html> -interval <20> -port <80> -retries <2>

I need to be able to extract part of what i want from the first block and use them for my syntax as described above. how do you i start about in the logic. thanks!


 
not much. I can't figure out how to take each element and put it in it's separate variable.

open (file, "input.txt") or die ("can't open file");
#write it into a array
@myfile=<file>;
foreach $i (@myfile) {
print "$i\n" ;

}
print "\n\n";
print "$myfile[0]";

As expected,the loop prints out the array element.When i print out element 0,it prints out, probe blah http.

I want to get probe,blah and http on it's own element..


 
thanks. however, i am still not able to bunch each word in it's own element in the array. this is what i have:

open (file, "input.txt") or die ("can't open file");
#write it into a array
@myfile=<file>;


foreach $i (@myfile){
@tmp=split /\s+/, $i;
print @tmp;
}

print ("\n\n");

print "the name of the monitor is ";
print @tmp[1];

--

When I look for @tmp[1], I expect blah as my second element but i get port!. do you know why that is? Thx.
 
this will get you closer but you'll see there is still more that needs to be done to get the output you want.

Code:
open (FILE, "input.txt") or die ("can't open file: $!");
my @myfile = <FILE>;
close(FILE);

foreach my $i (@myfile){
    my @tmp = split /\s+/, $i;
    print "$temp[1]\n";
}



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Just a small typo fix

Code:
open (FILE, "input.txt") or die ("can't open file: $!");
my @myfile = <FILE>;
close(FILE);

foreach my $i (@myfile){
my @tmp = split /\s+/, $i;
print "$tmp[1]\n";
 
Ahhh.. fixed the type and added another
Code:
open (FILE, "input.txt") or die ("can't open file: $!");
my @myfile = <FILE>;
close(FILE);

foreach my $i (@myfile){
    my @tmp = split /\s+/, $i;
    print "$tmp[1]\n";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top