Sponsored Content
Top Forums Shell Programming and Scripting Perl- Nested 'for' order change Post 302540555 by acsg on Thursday 21st of July 2011 06:07:56 AM
Old 07-21-2011
Perl- Nested 'for' order change

Hello,

I'm quite new to perl so my question is rather basic and I know there is probably a simple way around it but I can't seem to find it.

I have a medium-length code and there is a part that works with a nested for loop:

Code:
 foreach my $j(@primpiddelta){
                    for (my $k=1; $k <=10; $k++){
                         my $test1= (($P_cc + ($j * $k)) + 1)%16;
                         if($C_cc == $test1 && $k <= 9){
                            $flag=1;
                            my $prim_estim= $I_time/$mean_I_time;
                            if($prim_estim > $k){
                                $output= "@fields[0]\t\t$I_time\t\t$k\t\t$P_cc\t\t$C_cc\t\t$mean_I_time-\n";
                             }
                            else{
                                my $prim_estim2 = round($prim_estim);
                                $output= "@fields[0]\t$I_time\t\t$prim_estim2\t\t$P_cc\t\t$C_cc\t\t$mean_I_time--\n";
                             }
                             last;
                         }
                         elsif ($k > 9 && $flag != 1 && @primpiddelta[2] == $j && $alert != 1){
                            $output= "@fields[0]\t\t$I_time\t\t-1\n";
                         }
                         elsif($flag == 1){
                            last;
                         }
                     }  
            }

So, the problem that I have is in the two first "for" loops. I'd like to change the order in which they run:
for example, check the first value of @primpiddelta with $k= 1, then check the second value of @primpiddelta with $k=1 as well, and so on and so forth until the last value of @primpiddelta. Then, continue with $k=2, etc.

I'm guessing the solution is probably not using a 'for' loop but I'm a bit (lot) blocked.

Any help is much appreciated.

Thanks

---------- Post updated at 01:07 PM ---------- Previous update was at 10:59 AM ----------

very simple indeed.... I just had to change the order of the 'for' loops. Sorry ! Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to change the order of a string ?

Hi , I want to change the order of a string using sed command . Is it possible ? $echo "abc123xyz" | sed 's/\()*\) \(*\)/\2\1/' abc123xyz $ echo "abc123xyz" |sed 's/\()*\) \(*\) \()*\)/\2\1\3/' abc123xyz I want to change the string , abc123xyz as xyz123abc . Is it... (5 Replies)
Discussion started by: rajavu
5 Replies

2. HP-UX

ServiceGuard mounting nested file systems in wrong order

Hi all. I am having an issue and I'm not sure if anyone here would know the answer but I thought I'd ask anyway. The problem is with ServiceGuard where the control file lists the file systems to mount in a sequential order but ServiceGuard is mounting them as it feels like it. This is especially... (3 Replies)
Discussion started by: keelba
3 Replies

3. AIX

How to change the order of authentication in aix?

I have an AIX system configured as NIS client. I have an local user on the system called "batman" and i have a user by the same name in NIS as well. Now when i try to login with Batman user, the local batman gets in. How do I tell the AIX machine to authenticate Batman as NIS user? ... (2 Replies)
Discussion started by: balaji_prk
2 Replies

4. Shell Programming and Scripting

Change many columns position/order

Hi everyone, Please some help over here. (I´m using cygwing) I have files with 40 columns and 2000 lines in average. I´m trying to change the order position as follow. Original columns position:... (3 Replies)
Discussion started by: cgkmal
3 Replies

5. UNIX for Advanced & Expert Users

How to set the SGE job execution order for nested qsub?

Dear All I am trying to write a script to set the SGE job execution order. I named each job with 'job1', 'job2' and 'job3'. I want my script to do: When 'job1' execution is complete, 'job2' is executed; when both 'job1' and 'job2' are complete, 'job3' is executed. First, I tried this... (0 Replies)
Discussion started by: cliffyiu
0 Replies

6. Shell Programming and Scripting

Change order

Good evening I have a file as below and want to change the order, as in the second column, sed awk Pearl Thanks aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa bbbbbbbbb cccccccc aaaaaaaaaa cccccccc bbbbbbbbb aaaaaaaaaa cccccccc bbbbbbbbb (8 Replies)
Discussion started by: Novice-
8 Replies

7. Shell Programming and Scripting

change order

I have inside a file 22 25 80 111 631 694 861 875 I need this in the form using awk or sed 22,25,80,111,631,694,861,875 (4 Replies)
Discussion started by: anil510
4 Replies

8. UNIX for Dummies Questions & Answers

change service order

hi guys I have a service that depends on some shares (NFS shares ) that need to be mounted before before the service start so the service-app finds the NFS shares and starts correctly... I am confused here this is what I found but I am not sure what to do in order to change it BTW is Suse... (2 Replies)
Discussion started by: karlochacon
2 Replies

9. Shell Programming and Scripting

Change of fields order inline

Hi everyone, What is the best solution to check every line in the xml file and change order of found field along with its value without touching value. Pattern will be given i.e. one line can look like this one: <widget position="value,value" size="value,value" name="value"... (5 Replies)
Discussion started by: TiedCone
5 Replies

10. Shell Programming and Scripting

How to change row by order nr?

Hello, I have a file with thousands of rows and I need to change sequence of lines. Sample file: #NAME #SERVICE 112233 #DESCRIPTION AABBCCDD #SERVICE 738292 #DESCRIPTION FFYYRRTT ... ... ... Desired output: #NAME (5 Replies)
Discussion started by: baris35
5 Replies
break(1)                                                           User Commands                                                          break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 03:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy