Many thanks to Andy and Uri for their helpful comments. My problem is solved, 
plus I learned a lot in the process! — Rick


> On Jul 27, 2018, at 1:56 PM, Andy Bach <afb...@gmail.com> wrote:
> 
>     open my $fh1, '<', $file_to_convert
>         or die "Can't open $file_to_convert: $!\n"; 
>     $slurp = <$fh1>
>         or die "Could not slurp $file_to_convert: $!";
> 
> It's just a warning (the code works) that you're using $fh1 untested. This 
> doesn't complain
> if ( open my $fh1, '<', $file_to_convert ) {
>     $slurp = <$fh1>;
>     close $fh1;
> } 
> else { 
>     die "Can't open $file_to_convert: $!\n"; 
> }
> 
> note: the "close" has to be in the "if" block.  Good idea to close handles, 
> though, as soon as you're done with them. 
> 
> I guess it's not seeing the "or die" as a good enough test.
> 
> Uri wrote:
> > no need for xms if you aren't using those features.
> 
> Yaybut - I though D.Conway's Best Practice was to always include those, 
> unless you specifically didn't want one. Smacks of cargo cult but I'd never 
> argue with him.
> 
> On Fri, Jul 27, 2018 at 1:37 PM, Rick T <p...@reason.net 
> <mailto:p...@reason.net>> wrote:
> I tried to implement some advice about slurping that I read on this mailing 
> list (using local) but cannot get it to work. I get the message “Value of 
> <HANDLE> construct can be "0"; test with defined() at line 23” (the $slurp = 
> <$fh1> line). I’m using perl version 5.18.2 installed in 2014.
> 
> I’ve googled this error and think (ha!) I understand it, but though I’ve 
> tried many changes, I cannot make the error go away. I need the advice of 
> folks who are way ahead of me!
> 
> Rick Triplett
> 
> 
> use warnings;
> use strict;
> use DB_File; # module for Berkeley DBM w/ DB_HASH file type
> use CGI::Carp qw ( fatalsToBrowser );
> 
> # Declare some globals
> my $server = 'exploringmyself'; 
> my $file_to_convert = 'Untitled.tab'; 
> 
> chdir "/big/dom/x$server/data/courses/"
>     or die "Can't chdir to /courses: $!\n";
> if (! -e "$file_to_convert") {
>     die "Can't find $file_to_convert: $!\n"
> };
> 
> my $slurp;
> {
>     local $/;
>     open my $fh1, '<', $file_to_convert
>         or die "Can't open $file_to_convert: $!\n"; 
>     $slurp = <$fh1>
>         or die "Could not slurp $file_to_convert: $!";
>     $slurp =~ s/\r/\n/xmsg;     # swap Mac's CR for LF
>     $slurp =~ s/\x0b/<br>/xmsg; # swap Filemaker paragraph marker VT for html
>     close $fh1;
> }
> 
> 
> 
> 
> -- 
> 
> a
> 
> Andy Bach,
> afb...@gmail.com <mailto:afb...@gmail.com>
> 608 658-1890 cell
> 608 261-5738 wk

Reply via email to