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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:40:04+00:00 2026-05-20T19:40:04+00:00

I am reading a string from a file: 2343,0,1,0 … 500 times …3 Above

  • 0

I am reading a string from a file:

2343,0,1,0 … 500 times …3

Above is an example of $_ when it is read from a file. It is any number, followed by 500 comma separated 0’s/1’s then the number 3.

while(<FILE>){
    my $string = $_;
    chomp($string);
    my $a = chop($string);
    my $found;
    if($string=~m/^[0-9]*\,((0,|1,){$i})/){         
        $found = $&.$a;
        print OTH $found,"\n";
        }   
}

I am using chop to get the number 3 from the end of the string. Then matching the first number followed by $i occurences of 0, or 1. The problem I’m having is that chop is not working on the string for some reason. In the if statement when I try to concat the match and the chopped number all I get returned is the contents of $&.

I have also tried using my $a = substr $a,-1,1; to get the number 3 and this also hasn’t worked.

The thing that’s odd is that this code works in Eclipse on Windows, and when I put it onto a Linux server it won’t work. Can anyone spot the silly mistake I’m making?

  • 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-20T19:40:05+00:00Added an answer on May 20, 2026 at 7:40 pm

    As a rule, I tend always to allow for unseen whitespace in my data. I find that it makes my code more robust expecting that somebody didn’t see an extra space at the end of a line or string (as in writing to a log). So I think this would solve your problem:

    my ( $a ) = $string =~ /(\S)\s*$/;
    

    Of course, since you know you are looking for a number, it’s better to be more precise:

    my ( $a ) = $string =~ /(\d+)\s*$/;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a string that I'm reading from a file to lowercase
I am reading in from a text file using StreamReader into a string array
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I'm reading a comma-delimited list of strings from a config file. I need to
How does performance for reading/adding values from/to Dictionary(Of String, SomeReferenceType) depend on the number
I am reading a string from an xml file stored on the sdcard that
I am reading in a String from a text file which contains a date
I am reading a UTF8 file and storing data read from file in an
I am reading a string from a file that reads like <div style=Z-INDEX: 654;
I've got a function that should read from file line by line, the reading

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.