Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logics for array 2

Status
Not open for further replies.

JohnLucania

Programmer
Oct 10, 2005
96
US
#! /usr/bin/perl
use strict;
use warnings;

my @SeqChar;
print "Enter sequences and 'enter' and then Ctrl + D: ";
chomp(@SeqChar = <STDIN>);


sub StartChar {
my $abc;
$abc+= /(abc|ABC)/g
for @SeqChar;
return $abc
}


print "\n";
print "Yes, your input contains a seq char (abc).\n"
if StartChar ();
print "No, your input does not contain a seq char (abc).\n"
if !StartChar ();
print "\n";

If the put is 'aaaaaabcaaaddadaaaaaddd', it returns both of yes and No. It should return Yes only.

What am I missing here?

jl
 
your code is rather unusual in its approach, it seems much clearer to just do something like this:

Code:
sub StartChar {
    return(1) if grep(/abc/i, @SeqChar);
    return(0);
}
 
i don't think Kevin intended to be rude!

it does make for difficult reading though - only because it is overly complex

after all - this is all you are really doing:-

Code:
[b]#!/usr/bin/perl[/b]

print "Enter sequences and 'enter' and then Ctrl + D: ";
chomp($seqChar = <STDIN>);

print "\n";

if ($seqChar =~ /abc/i) {
  print "Yes, your input contains a seq char (abc).\n";
} else {
  print "No, your input does not contain a seq char (abc).\n";
}


Kind Regards
Duncan
 
Duncan,

I think thats JohnLucania's way of saying thank you. He has used that quaint salutation a few times now.
 
That is a great explanation! It helps a lot.
I think I ought to change my way of saying thank people. Something like, splendid, brilliant, ... :)
But, I still like charming though!

jl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top