http://www.perlmonks.org?node_id=435357


in reply to Perl oddities

I think the filehandle functions are generally messy: Bareword file handles, indirect object syntax for print() and close(), open() modifies it's $fh argument, and my least favorite "feature": defaulting to ignoring errors, which just means you end up having to type open FH,"<","file" or die "Can't open file: $!"; every time you use open, print and close.

I would prefer something like this:

my $fh = open "<","filename"; $fh->print "stuff"; $fh->close;

Which would also make it easier to replace a filehandle with some other object.

Replies are listed 'Best First'.
Re^2: Perl oddities
by TimToady (Parson) on Mar 01, 2005 at 18:27 UTC
    Change your arrows to dots and that's almost exactly how it looks in Perl 6.
Re^2: Perl oddities
by Corion (Patriarch) on Mar 01, 2005 at 11:35 UTC

    See Fatal, which does exactly that, override open (or whatever else you want) to die if it fails. The scheme falls down for system, as system returns a false value on success ...

      Fatal will be a built-in pragma in Perl 6, and any code which uses the fail keyword will fail in the way specified by the caller, which might be to throw a fatal exception, or to return an unthrown exception that is behaves like undef, or to cause some form of backtracking, in the case of the pattern matching engine.

      I'll talk about system elsewhere.

        Don't consider - use it. It will make your life a whole lot simpler. I know it has mine :-)