Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Should I worry about "Inappropriate ioctl for device"?

by Lady_Aleena (Priest)
on Aug 09, 2020 at 00:33 UTC ( [id://11120508]=note: print w/replies, xml ) Need Help??


in reply to Should I worry about "Inappropriate ioctl for device"?

Now I am confused a bit. The $! in the following, when it died, did not tell me that I was using ioctl inappropriately. The reason I am confused is that the lines of code in my OP were inside-out conditionals (don't remember where I got that term), but the code below is just a conditional too.

sub four_digit_year { my $year = shift; if ($year !~ /\d{4}/) { die "Sorry, please use the four digit year. Stopped $!"; } return $year; }

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^2: Should I worry about "Inappropriate ioctl for device"? (updated)
by AnomalousMonk (Archbishop) on Aug 09, 2020 at 01:15 UTC

    Nothing in the code you show does anything that would give $! a meaningful value. The value $! actually has at the moment the code shown is executed was either set in some previous operation that gave $! a meaningful value (update: see this), or else it's the value $! happened to have at program startup (update: see this), i.e., random. Either way, its value is meaningless.

    Update: Consider this code:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $year = 987; $! = 0; if ($year !~ /\d{4}/) { die qq{Idiot!, use 4 digit year. Stopped '$!' +} } " Idiot!, use 4 digit year. Stopped '' at -e line 1.
    Now try assigning different values (1, 2, 3, ...) to $! and see what messages you get. The messages you're seeing in your posted code are just cruft.


    Give a man a fish:  <%-{-{-{-<

      I forgot to mention, I already took $! out of that code. I am still a little confused by why I would get a message about inappropriate use of ioctl in one script but not another.

      Also, I just checked the rest of my code and removed all the other inappropriate uses of ioctl that I could find. All those that are left are with opens.

      My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

      No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
      Lady Aleena

        Most likely, errno (the system C variable behind the $! magic) was used uninitialized in both cases. The C runtime library never clears errno and only sets errno to report an error. If no such error has occurred since the program started, the value of errno is undefined, which (in C) means unspecified — it is still an integer, as there is no undef value in C. (NULL pointers are a related but slightly different concept — if you could dereference a NULL pointer, you would logically get undef. In reality, you get SIGSEGV if you dereference a NULL pointer and your program crashes.)

        ... [why would I] get a message about inappropriate use of ioctl in one script but not another.

        Perhaps because $! is being used inappropriately in one script and not in the other. Beyond that, I must confess that I'm confused about the current state of your code and can say no more.


        Give a man a fish:  <%-{-{-{-<

Re^2: Should I worry about "Inappropriate ioctl for device"?
by AnomalousMonk (Archbishop) on Aug 10, 2020 at 15:04 UTC
    ... inside-out conditionals ...

    NB: I'm guessing this refers to a statement modifier, but "inside-out conditional" is a good description too!


    Give a man a fish:  <%-{-{-{-<

      Found it! Perl Optimization Tidbits by Daina Petit at 27:03 mark. The link is to that spot in the video.

      My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

      No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
      Lady Aleena

      I've been trying to remember where I got that term, and I think I got it from a talk by Daina Petit on YouTube where he used it to refer to an inside-out for.

      My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

      No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
      Lady Aleena
Re^2: Should I worry about "Inappropriate ioctl for device"?
by karlgoethebier (Abbot) on Aug 10, 2020 at 12:09 UTC

    You may read this by brian_d_foy. $ERRNO is not what you want.

    One option might be to rewrite you code like this:

    sub four_digit_year { my $year = shift; if ( $year !~ /\d{4}/ ) { return; # undef } return $year; }

    Then check if the result of your sub call is defined and die with some custom error message if not.

    And probably you may find a more robust recipe on PM how to test if some date is valid.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found