I'm trying to replace only the first occurrence of a pattern in a file using a perl one liner.
>touch tmp
>perl -p -i.bak -e '++$seen if( !$seen && s/alpha/beta/);' tmp
After this I press Enter. Below message appears on the screen.
perl -p -i.bak -e '++$seen if( tmpseen && s/alpha/beta/);' tmp
Note that !$seen got replaced with tmpseen.
Why is this happening?
Thanks.
!$is expanding to the last argument of the previous command. I'm assuming that.if( \!$seenwill work.