Re: inverting List::Compare
- From: jrefior@xxxxxxxxx (John Refior)
- Date: Sun, 4 Jan 2009 19:07:35 -0500
# get files
open(DAT, $lfile) or die("unable to open");
my @Llist = <DAT>;
close(DAT);
You should include the $! variable in the die string so that you know why the
open failed. I suggest
my @llist;
{
open my $fh, '<', $lfile or die "Unable to open '$lfile': $!";
@llist = <$fh>;
}
Am I right in thinking that the braces here perform two functions:
1) Limit the scope of $fh. As far as I can tell from the
documentation ( http://perldoc.perl.org/functions/close.html ), the
block should also contain an additional line expressly closing the
file handle. Like:
close $fh or die "Unable to close $lfile: $!\n";
If you want to automatically close filehandles as they go out of
scope, it looks like IO::File can do that (see
http://perldoc.perl.org/functions/open.html at the end of the page).
2) Improve readability - the purpose of these lines is to get values
into the array @llist, let's make it look that way.
Do I have that right?
Thanks,
John
--
sub japh{$_=$_[0];s/[$:]/$"/gs;chop;print $&
while/(.)/g;}print chr q:44:,$/ unless &japh
(qq=Just$/another$/Perl$/hacker$/=) && print
"Gosh, that JAPH you wrote just crashed!\n";
John Refior
jrefior@xxxxxxxxx
.
- Follow-Ups:
- Re: inverting List::Compare
- From: "John W. Krahn"
- Re: inverting List::Compare
- References:
- inverting List::Compare
- From: David Newman
- Re: inverting List::Compare
- From: Rob Dixon
- inverting List::Compare
- Prev by Date: Re: Was re: inverting List::Compare
- Next by Date: Re: Was re: inverting List::Compare
- Previous by thread: Re: Was re: inverting List::Compare
- Next by thread: Re: inverting List::Compare
- Index(es):