Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: What technical benfits perl offers over python + few more questions.

by LanX (Saint)
on Nov 15, 2021 at 16:46 UTC ( [id://11138840]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What technical benfits perl offers over python + few more questions.
in thread What technical benfits perl offers over python + few more questions.

> Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

could you please elaborate what you mean?

DB<37> eval { 1/0 } or print "<$@>" <Illegal division by zero at (eval 46)[c:/Strawberry/perl/lib/perl5db. +pl:738] line 2. > DB<38>

edit

Probably you are talking about the kind of non-error "message" exceptions , e.g. thrown by iterators like in Python???

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^5: What technical benfits perl offers over python + few more questions.
by Fletch (Bishop) on Nov 15, 2021 at 17:36 UTC

    I think the distinction being made is maybe that in (say) Java trying to print on a closed filehandle object would throw an IOException which your code would be required to handle, whereas perl  -E 'close(STDOUT);say qq{FOOP}' will run (producing no output but also not printing any sort of error (although you could check the return from say and print $!)).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Of course if you "use warnings;", you will see the "print() on closed filehandle STDOUT" warning.
        > Of course if you "use warnings;", you will see the "print() on closed filehandle STDOUT" warning.

        and ...

        Of course you can propagate warnings to die by changing $SIG{__WARN__} ;-)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        I see what you mean. I am just starting with Python. Instead of handling the exception, it appears that:
        for value in some_iterable: print(value)
        is the preferred syntax.
Re^5: What technical benfits perl offers over python + few more questions.
by ikegami (Patriarch) on Nov 16, 2021 at 17:30 UTC

    ok, so you found an exception. Well, kinda. There's no IO library function that corresponds to division.

    Anyway, the point stands: Where other languages might use exception, Perl primarily returns false on error.

    Update: Clearer wording

      So you were only talking about IO and meant the lack of default to autodie?

      Wasn't obvious to me.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Of course you can create your own subs that throws exceptions, like autodie does. I don't know why you bring that up. I didn't talk about libraries at all except to say that Perl can throw exceptions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found