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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:19:50+00:00 2026-05-11T22:19:50+00:00

I am searching for a string in Perl and storing it in another scalar

  • 0

I am searching for a string in Perl and storing it in another scalar variable. I want to print this scalar variable. The code below doesn’t seem to work. I am not sure what is going wrong and what is the right way to go about it. Why is it printing ‘1’ when it doesn’t exist in the program?

Data it is running on

DATA

      13 E 0.496 -> Q 0.724
      18 S 0.507 -> R 0.513
      19 N 0.485 -> S 0.681
      21 N 0.557 -> K 0.482

The following is my code:

#!/usr/bin/perl
use strict;
use warnings;

my $find = '\s{10}[0-9]{2}\s[A-Z]'; #regex. it can also be '\s{10}[0-9]{2}\s[A-Z]' 
                                    #both dont seem to work
my @element;
open (FILE, "/user/run/test") || die "can't open file \n";
while (my $line = <FILE>) {
    chomp ($line);
    print "reached here1 \n"; # to test whether it reading the program properly
    my $value = $line=~ /$find/ ;
    print "reached here 3 \n"; # to test whether it reading the program properly
    print "$value \n";
}
exit;

OUTPUT

reached here1

1 

reached here 3 

reached here1 

1 

reached here 3 
  • 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-05-11T22:19:50+00:00Added an answer on May 11, 2026 at 10:19 pm

    The regex matching operation returns true (1) for match success, false otherwise. If you want to retrieve the match, you should try one of the following:

    • use the match variables $1, $2…
    • match in list context ($m1, $m2) = $string =~ /$regex/

    Note that you need to use captures in your regex for these to work. Which you’re not doing yet.

    You ought to take a look at the complete documentation in perlop, section “Regexp Quote-Like Operators”

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

Sidebar

Related Questions

I am using this python library that implements the Aho-Corasick string searching algorithm that
I'm searching a string for score but I don't want it to return when
Hello friends, I want to add a custom button on my searching string like
I need to do some extensive searching and string comparisons and for this I
I got this script while searching through stackoverflow string commonTextBoxPrefix = txt; foreach (Control
I'm studying string searching algorithms now and wondering what algorithm is used for .NET
For the two string searching algorithms: KMP and suffix tree, which is preferred in
I'm searching a string for a certain pattern. $string = Monday: 08.00-18.00; $pattern =
I need to create an array by searching a string for occurrences of '['
I am searching for the string <!--m--><li class=g w0><h3 class=r><a href= within the HTML

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.