in reply to Best way to "Skip" a set of operations

G'day thnksnw,

You can do what you want using a label. Here's an example:

#!/usr/bin/env perl use strict; use warnings; for (qw{1 two -3 3.4 zero 0}) { print "$_ is ", get_num_type($_), "\n"; } sub get_num_type { my ($num) = @_; my $num_type; NUM_TYPE_TEST: { if ($num !~ /^-?\d+$/) { $num_type = 'non-integer'; last NUM_TYPE_TEST; } if ($num < 0) { $num_type = 'negative'; last NUM_TYPE_TEST; } if ($num == 0) { $num_type = 'zero'; last NUM_TYPE_TEST; } if ($num > 0) { $num_type = 'positive'; last NUM_TYPE_TEST; } } return $num_type; }

Output:

1 is positive two is non-integer -3 is negative 3.4 is non-integer zero is non-integer 0 is zero

Do note that this may not be the best course of action in your case; however, as you just posted a swathe of code out of context, I'm in no position to tell. I do see that you're splitting $input_line on a comma: if you're working with CSV files, consider using Text::CSV (which will run faster if you have Text::CSV_XS installed).

— Ken