in reply to Detecting a Null or Enter key

IMO, you need to use strictures, after which the test for empty input should be performed first ... and then go on to process the entered data e.g.
#!/usr/bin/perl use warnings; use strict; local ($bak_id)=shift; local ($acc_bal)=shift; $bak_id=<STDIN>; $acc_bal=<STDIN>; chomp ($bak_id); print "Returning to MM\n", exit 0 unless $bak_id; . . .
Even better, IMO, would be to use a hash-based dispatch table keyed on (what was previously) $bak_id expressed as a regex e.g.
#!/usr/bin/perl use warnings; use strict; my %dispatch = ( '' => sub { print "Returning" ; exit }, 'BOTH' => sub { my $acc_bal = shift; . if ($acc_bal < 1.0) { . . } else { . . } }, 'Cust1|Cust2' => sub { my $acc_bal = shift; . if ($acc_bal < 1.0) { . . } else { . . } }, ); my ($bak_id, $acc_bal); while (1) { chomp($acc_bal = <STDIN>); foreach my $re (keys %dispatch) { next unless $acc_bal =~ /^(?:$re)$/; &{ $dispatch{$_} }(chomp <STDIN>); } } . .
or some such.

Afterthought: I've only just realised that you don't allow a value of 0 - it's either less or grater than 0 ?

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Detecting a Null or Enter key
by ikegami (Patriarch) on Jan 11, 2009 at 18:12 UTC
    local ($bak_id)=shift; local ($acc_bal)=shift;

    won't pass strict. But that's good because it's inappropriate to use local here. The above should be replaced with

    my ($bak_id)=shift; my ($acc_bal)=shift;

    In both cases, the parens are useless.

    my $bak_id = shift; my $acc_bal = shift;

    Or you could combine them

    my ($bak_id, $acc_bal) = @ARGV;
      You may notice that the 1st suggestion utilised a snippet from the OP (tho' I take your point that it was remiss of me to insert the strictures) - my 2nd suggestion deliberately didn't repeat the errror.

      A user level that continues to overstate my experience :-))
        What I noticed is that you provided a solution that made things worse for the OP. I wasn't contradicting you; I was simply completing the work you started.