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
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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-17-2006
sharatz83 sharatz83 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 5
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.
  #2 (permalink)  
Old 09-17-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,514
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
  #3 (permalink)  
Old 09-17-2006
sharatz83 sharatz83 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 5
how do you do it in perl?
What is the conditionals that I need to use?I`m sure theres a simple way to do it...
  #4 (permalink)  
Old 09-17-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,514
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
  #5 (permalink)  
Old 09-17-2006
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
I'm not exactly sure what you're looking for, but perhaps you could use a regular expression to match the characters here:
Quote:
if($AA[$i][$j] eq one of the characters S,H,A,R,A,T..what I do here??? ){
Maybe something like this:
Code:
if ( $AA[$i][$j] =~ m/SHARAT/ )
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 01:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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