Solved [Solved] problem with small perl script

Hello all,

Could someone tell me if they can spot my mistake in the bollow script?
Code:
#!/bin/sh
INIFILE="/usr/local/etc/php.ini"
perl -p -i -e '
s/.*memory_limit.*/memory_limit = 32M/;
s/.*upload_max_filesize.*/upload_max_filesize = 10M/;
s/.*post_max_size.*/post_max_size = 20M/;
' "$INIFILE"

PHPPFMFILE="/usr/local/etc/php-fpm.conf"
perl -p -i -e '
s/.*;events.mechanism.*/events.mechanism = kqueue/;
s/.*listen.*/listen = /var/run/php-fpm.sock/;
s/.*;listen.owner.*/listen.owner = www/;
s/.*;listen.group.*/listen.group = www/;
s/.*;listen.mode.*/listen.mode = 0666/;
' "$PHPPFMFILE"
This is the error message that I am getting:
Code:
Having no space between pattern and following word is deprecated at -e line 3.
Bareword found where operator expected at -e line 3, near "s/.*listen.*/listen = /var"
syntax error at -e line 3, near "s/.*listen.*/listen = /var"
Execution of -e aborted due to compilation errors.
Thank you in advance

Fred
 
Re: problem with small perl script

Code:
s/.*listen.*/listen = /var/run/php-fpm.sock/;

I suspect Perl is interpreting the / just before var as the end of the pattern. You'll probably need to escape the slashes in the path with backslashes. That or choose a different character to denote the start and end of the pattern/replacement.
 
Re: problem with small perl script

The '/' character would certainly have to be escaped in this context. So you would need a '\/' to get a literal slash. That gets ugly quickly though. Here's an example that I've used using '^' to break apart the substitution strings to avoid the need to escape a '/'. Perl isn't picky about what characters you use there.

Code:
perl -pwi -e 's^#ZPOOL=tank^ZPOOL=zfs^g' poudriere.conf
perl -pwi -e 's^_PROTO_://_CHANGE_THIS_^ftp://ftp.freebsd.org^g' poudriere.conf
perl -pwi -e 's^BASEFS=/usr/local/poudriere^BASEFS=/zfs/poudriere^g' poudriere.conf
 
Re: problem with small perl script

Strictly speaking this isn't a Perl script but a shell script that uses Perl ;)

And why the overkill of Perl? Why not use sed(1)? The only thing you seem to use is search and replace.

Instead of a / it's quite common to see |. Makes it somewhat readable too.

perl -pwi -e 's|#ZPOOL=tank|ZPOOL=zfs|g' poudriere.conf
 
Back
Top