develooper Front page | perl.perl5.porters | Postings from June 2012

Fwd: [perl #113046] Code embeddable in argument to -i switch

Jeremy Madea
June 11, 2012 01:05
Fwd: [perl #113046] Code embeddable in argument to -i switch
Message ID:
Apologies for any duplicates. I think I hit the link to toggle the CC
of p5p on the RT web interface. (Aside: Is that link really all that

On Fri Jun 08 18:03:22 2012, sprout wrote:
> On Thu Jun 07 03:38:16 2012, jmadea wrote:
> > I don't have such a system though.
> Does anyone know which system that is?  Is it possible to probe for it
> at configure time?

Eric Brine <> suggested this was a possibility in a
thread on p5p, though he himself posed it as a question.

> > If there is no test for that case,
> > one should be added, of course.
> Could you write tests for the cases that your patch changes?

My initial report was poorly worded as I was still partially focused on
a wider (unresolved) issue. Let me clearly state what my patch does
before answering your question.

While looking at the behavior reported by EvanCarroll, I found -i
working differently than other switches. Specifically, after exactly one
space in its argument, a following letter (w/o a dash) would be
interpreted as a switch.

The following emit warnings:
perl -i'foo e warn 1'
perl -i' e warn 1'

With two spaces after the argument, these do not emit warnings:
perl -i'foo  e warn 1'
perl -i'  e warn 1'

I quickly found that there were other switches that behaved similarly to
-i wrt to putting further switches in their arguments; -F and -C are
examples. But I did not find another that would interpret a letter
without a dash as a switch.

For instance, while these do emit warnings:
perl -F'foo -e warn 1'
perl -F' -e warn 1'
perl -C'1 -e warn 1'
perl -C' -e warn 1'

The following do not:
perl -F'foo e warn 1'
perl -F' warn 1'
perl -C'1 e warn 1'
perl -C' e warn 1'

My patch changes -i to work as other switches (like -F and -C) do.

In other words, after the patch, the following no longer emit warnings:
perl -i' e warn 1'
perl -i'foo e warn 1'

You asked if I can add a test case for it. I suppose I could. But do you
really want to test that perl is *not* doing something that it
*shouldn't*? If so, it seems like there might be an awful lot of test
cases to add. :-) I don't imagine it's very likely someone will add this
behavior to -i again by accident. So long as this patch doesn't cause
any regressions, I would think that should be sufficient.


Jeremy Madea Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About