Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat regex with a string in a constant declaration as oneliner

Tags:

string

regex

perl

I am trying to declare a constant as an one liner like this:

use constant HOME_SCRIPT => "/home/george/". $0 =~ /(.*)\.pl/;
The problem is that this returns: /home/george/1. I.e. it concats the number of matches of regex.
I tried:
use constant HOME_SCRIPT => ("/home/george/"). $0 =~ /(.*)\.pl/;
use constant HOME_SCRIPT => "/home/george/". ($0 =~ /(.*)\.pl/);
but same result.
Is it possible to create an oneliner for this?

like image 798
Cratylus Avatar asked Jan 25 '26 18:01

Cratylus


1 Answers

use constant HOME_SCRIPT => "/home/george/". ($0 =~ /(.*)\.pl/)[0];

or

use constant HOME_SCRIPT => join "", "/home/george/", $0 =~ /(.*)\.pl/;
like image 100
mpapec Avatar answered Jan 27 '26 19:01

mpapec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!