Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:14:45+00:00 2026-05-28T19:14:45+00:00

Is there a good reason for map to not read from @_ (in functions)

  • 0

Is there a good reason for map to not read from @_ (in functions) or @ARGV (anywhere else) when not given an argument list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:14:45+00:00Added an answer on May 28, 2026 at 7:14 pm

    I can’t say why Larry didn’t make map, grep and the other list functions operate on @_ like pop and shift do, but I can tell you why I wouldn’t. Default variables used to be in vogue, but Perl programmers have discovered that most of the “default” behaviors cause more problems than they solve. I doubt they would make it into the language today.

    The first problem is remembering what a function does when passed no arguments. Does it act on a hidden variable? Which one? You just have to know by rote, and that makes it a lot more work to learn, read and write the language. You’re probably going to get it wrong and that means bugs. This could be mitigated by Perl being consistent about it (ie. ALL functions which take lists operate on @_ and ALL functions which take scalars operate on $_) but there’s more problems.

    The second problem is the behavior changes based on context. Take some code outside of a subroutine, or put it into a subroutine, and suddenly it works differently. That makes refactoring harder. If you made it work on just @_ or just @ARGV then this problem goes away.

    Third is default variables have a tendency to be quietly modified as well as read. $_ is dangerous for this reason, you never know when something is going to overwrite it. If the use of @_ as the default list variable were adopted, this behavior would likely leak in.

    Fourth, it would probably lead to complicated syntax problems. I’d imagine this was one of the original reasons keeping it from being added to the language, back when $_ was in vogue.

    Fifth, @ARGV as a default makes some sense when you’re writing scripts that primarily work with @ARGV… but it doesn’t make any sense when working on a library. Perl programmers have shifted from writing quick scripts to writing libraries.

    Sixth, using $_ as default is a way of chaining together scalar operations without having to write the variable over and over again. This might have been mitigated if Perl was more consistent about its return values, and if regexes didn’t have special syntax, but there you have it. Lists can already be chained, map { ... } sort { ... } grep /.../, @foo, so that use case is handled by a more efficient mechanism.

    Finally, it’s of very limited use. It’s very rare that you want to pass @_ to map and grep. The problems with hidden defaults are far greater than avoiding typing two characters. This space savings might have slightly more sense when Perl was primarily for quick and dirty work, but it makes no sense when writing anything beyond a few pages of code.

    PS shift defaulting to @_ has found a niche in my $self = shift, but I find this only shines because Perl’s argument handling is so poor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good reason? Are their internal functions (not exported) also stdcall convention?
If so, can the image be animated? Is there a good reason not to
Is there ever a good reason to not declare a virtual destructor for a
I was wondering if there is a good reason for ScriptReference not to override
Is there a good reason why the type of Prelude.read is read :: Read
Is there a good reason not to set the PHP configuration variable max_execution_time to
Is there a good reason to manually remove event listeners from object's events if
is there any good reason not to use XML-RPC for an object-broker server/client architecture?
Is there a good reason why there is no Pair<L,R> in Java? What would
Is there a good reason (advantage) for programming this style XmlDocument doc = null;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.