Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > length limitation with split() ?

Reply
Thread Tools

length limitation with split() ?

 
 
Peter_W_Levine@uhc.com
Guest
Posts: n/a
 
      07-18-2005
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?

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      07-18-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      07-19-2005
(E-Mail Removed) 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
 
Reply With Quote
 
Peter_W_Levine@uhc.com
Guest
Posts: n/a
 
      07-20-2005
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.

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      07-20-2005
(E-Mail Removed) 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

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-20-2005
(E-Mail Removed) <(E-Mail Removed)> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      07-21-2005
(E-Mail Removed) 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];
}
 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      07-22-2005
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
65K length limitation in MySQLdb? TT Python 1 06-10-2008 05:53 AM
HELP: Request String Length Limitation? Brad HTML 4 04-05-2006 09:00 AM
string length limitation of printf Seong-Kook Shin C Programming 3 02-04-2005 10:20 AM
Do webservices have a parameter length limitation? Al Knowles ASP .Net Web Services 0 08-29-2003 11:32 AM
How to get length of string? length() problems Mitchua Perl 5 07-17-2003 12:08 AM



Advertisments