CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Problem on the output

 



Vyrphan
New User

Feb 28, 2008, 4:37 AM

Post #1 of 2 (433 views)
Problem on the output Can't Post

Hi mates,
I'm making some scripts for Linux system, and i'm in trouble with one. In an instruccion foreach, the $line var get allways the same value, but the list where $line comes from have several different values.
I post here the code, and hope that someone can help me

Code
#!/usr/bin/perl 
@modules = ('isofs','reiserfs','loop','vfat','ext3','ipv6','fuse');
@ok_mod = (0, 0, 0, 0, 0, 0, 0);
$cmd_find = 'find /lib/modules -type f -iname \'*.o\' -or -iname \'*.ko\'';
$cmd_lsmod = 'lsmod';
$content = `$cmd_find`;
@txt = split('\n', $content);

foreach $line(@txt){#comprobar que està instal·lat
@words = split('/', $line);
for($i = 0; $i < @modules; $i++){
if($words[@words-1] =~ /$modules[$i]/ ){
@ok_mod[$i] = 1;
}
}
}
$content = `$cmd_lsmod`;
@txte = split('\n', $content);
$noway = 0;
do{
do{
$rnd = int(rand(@modules));
}while($ok_mod[$rnd] == 0);

foreach $line(@txte){
print $line;
@words = split(' ', $line);
if($words[0] == $modules[$rnd]){#està carregat
$noway++;
$ok_mod[$rnd] = 0;
last;
}
}
}while($ok_mod[$rnd] == 0 && $noway < 7); #estava carregat; en busquem un altre

if($noway == 7){ #tots els ṃduls de la llista estàn carregats
exit(1);
}else{
print $modules[$rnd];
}

the part that i'm having trouble is

Code
	foreach $line(@txte){ 
print $line;
@words = split(' ', $line);
if($words[0] == $modules[$rnd]){#està carregat
$noway++;
$ok_mod[$rnd] = 0;
last;
}
}


Thanks for help,
I'll wait for your answer


Vyrphan
New User

Feb 28, 2008, 5:41 AM

Post #2 of 2 (430 views)
Re: [Vyrphan] Problem on the output [In reply to] Can't Post

Problem solved:
the comparision between $words[0] and $modules[$rnd] was a string compare, not an integer compare.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives