Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Split function

by bart (Canon)
on Dec 03, 2012 at 13:10 UTC ( #1006872=note: print w/replies, xml ) Need Help??


in reply to Split function

If you can't have it die, you can make it do that if split splits into only one part.
(my ($s, $a, $c, $r) = split /[,\t]/) == 1 and die;
or, alternatively, you can do
die if not defined $a;
edit code fixed, thanks ColonelPanic

Replies are listed 'Best First'.
Re^2: Split function
by ColonelPanic (Friar) on Dec 03, 2012 at 13:42 UTC

    If you are going to do error checking, why not do it properly? Check that all fields are present:

    (my ($s, $a, $c, $r) = split /[,\t]/) < 4 and die;
    or:
    die if not defined $r;

    (Also, you had a typo in your code: extra paren)



    When's the last time you used duct tape on a duct? --Larry Wall

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006872]
help
Chatterbox?
[Dumu]: hello again jedikaiti! thanks everyone today for being in the monastery!
[Dumu]: and incidentally, in case you're dying to know, it's multiple web browser bookmark format files...
[ambrus]: Seeking afterwards might also work fine, I think.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-11-20 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?