Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substr outside of string at <file name> <line no>

Status
Not open for further replies.

1surya

Programmer
Jul 14, 2002
25
CA
Hi
I am using perl
what My program does is it will take each line from a file and put it into an array variable. and from the array variable I am placing specific part in to another array.

the code is as follows

@output contains the part of the file I want.
foreach my $id(@output)
{
$pdbid=substr($id,8,3);
push(@arrpdb,$pdbid);

}

at the line where I am assigning the part of the string to the $pdbid
its giving me an warning that
substr outside of string at <fine name ><line number>.
in the same program I am retriving a part of the string to another variable.

foreach my $acc(@output)
{

$accno=substr(@output,36,3);
push(@arracc,accno);
}
here also its promting the same warning.
but my program works fine.

The other warning I am getting is uninitialised value in hash element.


Can anybody kindly help me to solve these warnings.
thanks a lot
 
1) This just looks like maybe you have a blank line being input or something. The line is not 8 chars long. Your substr is grabbing chars 0,1,2 in an exactly 8 char long string. if it is 7 chars long, then it can't go backwards 8 characters to start the substr.

2) The second one you are trying to grab a substr from an array which to my knowledge doesnt work.
Use a scalar. --Derek

&quot;Fear not the storm for this is where we grow strong.&quot;
 
hi Derek
you are absolutly correct regarding the second point.
I mistakenly typed array variable.But actually both are scalar.
$pdbid=substr($output,8,3);
$accno=substr($output,36,3);


regarding the warning

I am retriving the pdb file from the database into an array.
from the array with foreach loop I am taking each line into a scalar and from the scalar with substr function I am taking a perticular part.
regarding the length of line
its more than 90 charecters but there are spaces in between charecters.
could you give me some solution.
 
Hi Derek
You are absolutely correct regarding the length of the string.
I checked my code by giving length function. there are lines which are less than than what I specified in my substr function.
By finding this I fixed my problem. Now my program is running with out warnings.
Thanks a lot for your great help.
regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top