perl

Writing to existing file and changing permissions

老子叫甜甜 提交于 2021-01-28 14:10:08
问题 I am trying to write to an existing file and at the same time change its permissions. For example: use warnings; use strict; use File::Slurp 'write_file'; my $script="#! /bin/bash echo \"Hello\" "; my $saveName='test.sh'; unlink $saveName if -f $saveName; writeFile($saveName,$script,0755); writeFile($saveName,$script,0775); sub writeFile { my ($saveName,$script,$mode) = @_; printf "Writing file with permissions %04o\n", $mode & 07777; write_file($saveName,{perms=>$mode},\$script); my

xargs pass multiple arguments to perl subroutine?

醉酒当歌 提交于 2021-01-28 13:55:06
问题 I know how to pipe multiple arguments with xargs: echo a b | xargs -l bash -c '1:$0 2:$1' and I know how to pass the array of arguments to my perl module's subroutine from xargs: echo a b | xargs --replace={} perl -I/home/me/module.pm -Mme -e 'me::someSub("{}")' But I can't seem to get multiple individual arguments passed to perl using those dollar references (to satisfy the me::someSub signature): echo a b | xargs -l perl -e 'print("$0 $1")' Just prints: -e So how do I get the shell

How to run this simple Perl CGI script on Mac from terminal?

安稳与你 提交于 2021-01-28 13:36:02
问题 This simple .pl script is supposed to grab all of the images in a directory and output an HTML — that when opened in a browser — displays all of the images in that dir at their natural dimensions. From the mac command line, I want to just say perl myscript.pl and have it run. … It used to run on apache in /cgi-bin . #!/usr/bin/perl -wT # myscript.pl use strict; use CGI; use Image::Size; my $q = new CGI; my $imageDir = "./"; my @images; opendir DIR, "$imageDir" or die "Can't open $imageDir $!"

Remove duplicate line only contain specific string

只谈情不闲聊 提交于 2021-01-28 12:10:57
问题 I try to remove duplicates lines only if contain a specific string. It's easy to remove only duplicates lines, but some useful lines is deleted with : awk '!seen[$0]++' or perl -ne 'print unless $seen{$_}++' Exemple : keep first occurence of lines containing "host_name=" keep all occurrences of lines containing "plugin output=" with above awk or Perl commands that delete the client number too. My output command : host_name=Client1 plugin_output=Name : Client1 Marseille host_name=Client1

how to install perl XML::XPath on Windows?

感情迁移 提交于 2021-01-28 12:10:51
问题 Been running in Google'ish circles trying to install XML::XPath on windows. Windows 10, Perl 5.4 (where perl = /usr/bin/perl). I am running Strawberry perl. "cpan install XML::XPath" fails, > cpan install XML::XPath Can't find E:\Plang\Strawberry_Perl\perl\bin\cpan.bat on PATH, '.' not in PATH. Manual download of xml-xpath-1.44, then unpacking, and run makefile, fails: perl Makefile.PL Expat must be installed prior to building XML::Parser and I can't find it in the standard library

Cannot install DBD::mysql on Mac

扶醉桌前 提交于 2021-01-28 10:51:54
问题 (It's my first time posting here, so the format might not be right, sorry.) I have been trying to install DBD::mysql on my macOS Catalina using cpan, but I have not succeeded yet. I used perlbrew, and tried mysql and mariaDB, but still no luck. Also, I've looked into different solutions online (Probably messed up a bit as well), but no luck as well, so I want to see if anyone can help. Thanks! The log is as below: cpanm (App::cpanminus) 1.7044 on perl 5.030002 built for darwin-2level Work

How does diamond operator work with array as argument

这一生的挚爱 提交于 2021-01-28 10:30:56
问题 I have got an array @address whose zero element contains some strings. I can not find an example diamond operator works with @array as argument. (how it 'split' strings?) use Mojo::Loader qw/ data_section /; my @address = data_section 'main', 'address_strings'; while( my $line = <@address> ) { print $line; } 1; __DATA__ @@ address_strings "010101, УУУ обл., м. Тернопіль, вул. ВВВ, буд. 0101, 01" "020202, ЛЛЛ обл., ААА район, село ФФФ, ВУЛИЦЯ ШШШ, будинок 01" "030303, м.ЮЮЮ, ЮЮЮ р-н, вул. ЛЛЛ,

Taking strnig as input for calculator program in Perl

大憨熊 提交于 2021-01-28 10:20:52
问题 I am new to Perl and I'm trying to create a simple calculator program, but the rules are different from normal maths. All operations have the same power and the math problem must be solved from left to right. Here is an example: 123 - 10 + 4 * 10 = ((123 - 10) + 4) * 10 = 1170 8 * 7 / 3 + 2 = ((8 * 7) / 3) + 2 = 20.666 So in the first case the user needs to enter one string: 123 - 10 + 4 * 10. How do i approach this task? I'm sorry if it's too much of a general question, but i'm not sure how

How to automatically change the format or encode the excel cell value while writing it to CSV file

北城余情 提交于 2021-01-28 09:01:31
问题 My script is breaking when excel cell has double quotes in their value and quotes. I had to explicitly write a function to handle commas in OUTFILE. Is there any way I can provide cell value and automatically it can be encoded to CSV format. example- cell->value - Student GOT 8 MARKS in math, 7 in Spanish Desired Correct CSV format-> "Student GOT 8 MARKS in math, 7 in Spanish". cell->value - Student GOT 8 MARKS in "math", 7 in "Spanish" Desired Correct CSV format-> "Student GOT 8 MARKS in "

Why is incorrect value of pi output?

点点圈 提交于 2021-01-28 07:50:29
问题 I'm trying to calculate pi using following code that uses Chudnovsky algorithm. When $n is increased, then number of digits after the decimal point. However when $n is small, it can calculate correct value of pi (3.141592...) is output, but when $n is increased, it calculate incorrect value of pi. Why? #!/usr/bin/perl use strict; use warnings; use GMP qw(:all); use GMP::Mpf qw(:all); use GMP::Mpz qw(:all); use GMP::Mpq qw(:all); my $n = shift; $n = $n<7?7:$n; $n *= 8; my $l = int($n/7) + 1;