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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeating a task for each item in a list?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I learn best from seeing samples of scripts so it'd be great if someone could
show me a sample script of the folling. You have a list of something such as
"apple,orange,grape,lemon" located as a text file in the same directory and
you have it do a task for each item in the list. For the sake of simplicity,
let's say you just print each word. So this is what the general over view is

set variable x to the contents of the text file
repeat (ammount of times in list) times
set y to the item from x
print y
end repeat

And end up with it printing "appleorangegrapelemon".. this isn't exactly what
I want to do so please don't just give me a script that replaces ","s with
nothing.. please have it in the format I listed and this will be greatly
appreciated. This is for a special type of forum btw, and I just can't figure
this out. Thanks alot in advance
 
Good day,
I will give u an example that i have already developped to treat a set of files.
The PERL/CGI script opens a directory, load all files in a list, and when u click the start button, there is a program called to treat each file tn the list.
It is so long , so i will write u the parts u seek !
Good luck !

I will send you the entire script if u like,but i dont know your E-mail !!

/**************************************/
/* Reading the directory and loading its content in a list

# Ouverture du répértoire $dir

opendir(DIR_out,$dir);
while ( $fichier=readdir (DIR_out) )
{
push ( @fichier , $fichier);
}
close (DIR_out) ;
@fichier=sort {uc($a) cmp uc($b)} (@fichier);
splice(@fichier,0,2);
print &quot; <TD align='center'><B><FONT size='2'>Fichiers proposés</FONT></B><BR>&quot;;
print &quot; <SELECT align=top name='liste1' size=6 multiple >&quot;; #style='width:120px'
foreach (@fichier) {
print &quot;<OPTION value=$_>$_</OPTION>&quot;;
}
print &quot; </SELECT>&quot;;
/*********************************************************/
/* Getting the list elements in an array !

@tab_files=$q->param(&quot;liste2&quot;);

/*********************************************************/
/* Traitement of each file in the list (compressing the file) !

foreach $fich (@tab_files) {

system(&quot;compress $fich&quot;);
}

/**********************************************************/

That is all !!!
Hope this helps u !
 
good example
but here is a very basic one so that its more clear for u
Code:
# set all list in a array
@list = ('apple','orange','grape','lemon');
foreach $item (@list) {
 print &quot;\n$item&quot;;
}
so this will print
apple
orange
grape
lemon

hope this help's
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Good day,
Surely,your example , &quot;NEVERSLEEP&quot; is so simple to understand !
I hope this helps our friend 'ninesky' !!!
Good work ! i advice u to sleep some times because :
&quot; Early to bad, early to rise , make body healthy , wealthy and wise &quot; !!!
Bye !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top