XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
For me, the critical thing to realize about a statement like which is passed an array by the reference $list is also operating on the referent of $list! Consider: (Update: Also, the statement my @another_array = map { chomp($_); $_; } @original_array; is equivalent to the statements my @another_array = @original_array; chomp @another_array; chomp @original_array; because $_ is aliased to the elements of @original_array. In the case of a statement like my @list = map { chomp($_); $_ } <$fh>; this doesn't matter: the <$fh> expression creates a temporary list that is fed to map and then vanishes. But in other cases... See also ikegami's reply.) Any time I see code structured in this way, my buggy-sense starts to tingle. If you're happy with the operation of your code, that's fine with me; you can just ignore or (I think) turn off the specific critique. Just be aware that pitfalls lurk here. Update: Oops... In my haste to answer, I overlooked the latter questions of your post. ...why the expression form of eval is discouraged?String eval is looked upon askance because it is an open invitation to all kinds of mischief if your data is not absolutely trustworthy — and even then many programmers would avoid it, preferring alternatives that may be slightly more roundabout, but that are a whole bunch safer. my $var = "foo" if 'some condition';This inadvertantly allowed syntax leaves $var in an undefined state of existence. It used to be used to simulate a persistent, "static" variable within a function; state is used for this purpose now, and the old usage is officially Frowned Upon. Give a man a fish: <%-{-{-{-< In reply to Re: Perl::Critic says don't modify $_ in list functions and other things (updated x2)
by AnomalousMonk
|
|