The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
[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
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Perhaps you could elaborate a bit on what this is supposed to do, and how it fails to accomplish that.
  #3 (permalink)  
Old 03-18-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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"; 
}
Next time do as "era" has asked and elaborate a bit more. It's too hard to guess at your intentions or what your code should do.
  #4 (permalink)  
Old 03-18-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
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.
  #5 (permalink)  
Old 03-18-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Is this school/class/course work?
  #6 (permalink)  
Old 03-18-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
Quote:
Originally Posted by KevinADC View Post
Is this school/class/course work?
No, it is not. But I finally figure out I can use "goto" instead of "redo" just now.
Thanks for help!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0