title: What's the best way to tell if your perl's running on -e?
body: <p>The question is not how to tell in a oneliner. If you're writing the code in a one-liner, <em>you know</em> you are. But how does a module, included by <code>-MMy::Module::Name</code> know that it all started from a oneliner. </p>
  
  <p>This is mine. It's non-portable though and relies on UNIX standard commands (although, it can be made portable more or less.)</p>
  
  <pre><code>my $process_info = `ps $$ | tail -1`;
  my $is_oneliner  
      = $process_info =~ m/perl.*?\s+-[^\P{IsLower}e]*e[^\P{IsLower}e]*\s+/m
      ;
  </code></pre>
  
  <p>And if you have a snazzier regex, feel free to improve upon mine. </p>
  
  <hr>
  
  <p>A couple of people have asked why I would want to do this. brian correctly guessed that I wanted to change export behavior based on whether it's a script, which we can assume has had some amount of design, or whether it's a oneliner where the user is trying to do as much as possible in a single command line. </p>
  
  <p>This sounds bad, because there's this credo that exporters should respect other packages--sometimes known as "<code>@EXPORT</code> is <em>EVIL</em>!" But it seems to me that it's a foolish consistency when applied to oneliners. After all perl itself goes out of it's way to violate the structure of its language and give you easy loops if you ask for them on the command line, I simply want to extend that idea for my operational/business domain. I even want to apply source filters (<em>gasp!</em>) if it helps. </p>
  
  <p>But this question also suggests that I might want to be a good citizen of Perl as well, because I only to break the community guidelines in certain cases. It is quite awesome to be able to create major business-level actions just by changing the command line in a batch scheduler rather than writing a whole new module. The test cycle is much compressed. </p>