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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:37:22+00:00 2026-05-14T04:37:22+00:00

I am very new to Perl, so please bear with my simple question: Here

  • 0

I am very new to Perl, so please bear with my simple question:

Here is the sample output:

Most successful agents in the Emarket climate are (in order of success):
1.  agent10896761       ($-8008)
2.  flightsandroomsonly     ($-10102)
3.  agent10479475hv     ($-10663)
Most successful agents in the Emarket climate are (in order of success):
1.  agent10896761       ($-7142)
2.  agent10479475hv     ($-8982)
3.  flightsandroomsonly     ($-9124)

I am interested only in agent names as well as their corresponding balances, so I am hoping to get the following output:

agent10896761       -8008
flightsandroomsonly     -10102
agent10479475hv     -10663
agent10896761       -7142
agent10479475hv     -8982
flightsandroomsonly     -9124

For later processes.

This is the code I’ve got so far:

#!/usr/bin/perl -w
open(MYINPUTFILE, $ARGV[0]);

while(<MYINPUTFILE>)
{
    my($line) = $_;
    chomp($line);

    # regex match test
    if($line =~ m/agent10479475/)
    {   
        if($line =~ m/($-[0-9]+)/)
        {
            print "$1\n";
        }

    }
    if($line =~ m/flightsandroomsonly/)
    {
        print "$line\n";
    }
}

The second regex match has nothing wrong, ’cause that is printing out the whole line. However, for the first regex match, I’ve got some other output such like:

$ ./compareResults.pl 3.txt
2.      flightsandroomsonly             ($-10102)
0479475
0479475
3.      flightsandroomsonly             ($-9124)
1.      flightsandroomsonly             ($-8053)
0479475
1.      flightsandroomsonly             ($-6126)
0479475

If I “escape” the braces like this

if($line =~ m/\($-[0-9]+\)/)
{
    print "$1\n";
}

Then there is never a match for the first regex…

So I’m stuck with a problem of making that particular regex work. Any hints for this? Many thanks in advance.

  • 1 1 Answer
  • 2 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-14T04:37:23+00:00Added an answer on May 14, 2026 at 4:37 am
    perl -ane '$F[2]=~s/\(|\)//g;print "$F[1] $F[2]\n" if $F[1]=~/agent|flight/' file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies for a simple question, but I'm very new to Perl! I have an
Warning - I am very new to NHibernate. I know this question seems simple
I am new to Perl and I have a problem that's very simple but
I am very new to perl so please help me out in following I
I am new to perl so please accept my apologies if my question is
I very new to Python, and fairly new to regex. (I have no Perl
Very new mobile developer here... I am trying to retrieve a list of tweets
I'm very new to Perl programming. I've just finished reading the Llama book. Up
I have the following code in Perl. I am very new to the language:
I am very new to Perl (scripting languages in general) and I was wondering

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.