Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:32:01+00:00 2026-06-04T22:32:01+00:00

This code is an if statement; I want to test whether $rtgene contains trn

  • 0

This code is an if statement; I want to test whether $rtgene contains trn.
I tested the code with $rtgene= nad3:

if ($rtgene!~/trn/){
$end=$data[$i][0]+100;
}
else{
$end =$data[$i][1];
}
print $end;

This is an alternative expression that doesn’t work:

($rtgene!~/trn/)? $end=$data[$i][0]+100 : $end=$data[$i][1]; print $end;

The problem is in the first code (normal if else statement) it works and give me the expected results, but the alternative one (last line) it’s not working; it always executes the else statement.

Question: What is the cause of this problem? How to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:32:02+00:00Added an answer on June 4, 2026 at 10:32 pm

    Since you are trying to assign one of two values to $end based on a condition, why not write the conditional expression like that:

    $end = ($rtgene !~ /trn/) ? $data[$i][0]+100 : $data[$i][1];
    print $end;
    

    This avoids the precedence problem accurately diagnosed by ysth and is quite a bit easier to understand.

    Perl can be used to write inscrutable code; it is not a good idea to make all your code inscrutable, though. Stacking the assignment and print on a single line is tending towards inscrutability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This line of code is a snippet from my select statement. frdFreedays - DateDiff(dd,conReceiptToStock,GetDate())
In this statement, taken from the Pagerank source code: Pattern.compile(\\[.+?\\]); What does the pattern
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
I want to test (true or false) whether an arbitrary XML file matches a
Question: I want to test an if statement in PostgreSQL: IF (SELECT COUNT(*) FROM
I am working on a little test app to scrape some data (in this
I want to write an if/else statement that tests if the value of a
I want to use prepared statement to insert and update data in mysqli, Below
I have this code in my program: (I included the cout statements for debugging

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.