length limitation with split() ?

P

Peter_W_Levine

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?
 
J

John W. Krahn

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
 
J

Joe Smith

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
 
P

Peter_W_Levine

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.
 
P

Paul Lalli

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
 
J

Joe Smith

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];
}
 
A

axel

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top