![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| how could i make a program mixed with many "|", "<" and ">" | strugglingman | High Level Programming | 2 | 04-29-2006 08:11 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
| Perl CGI to access / edit "root" owned config files | WIntellect | Shell Programming and Scripting | 1 | 04-23-2003 03:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
[B]"redo" in perl[/B]
I knew this would not work because of problem with "redo". Is there a way to fix this? Thanks a lot!
Code:
my @n = (10..100);
my $i;
my $j = 0;
my $k;
LINE1: for ($i; $i < 10; $i++) {
$k = $n[int rand @n];
$j += $k;
}
if ( ((550 - $j) < 10) || ((550 - $j) > 100) ) {
redo LINE1;
}
Last edited by zx1106; 03-18-2008 at 06:51 PM.. Reason: added code tags |
|
||||
|
The biggest problem is that redo is outside a loop. There is nothing to redo. Maybe this is what you mean to do (with print commands added for tracking process) :
Code:
my @n = (10..100);
my $i;
my $j;
LINE1: for ($i; $i < 10; $i++) {
$i = $n[int rand @n];
$j += $i;
if ( ((5500 - $j) < 10) || ((5500 - $j) > 100) ) {
print qq{Inside "if" condition $j\n};
redo LINE1;
}
print $j,"\n";
}
|
|
||||
|
Sorry I should make this more clear. Thanks to era and KevinADC for help.
The question I tried to solve equals to: Randomly divide a 5500 feet rope into 10 pieces, and the length of every piece should be (10..100) feet. |
|
||||
|
No, it is not. But I finally figure out I can use "goto" instead of "redo" just now.
Thanks for help! |
| Sponsored Links | ||
|
|