Hello everyone,
This is in a subroutine.
my @block = @_;
my $string = join ("", @block);
First I do this to turn an array of strings into one single string. Then assign two variables to random values (for purpose of testing):
$preDB = "whydoyou";
$postDB = "hateme";
Then
if($string =~ m/Pre BD/i)
{
$indexPre = index($string, "Pre BD:");
$indexPost = index($string, "Post BD:");
$indexLV = index($string, "Lung Volumes:");
$preDB = substr($string, $indexPre, ($indexPost - $indexPre));
$postDB = substr($string, $indexPost, ($indexLV - $indexPost));
print "\nIn IF String: " . $string;
print "\nIn IF pre: " . $indexPre;
print "\nIn IF post: " . $indexPost;
print "\nIn IF LV: " . $indexLV;
print "\nIn IF PreDB: " . $preDB;
print "\nIn IF PostDB: " . $postDB;
In my output, string outputs fine and all the index have appropriate integer values given the string. However, both preDB and postDB continue to taunt me with their hatred. If I change the above assignment to preDB and postDB to print statements of the substr, the output is appropriate (ie. it shows the appropriate substring).
I am stumped as to why the output of substr will properly print but not assign to a string.
Thanks for your time and consideration.
My best wishes,
Droppy
This is in a subroutine.
my @block = @_;
my $string = join ("", @block);
First I do this to turn an array of strings into one single string. Then assign two variables to random values (for purpose of testing):
$preDB = "whydoyou";
$postDB = "hateme";
Then
if($string =~ m/Pre BD/i)
{
$indexPre = index($string, "Pre BD:");
$indexPost = index($string, "Post BD:");
$indexLV = index($string, "Lung Volumes:");
$preDB = substr($string, $indexPre, ($indexPost - $indexPre));
$postDB = substr($string, $indexPost, ($indexLV - $indexPost));
print "\nIn IF String: " . $string;
print "\nIn IF pre: " . $indexPre;
print "\nIn IF post: " . $indexPost;
print "\nIn IF LV: " . $indexLV;
print "\nIn IF PreDB: " . $preDB;
print "\nIn IF PostDB: " . $postDB;
In my output, string outputs fine and all the index have appropriate integer values given the string. However, both preDB and postDB continue to taunt me with their hatred. If I change the above assignment to preDB and postDB to print statements of the substr, the output is appropriate (ie. it shows the appropriate substring).
I am stumped as to why the output of substr will properly print but not assign to a string.
Thanks for your time and consideration.
My best wishes,
Droppy