length limitation with split() ?

Discussion in 'Perl Misc' started by Peter_W_Levine@uhc.com, Jul 18, 2005.

  1. Guest

    I am running perl v5.8.6 under NT 2000.

    I am reading variable/value pairs out of a config file.
    Below is the entry that's giving me trouble. Note: Spaces ARE in the
    config file and are part of the filepath. The backslash character at
    the end of the line is NOT in the config file --- it is only there for
    readability.

    $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    KS/MSR/07-2005/07-14/EP500/covn_ks_msr_20050714_inc_error.tab


    I can read the above line fine using the following code fragment:

    elsif(/COSMOS_err_file/)
    {
    $COSMOS_err_file=(split('=',$_,2))[1];
    }

    But if the dirname is one character longer (ex.change EP500 to
    EP5000)then I get a null value for $COSMOS_err_file.

    $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    KS/MSR/07-2005/07-14/EP5000/covn_ks_msr_20050714_inc_error.tab

    Is there a limitation of some sort in split() or I am missing something
    obvious?
     
    , Jul 18, 2005
    #1
    1. Advertising

  2. wrote:
    > I am running perl v5.8.6 under NT 2000.
    >
    > I am reading variable/value pairs out of a config file.
    > Below is the entry that's giving me trouble. Note: Spaces ARE in the
    > config file and are part of the filepath. The backslash character at
    > the end of the line is NOT in the config file --- it is only there for
    > readability.
    >
    > $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    > KS/MSR/07-2005/07-14/EP500/covn_ks_msr_20050714_inc_error.tab
    >
    >
    > I can read the above line fine using the following code fragment:
    >
    > elsif(/COSMOS_err_file/)
    > {
    > $COSMOS_err_file=(split('=',$_,2))[1];
    > }
    >
    > But if the dirname is one character longer (ex.change EP500 to
    > EP5000)then I get a null value for $COSMOS_err_file.
    >
    > $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    > KS/MSR/07-2005/07-14/EP5000/covn_ks_msr_20050714_inc_error.tab
    >
    > Is there a limitation of some sort in split()


    Not that I know of.

    > or I am missing something obvious?


    You should probably do it like this:

    elsif ( s/^COSMOS_err_file=// )
    {
    $COSMOS_err_file = $_;
    }


    Or perhaps:

    elsif ( /COSMOS_err_file=(.+)/ )
    {
    $COSMOS_err_file = $1;
    }


    Or use one of the config file modules on CPAN.



    John
     
    John W. Krahn, Jul 18, 2005
    #2
    1. Advertising

  3. Joe Smith Guest

    wrote:

    > elsif(/COSMOS_err_file/)
    > {
    > $COSMOS_err_file=(split('=',$_,2))[1];
    > }


    I would do that as

    my($key,$val) = split /=/,$_,2;
    $COSMOS_err_file = $val if $key eq '$COSMOS_err_file';

    -Joe
     
    Joe Smith, Jul 19, 2005
    #3
  4. Guest

    I've tried your suggestion as well as both of John's and I still have
    the problem. As I mentioned in my first post, the problem occurs when I
    change the length of the dirname part of the path by a single
    character. (In the example from EP500 to EP5000. Interestingly I do
    NOT have the problem if I increase the length of the basename part of
    the file.

    I'm still stumped.
     
    , Jul 20, 2005
    #4
  5. Paul Lalli Guest

    wrote:
    > I've tried your suggestion as well as both of John's and I still have
    > the problem. As I mentioned in my first post, the problem occurs when I
    > change the length of the dirname part of the path by a single
    > character. (In the example from EP500 to EP5000. Interestingly I do
    > NOT have the problem if I increase the length of the basename part of
    > the file.
    >
    > I'm still stumped.


    I would strongly advise you to post a short-but-complete script that
    demonstrates your error, so that we can run it and verify what you're
    seeing. Otherwise, anyone trying to help is just grasping at straws
    guessing what the error might be.

    Paul Lalli
     
    Paul Lalli, Jul 20, 2005
    #5
  6. <> wrote:


    > I'm still stumped.



    Then show a short and complete program, that we can run, that
    demonstrates the problem, and we will help unstump you.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 20, 2005
    #6
  7. Joe Smith Guest

    wrote:
    > I've tried your suggestion as well as both of John's and I still have
    > the problem. As I mentioned in my first post, the problem occurs when I
    > change the length of the dirname part of the path by a single
    > character. (In the example from EP500 to EP5000. Interestingly I do
    > NOT have the problem if I increase the length of the basename part of
    > the file.
    >
    > I'm still stumped.


    The split() function has no limits on length, so what you are
    seeing should not be happening. Try printing the intermediate results.

    elsif(/COSMOS_err_file/)
    {
    print STDERR "Found COSMOS_err_file, line length=",length(),"\n";
    #### $COSMOS_err_file=(split('=',$_,2))[1];
    my @temp = split /=/,$_,2; # (See if /=/ differs from '=')
    print STDERR "\$temp[0]='$temp[0]' \$temp[1]='$temp[1]'\n";
    $COSMOS_err_file=$temp[1];
    }
     
    Joe Smith, Jul 21, 2005
    #7
  8. Guest

    wrote:
    > I am reading variable/value pairs out of a config file.
    > Below is the entry that's giving me trouble. Note: Spaces ARE in the
    > config file and are part of the filepath. The backslash character at
    > the end of the line is NOT in the config file --- it is only there for
    > readability.


    > $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    > KS/MSR/07-2005/07-14/EP500/covn_ks_msr_20050714_inc_error.tab



    > I can read the above line fine using the following code fragment:


    > elsif(/COSMOS_err_file/)
    > {
    > $COSMOS_err_file=(split('=',$_,2))[1];
    > }


    > But if the dirname is one character longer (ex.change EP500 to
    > EP5000)then I get a null value for $COSMOS_err_file.


    > $COSMOS_err_file=J:/DATA/Shared/EDITEAM/Coventry of \
    > KS/MSR/07-2005/07-14/EP5000/covn_ks_msr_20050714_inc_error.tab


    > Is there a limitation of some sort in split() or I am missing something
    > obvious?


    Are you checking that the data you are getting from the config file
    is the data that you are expecting... e.g. by printing each line
    as a diagnostic before the attempted operation?

    Axel
     
    , Jul 22, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad
    Replies:
    4
    Views:
    5,424
    Jim Higson
    Apr 5, 2006
  2. Seong-Kook Shin

    string length limitation of printf

    Seong-Kook Shin, Jan 28, 2005, in forum: C Programming
    Replies:
    3
    Views:
    6,755
  3. TT
    Replies:
    1
    Views:
    323
    Jarkko Torppa
    Jun 10, 2008
  4. Al Knowles

    Do webservices have a parameter length limitation?

    Al Knowles, Aug 29, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    400
    Al Knowles
    Aug 29, 2003
  5. Tim McDaniel

    Re: sys call length limitation

    Tim McDaniel, Jan 22, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    94
    Tim McDaniel
    Jan 22, 2014
Loading...

Share This Page