develooper Front page | perl.perl6.users | Postings from September 2017

Re: write bytes requires an object with REPR MVMOSHandle

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
September 29, 2017 19:23
Subject:
Re: write bytes requires an object with REPR MVMOSHandle
Message ID:
c0dc89be-92b8-33d4-a20b-61290edb1f0b@zoho.com
>> On Fri, Sep 29, 2017 at 1:49 AM, ToddAndMargo <ToddAndMargo@zoho.com 
>> <mailto:ToddAndMargo@zoho.com>> wrote:
>> 
>>     Hi All,
>> 
>>     I am stumped.  This only screws up in the for loop.
>> 
>>     This is only the chopped up version
>> 
>>     <code>
>>     #!/usr/bin/env perl6
>> 
>>     my $SmtpIniFileName = $?FILE ~ ".ini";
>>     my %SmtpIni = [ 'DebugTrace' => "",      #   1 | 0  (-vvv)
>>                      'smtp'       => "",      # smtp.zoho.com
>>     <http://smtp.zoho.com>
>>                      'port'       => "",      #   465 (ssl), 587 (tls),
>>     25, 80, 3535 etc.
>>                      'username'   => "",      #   Typically the sender's
>>     eMail address, but not always.
>>                                               #   Blank will default
>>     tothe sender's eMail address;
>>                      'password'   => "",      #   User's ($username)
>>     password
>>                      'from'       => "",      #   The sender's eMail
>>     address;
>>                      'to'         => @[""],   #   qw [ larry@zoho.com
>>     <mailto:larry@zoho.com> currly@gmail.com <mailto:currly@gmail.com>
>>     ];   # This is an array, not a string; delimit with a space
>>                      'Subject'    => "",      #   Subject of the eMail
>>                      'Text'       => "",      #   Body (verbage) of the
>>     eMail
>>                      'FileName'   => @[""] ]; #   attachment path and
>>     name. Leave blank for no attachment
>> 
>> 
>>     sub PrintRed    ( $Str ) { print color('bold'), color('red'), 
>>       "$Str", color('reset'); }
>>     sub PrintGreen  ( $Str ) { print color('bold'), color('green'),
>>     "$Str", color('reset'); }
>>     sub PrintBlue   ( $Str ) { print color('bold'), color('blue'), 
>>     "$Str", color('reset'); }
>>     sub PrintRedErr ( $Str ) { $*ERR.print: color('bold'), color('red'),
>>     "$Str", color('reset'); }
>> 
>>     sub CreateSmtpIni () {
>>              my $SmtpHandle = open( $SmtpIniFileName, :rw );  #
>>     Read/write, create if does not exist
>>              chmod 0o400, $SmtpIniFileName;                   #
>>     Read//write to root only
>>              RunNoShell ( "chown root.root $SmtpIniFileName" );
>> 
>>              $SmtpHandle.print( "# SmtpIni file for for $IAm\n" );
>>              $SmtpHandle.print( "#    This file must be owned by
>>     root.root and have a permission of 400\n" );
>>              $SmtpHandle.print( "#    Do not use a space after the =
>>     sign.  \n" );
>>              $SmtpHandle.print( "#\n" );
>> 
>>              for %SmtpIni.kv -> $key, $value {
>>                      PrintGreen ( "key = <$key>  value =<$value>\n" );
>>                 if    ( $key eq "to" )       { $SmtpHandle.print( "$key=
>>     #delimiter is a comma\n" ); }
>>             elsif ( $key eq "FileName" ) { $SmtpHandle.print( "$key=
>>     #delimiter is a comma\n" ); }
>>             else { $SmtpHandle.print( "$key=\n" ); }
>>          close ( $SmtpHandle ); }
>> 
>>              PrintRedErr ( "$SmtpIniFileName was not found.  Recreating
>>     a blank template.\n" );
>>              PrintRedErr ( "Please edit this template and try again. 
>>     Cowardly existing.  Bummer dude.\n\n" );
>>          exit 2;
>>     }
>> 
>>     CreateSmtpIni();
>> 
>>     </code>
>> 
>>     # CheckRaid.pl6
>>     key = <Subject>  value =<>
>>     key = <port>  value =<>
>>     write bytes requires an object with REPR MVMOSHandle (got VMNull
>>     with REPR Null)
>>        in sub CreateSmtpIni at ./CheckRaid.pl6 line 52
>>        in sub GetSmtpIni at ./CheckRaid.pl6 line 62
>>        in block <unit> at ./CheckRaid.pl6 line 143
>> 
>>     Line 52 is
>>          else { $SmtpHandle.print( "$key=\n" ); }
>> 
>>     # cat CheckRaid.pl6.ini
>>     # SmtpIni file for for CheckRaid.pl6
>>     #    This file must be owned by root.root and have a permission of 400
>>     #    Do not use a space after the = sign.
>>     #
>>     Subject=
>> 


On 09/29/2017 11:59 AM, Andy Bach wrote:
>      close ( $SmtpHandle ); }
> 
> Your indenting has done you wrong - you close the file handle inside the 
> loop for loop, so it closed after the first print.
> 

Hi Andy,

AH POOP!  I was closing the handle after each iteration of the loop.
I must have stared at that 1000 times.  I move the close outside
the loop and happy camping returned.

Great catch.  Thank you for the second pair of eyes!

-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About