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 7991723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:22:28+00:00 2026-06-04T13:22:28+00:00

How to check if a variable is defined and search for two patterns within

  • 0

How to check if a variable is defined and search for two patterns within an array using perl regex?

$/ = ""; # paragraph mode

__Data__
#SCSI_test         # put this line into  @arrayNewLines      
kdkdkdkdkdkdkdkd
dkdkdkdkdkdkdkdkd
- ccccccccccccccc  # put this line into @arrayNewLines


  while(<FILEREAD>)
  {
      chomp;
      my @arrayOld = split('\n',$_);

      foreach my $i (0 .. $#arrayOld) # using the foreach of index to remove the lines.
      {
            if($arrayOld[$i] =~ /-(.*)/ || /\#(.*)/)
            {
                 my @arrayNewLines = $arrayOld[$i];
                 splice @arrayOld,$i,1;             # remove lines from arrayOld
                 print "@arrayNewLines\n";
            }
                 print "@arrayOld\n";
      }
   }

This code does not work in terms of placing each type of – or # lines into the same @arrayNewLines array. It only works on the first (/-(.)/) pattern and does not work on the second (/#(.)/). I need it to search on both patterns and defined the $arrayOld[i] variable to prevent use of uninitiilize messages.
I want to defined

  • 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-04T13:22:29+00:00Added an answer on June 4, 2026 at 1:22 pm
    if($arrayOld[$i] =~ /-(.*)/ || /\#(.*)/)
    

    This does not work the way you think it does, for the same reason that this wouldn’t either:

    if($x == 1 || 2)
    

    Use this instead:

    if($arrayOld[$i] =~ /-(.*)/ || $arrayOld[$i] =~ /\#(.*)/)
    

    Just as you’d use this:

    if($x == 1 || $x == 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I check a variable is defined before or not within the let
I wanted to check whether the variable is defined or not. For example, the
I'm trying to check if a variable has been defined as a nullable Guid.
I'd like to check if some variable is defined in R - without getting
I created an isset function to check if a variable is defined and not
I can use isset($var) to check if the variable is not defined or null.
M-x < TAB > prints all the defined functions. To check a variable is
I want to check if a value exists in a sequence defined as <xsl:variable
I'm trying to figure out how to use a defined variable when using <<<HTML
How I can check defined variable $var01 or not? The problem there are: <input

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.