![]() |
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 |
| Help with perl scripting on strings | sagarbsa | Shell Programming and Scripting | 2 | 04-29-2008 01:00 AM |
| Perl RegExp to remove last character from strings | ospreyeagle | Shell Programming and Scripting | 2 | 04-03-2008 02:55 PM |
| Using arrays with conditionals | myndcraft | Shell Programming and Scripting | 1 | 12-03-2007 08:59 PM |
| Multiple Conditionals | jeriryan87 | Shell Programming and Scripting | 1 | 07-02-2007 04:07 PM |
| sort() array of strings in perl | photon | Shell Programming and Scripting | 2 | 10-19-2004 01:27 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
ideas for perl script - strings,conditionals..etc
I have a matrix , how do I compare all the elements of a column , lets say I want to check if the columns contain the alphabets "S","H","A","R","A","T".
and not "X"s. Lets say matrix looks something like this .. SSSXSH HHXXHA AAXXAT RRRXRS AAXTAR TTTTTA I can hard code it where $AA[0][$j] , $AA[1][$j] , $AA[2][$j] .. is the row and column ... like this .. for($j=0;$j<$len;$j++){ if($AA[0][$j] eq "what goes here??" && $AA[1][$j] eq "A" && $AA[2][$j] eq "A"){ print "blah blah \n"; exit;} else{} } what I would like to do is put it in 2 for loops like this... for($i=0;$i<3;$i++){ for($j=0;$j<$len;$j++){ if($AA[$i][$j] eq one of the characters S,H,A,R,A,T..what I do here??? ){ print "blah blah \n"; exit;} else{} } } Tips ideas and code are welcome. |
|
||||
|
my solution is in Python, could be converted to Perl easily.
Code:
matrix = [ 'SSSXSH', 'HHXXHA', 'AAXXAT', 'RRRXRS', 'AAXTAR', 'TTTTTA' ] for x in range( len(matrix[0] ) ): # matrix[0] is SSSXSH row = [ matrix[y][x] for y in range(len(matrix)) ] #['S', 'H', 'A', 'R', 'A', 'T'] if "SHARAT" == ''.join(row): print "Found SHARAT at column" , x |
|
||||
|
SSSXSH <---X
HHXXHA AAXXAT RRRXRS AAXTAR TTTTTA | y pseudocode: Code:
get values into matrix array..such that SSSXSH is first element and so on
loop through length of x
loop through length of y (length of whole matrix array)
get value of matrix[y][x] and store in array
compare array with SHARAT
|
|
||||
|
I'm not exactly sure what you're looking for, but perhaps you could use a regular expression to match the characters here:
Quote:
Code:
if ( $AA[$i][$j] =~ m/SHARAT/ ) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|