Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Most Perl programmers think "it" when they use or see $_

Examples of using "it":

  map { (1/$_)+1 } 1..100;

  grep { $_ eq 'something' } @list;
You can also replicate the if and big_long_calculation using "for":

  for (big_long_calculation) {
      $_->foo;
  }
But if u prefer to stick with "if" then you can do:

  if (my $it = big_long_calculation) {
      $it->foo;
  }
And remember in a lot of cases using "it" isn't mandatory:

  say for @list;
is same as:

  say $_ for @list;


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: