perl

Is the difference between these two evals explained with constant folding?

家住魔仙堡 提交于 2021-02-09 11:09:33
问题 Given these two evals which only change Module::FOO() and FOO() . # Symbols imported, and used locally. eval qq[ package Foo$num; Module->import(); my \$result = Module::FOO() * Module::FOO(); ] or die $@; # Symbols imported, not used locally referencing parent symbol. eval qq[ package Foo$num; Module->import(); my \$result = FOO() * FOO(); ] or die $@; why would the top block take up substantially less space? The script and output are reproduced below, Script package Module { use v5.30; use

perl xs module writing - Use another function from within same xs file

烂漫一生 提交于 2021-02-09 11:00:40
问题 I'm a beginner in XS and have spent some time looking for this answer on the web with no luck. The problem is that XS changes the name of the function and when it goes to compile, I will get an undefined reference error. For example consider the XS code below: size_t matrixIndex (colIndex, rowIndex,nCols,nRows) size_t colIndex size_t rowIndex size_t nCols size_t nRows CODE: size_t register i; RETVAL = (rowIndex * nCols) + colIndex; OUTPUT: RETVAL I then try to use this in the following

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

*爱你&永不变心* 提交于 2021-02-09 08:11:00
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

送分小仙女□ 提交于 2021-02-09 08:08:13
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

半腔热情 提交于 2021-02-09 08:06:59
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Syntax error in hashref lookup, can not see why

你离开我真会死。 提交于 2021-02-09 07:25:58
问题 perl -E 'say for map s/(æ|ø|å)/ {qw(æ ae ø oe å aa)}->{$1}/ger, qw(rød gul blå)' perl -E 'say for map s/(æ|ø|å)/"".{qw(æ ae ø oe å aa)}->{$1}/ger, qw(rød gul blå)' The first line above gives me syntax error at -e line 1, near "}->" but the second prints roed , gul and blaa as expected. Is this a weakness of the compiler or are there some reason for it that I can't see? I tested and got this behaviour in versions 5.10, 5.22 and 5.26. 回答1: The {...} are interpreted as a BLOCK, not a hashref. We

Why is inotify losing events?

孤街浪徒 提交于 2021-02-08 21:19:21
问题 I need to process large (~100s) of syslog messages using Perl and Linux::Inotify2. I wrote a test script which generates log messages continuously. To process events, my Perl script looks like this- #!/usr/bin/perl use Linux::Inotify2 ; use Time::HiRes qw(usleep nanosleep); # create a new object my $inotify = new Linux::Inotify2 or die "Unable to create new inotify object: $!" ; # create watch $inotify->watch ("/var/log/messages", IN_ACCESS|IN_OPEN|IN_CLOSE|IN_MODIFY|IN_Q_OVERFLOW) or die

Perl: How to “die” with no error message?

谁说我不能喝 提交于 2021-02-08 19:54:32
问题 I run a simple file test in perl with the code below: my $f1 = "$pre_file"; unless (-e $1) { print "\n Pre_check file does not exists! \n"; die; } It prints the following output: Pre_check file does not exists! Died at ./huawei-postcheck line 81. However I do not want the last line "Died at ./huawei-postcheck line 81.". I want to to "die" with no error message. Is it possible? 回答1: You could just say die "\n"; to suppress the message. 回答2: See the documentation for die. If the last element of

Perl: How to “die” with no error message?

梦想与她 提交于 2021-02-08 19:53:12
问题 I run a simple file test in perl with the code below: my $f1 = "$pre_file"; unless (-e $1) { print "\n Pre_check file does not exists! \n"; die; } It prints the following output: Pre_check file does not exists! Died at ./huawei-postcheck line 81. However I do not want the last line "Died at ./huawei-postcheck line 81.". I want to to "die" with no error message. Is it possible? 回答1: You could just say die "\n"; to suppress the message. 回答2: See the documentation for die. If the last element of

Why is my Perl in-place script exiting with a zero exit code even though it's failing?

こ雲淡風輕ζ 提交于 2021-02-08 15:19:20
问题 I have a one-liner Perl search and replace that looks roughly like this: perl -p -i -e 's/foo/bar/' non-existent-file.txt Because the file doesn't exist (which isn't intentional, but this is part of an automated build script, so I want to protect against that), Perl exits with this error: Can't open non-existent-file.txt: No such file or directory. However, the exit code is still zero: echo $? 0 Am I doing something wrong? Should I be modifying my script, or the way I'm invoking Perl? I was