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: Beginner:
Looping and printing Part 2

 



Louis Mc
Deleted

Apr 10, 2000, 10:06 PM

Post #1 of 4 (508 views)
Looping and printing Part 2 Can't Post

I read this in another reply below (Printing a list of variables). Would this work with my previous request?

for ($i = 1; $i <= 10; $i++){
$text1 = eval "\$friend_id$i";
$text2 = eval "\$mdl_num$i";
print "<Table><TR><TD>$text1<BR>$Text2<P></TD></TR>";
}

How do I replace the number 10 with the correct number of $friend_id[?] found? I was think of this:
$NumberLines = grep(/CR/i, @SortList);
#CR is the key I need to look for
for ($i = 1; $i <= $NumberLines; $i++){


Rivotti
User

Apr 11, 2000, 4:18 PM

Post #2 of 4 (508 views)
Re: Looping and printing Part 2 [In reply to] Can't Post

Hi Louis Mc:

There must be a better way to do this but I think this works:<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$grabthem= join("",@SortList);
while($grabthem=~ /CR/g)
{ $NumberLines++ }
</pre><HR></BLOCKQUOTE>

I didn't tested it but I think it works. Smile


Louis Mc
Deleted

Apr 11, 2000, 7:55 PM

Post #3 of 4 (508 views)
Re: Looping and printing Part 2 [In reply to] Can't Post

Ok, I'll give it a try. Thanks Rivotti!

#defining $grabthem
$grabthem= join("",@SortList);

#loop, I'll have to look this '=~'
#and this '/g' up in a PERL doc
while($grabthem=~ /CR/g)

#This I don't understand, but that's
#why I'm here ;^)
{ $NumberLines++ }


Rivotti
User

Apr 12, 2000, 1:33 AM

Post #4 of 4 (508 views)
Re: Looping and printing Part 2 [In reply to] Can't Post

Hi again:

"=~" and "/g" are part of the syntax of the regular expressions. Regular Expressions are used to match, substitute, count, validade strings.

while($grabthem=~ /CR/g)
{ ... }
means that:
while there is "CR" in the string the program do something

and $NumberLines++ is the same as $NumberLines+1.

Check the Regular Expression Man Page or the basic regular expression syntax table.
There is also the Regular Expression FAQ.

I hope this help you.
Rivotti

[This message has been edited by Rivotti (edited 04-12-2000).]

 
 


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

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