You are actually not explicitly returning anything from the lctime
subroutine, which means that implicitly perl will return the last return
value of what happened in lctime. 

Here is what you need to do:

  * Change your printf to sprintf (i assume sprintf is what you really 
    want)

  * put a explicit return in. 

aka, 

sub lctime {
  ...
  ...
  return sprintf(...);
}


At the moment your printf statement is returning "true" (or '1') which
is the reason you are having '1' printed. 

simran.

  






On Tue, 2003-01-21 at 14:01, Harry Putnam wrote:
> Wiggins d'Anconia <[EMAIL PROTECTED]> writes:
> 
> > "The file must return true as the last statement to indicate
> > successful execution of any initialization code, so its customary to
> > end such a file with "1;" unless youre sure itll return true
> > otherwise.  But its better just to put the "1;", in case you add more
> > statements."
> 
> Maybe unrelated to the comments above since this is `do' I'm posting
> about in this post.  But I'm still seeing something here I don't
> understand.
> 
> I'll use my reall example code since that is where I notice this
> phenomena.
> 
> My function to slurp looks like:
> 
> cat /home/hgp/scripts/perl/fnc/lctime
> 
>   sub lctime {
>   ## Fucntion to create a date in my preferred format
>     @lta = localtime;
>   ## Adjust for mnth range of 0-11
>     $lta[4] += 1;
>   ## Adjust for year based on 1900, and remove leading 2 digits so
>   ## 103 first becomes 2003 and then 03
>     ($lta[5] = ($lta[5] += 1900)) =~  s/^..//;
>   ## Print it out in this format:
>   ## mnthdayyr hr:min:sec wkday (padding with zeros where necessary) 
>   ## Like 012003 15:15:51 01   
>     printf "%02d%02d%02d %02d:%02d:%02d %02d\n", @lta[4,3,5,2,1,0,6];
>   }
> 
> How can I print the output of this into a file handle?
> 
> When I try, I get an extra numeral 1 which I'm guessing is a return
> value from misguided referencing.
> 
> Example:
> 
> #!/usr/local/bin/perl -w
>   do "/home/hgp/scripts/perl/fnc/lctime";
>   open(FILE,">somefile");
>   print FILE "An extra numeral <" . &lctime . "> appears\n";
> 
> cat somefile
>   An extra numeral <1> appears
> 
> But the output of &lctime goes to tty.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to