If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Problems returning value in subroutine

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-23-07, 07:55
ejazzy ejazzy is offline
Registered User
 
Join Date: Feb 2007
Posts: 5
Problems returning value in subroutine

Hi All

I am rather frustrated with a subroutine that is supposed to does the following.

Reads a date from a file
removes the slashes
return the new values

This is the subroutine to do this
sub ReadFile {
$inputfilename = "$ENV{'PCRESCRIPT'}/config/effectivedate";
open( INFILE, "< $inputfilename" ) or die "Can't open $inputfilename : $!";
while( <INFILE> )
{
chomp;
$line = $_;
$line=~ s/\///g;
$datval= $line;
return "$datval\n";
} close (INFILE); }

In my second script, I would like to set a variable to this returned value. This is where I get stuck. This is how I am calling this routine in my second script.

#!/usr/bin/perl
require "/local5/depfa453/PCRESCRIPTS/batch/RUN/routinefile.pl";
$PCREDATE=ReadFile($datval);

Firstly, I hope I'm in the right direction but I get this error

routinefile.pl did not return a true value at ./routinetest.pl line 2

Any suggestions would be appreciated.

Regards
Reply With Quote
  #2 (permalink)  
Old 02-24-07, 14:17
KevinADC KevinADC is offline
Registered User
 
Join Date: Feb 2006
Posts: 56
does it only return one line?

Code:
sub ReadFile {
   $inputfilename = "$ENV{'PCRESCRIPT'}/config/effectivedate";
   open( INFILE, "< $inputfilename" ) or die "Can't open $inputfilename : $!";
   while( <INFILE> )
   {
      chomp;
      $line = $_;
      $line=~ s/\///g;
   }
   close (INFILE); 
   return "$line\n";
  }
}
1;#<-- need this at the end routinefile.pl

this line:

$PCREDATE=ReadFile($datval);

should just be:

$PCREDATE=ReadFile();

because you are not passing $datval to the sub routine, only getting a value back.
Reply With Quote
  #3 (permalink)  
Old 03-04-07, 16:42
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
(kevin covered it just fine, redundant comment removed.)

Last edited by sco08y; 03-04-07 at 16:47.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On