Closed Thread
Results 1 to 6 of 6

Thread: substr() bug?

  1. #1
    NeedHelp Guest

    substr() bug?

    I use Active Perl in windows to do my perl scripting and then migrate it to a Linux machine. I've found two bugs:

    1) I parse a file and I read segments to get values. One segment looked like:

    Code:
    $stringValue = substr($n,64,20);
    And with Active perl this worked great! So my testing worked great. I move this to production and everything worked great. Then one file I get some odd values. The substr was actually assigning more than 20 characters all of a sudden. I received around 40. I could change the 64 starting value to 60, 70, etc and it would always grab more than 20. I had to end up doing this to make it work in Linux:

    Code:
    $stringValue = substr($n, 64, 20);
    $stringValue = substr($stringValue, 0, 20);
    Very odd....

    2) Again I'm reading segments and everything is fine in windows. I move it to Linux and have issues. I am using a substr:

    Code:
    $value = substr($n, 0, 256);
    But I get wierd results in Linux so I had to modify to this:

    Code:
    $value = substr($n,0,128);
    $value = $value . substr($n, 0, 128);
    Can anyone explain this to me or tell me a fix? I'd like my test and production environment to work the same.

  2. CODECALL Circuit advertisement

     
  3. #2
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    must be an issue with the data you are running through the substr() function. There is no differenc between substr on winodws or linux that I am aware of.

  4. #3
    NeedHelp Guest
    Quote Originally Posted by KevinADC View Post
    must be an issue with the data you are running through the substr() function. There is no differenc between substr on winodws or linux that I am aware of.
    That is what I always thought and truthfully I expected it to work better on Linux instead of vise versa. If I can provide the sample data is anyone willing to try to repeat the bug?

  5. #4
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    I'll take a look.

  6. #5
    Jordan Guest
    I will as well. I have various Linux machines I can test on and will install ActivePerl if you tell me the version you use.

  7. #6
    NeedHelp Guest
    Ok, I'll post all the information to replicate this problem next week when I'm back at work.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Where would i put a conditional substr?
    By Cyberen in forum PHP Development
    Replies: 1
    Last Post: 09-06-2011, 11:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts