Bad coding style is a little vague..
You could be meaning syntax- which is more about formatting- or maybe symbol names (variable names, etc) - or your lack of use strict, or your use of foreach instead of for.. etc etc.
Here's how I would naturally code this, myself..
my @a = qw/1 2 3 # 6 7 # 9 10/; for my $val ( @a ){ $val eq '#' ? do_something() : $val eq '1' ? do_where_var_is_1() : do_something_else(); }
Why am I naming a variable $val instead of simply using $_ ? Because it's more intuitive when I look at it- to mean that I am checking that value, if I were using the value, I may name it $arg.
Why use a for instead of foreach? I use foreach with hashes, for with arrays, something personal.
Why use the ternary operator instead of if and else? For brevity and because it rocks.
Why do I use eq for both 1 and # ? Because it makes the code make more sense for human eyes. ( Besides you don't need to differentiate between numbers and strings here- they are all strings, right? That is, it appears the sample data you may have is by default all string- and it may be a character number or something else. You can't have all numbers and one character and still have all numbers, but you can have all c... anyways.. )
That's what *I* would do naturally. But everyone has a style. What's important is that is work, and it's also important that another coder can look at it and easily tell what you are doing.
In reply to Re: Is this bad coding style?
by leocharre
in thread Is this bad coding style?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |