Conditional only seeing last condition?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • starlight849
    New Member
    • Jun 2009
    • 82

    Conditional only seeing last condition?

    I have a perl script that goes to write to a file based on whether a string contains A, B, C, or D.
    The string are populated from a read in file and all letters are absolutely contained in the file and being read.
    Such as this:

    Code:
    if (($myString eq "A") ||  ($myString eq "B") || ($myString eq "C") || ($myString eq "D"))
    {
    print OUTFILE "print some stuff";
    }
    My problem is that whichever condition is last will be written to the file. (In this case D) If I changed the last condition to A then I would only see A's in the output.

    Is there something wrong with my conditional statement?
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Can you show us the contents of the file and how you're assigning $myString?

    You conditional could be cleaned up. Try this:
    Code:
    if ( $myString =~ /^[ABCD]$/ ) {
        print OUTFILE "print some stuff";
    }

    Comment

    Working...