in reply to Input validation

Just wonder if this is going to be robust enough ?
Depends on what you need it for. (Oh, and you forgot to escape the | in your code: it should be m"\|").

If you just need to check for the presence of A separator, your code (as ammended) would be sufficient.

However, you might want to check other things, such as the number of fields you get after the split, if the fields contain the data you expected (you do have a plan on how to handle empty fields, don't you?) etc.

Replies are listed 'Best First'.
Re: Re: Input validation
by pacman (Initiate) on Mar 23, 2004 at 09:01 UTC
    hi thanks Matija,Castaway & CountZero ..

    The line should comprise the said number of fields(in
    the eg case - 4).So what I am also checking for,is the
    number of fields returned on the 'split' & yeah I am
    taking care of the possibility of receiving an empty
    $line and/or empty field/fields. I think the two checks
    1.Fields returned & 2. delimiter presence should be good
    enough method to determine if the $line is fine,right?

      Sounds like you are concerned that you may have bad data, and asking us how bad it could be, which of course we have no way of telling.

      If you want to check that split returns the number of fields you expect, just check it:

      my @split_line = split(m"\|",$line); if (@split_line != 4) { warn "something gang aft"; } else { print "valid data!"; }