Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: perl not going to error path

by Anonymous Monk
on Jan 23, 2016 at 18:05 UTC ( #1153475=note: print w/replies, xml ) Need Help??


in reply to perl not going to error path

Non-numeric strings evaluate as zero when used in arithmetic.

$ perl -lwe 'use strict; print int "NANNY"; print int "non-numeric";'
Argument "NANNY" isn't numeric in int at -e line 1.
nan
Argument "non-numeric" isn't numeric in int at -e line 1.
0
That is to say: perl did not error out in seek() because the seek to zero offset was successful.

What is the reason for passing non-numeric offset? You will have to check the passed value yourself, or, better yet, fix the program logic to not pass a string where a number is expected!

Replies are listed 'Best First'.
Re^2: perl not going to error path
by gupr1980 (Acolyte) on Jan 23, 2016 at 18:17 UTC

    Oh my, i thought putting the quote around the file handle works but it does not. even when i send a numeric offset putting a quote around file handle goes to die. I guess i should not put quote around file handle. So i should check to make sure that the value is numeric before passing it to seek.

    hopefully there is a way to check and die if it is non numeric with a non zero exit code. I will look around. thanks

      "So i should check to make sure that the value is numeric before passing it to seek"

      You can, yes. Doing it this way will allow you to handle the error yourself:

      my $offset = 'blah'; if ($offset =~ /^[0-9]+$/){ seek $fh, $offset, 0; } else { die "offset needs to be numeric"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-05-21 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?