perl

How to check and delete a symlink if it exists, using Perl?

我们两清 提交于 2021-02-07 06:12:50
问题 if (-e "$ENV{MYHOME}/link") { system("rm $ENV{MYHOME}/link"); } This is the code being used to check if a symlink exists and remove it if it does. I am tracking a bug where this code does not work. I have not been able to figure it out as of now, but what is happening is that this code is unable to remove the symlink, which results in a 'File exists' error down the line. I wanted to check if there is some fundamental flaw with this technique? I also read about http://perldoc.perl.org

How can I send mail through Gmail with Perl?

折月煮酒 提交于 2021-02-06 23:56:13
问题 How can I send email using Perl through my Gmail account? The one CPAN library (Mail::Webmail::Gmail) that I tried didn't work and I don't see much activity with it. At the moment I really only need to send a message. However, the advanced functionality of getting my contacts, acting when a new email is received that has a certain label, etc. certainly seems appealing for another day. 回答1: Did you try Email::Send::Gmail? 回答2: You could always send with SMTP. The server is smtp.gmail.com, it

How can I send mail through Gmail with Perl?

倖福魔咒の 提交于 2021-02-06 23:56:08
问题 How can I send email using Perl through my Gmail account? The one CPAN library (Mail::Webmail::Gmail) that I tried didn't work and I don't see much activity with it. At the moment I really only need to send a message. However, the advanced functionality of getting my contacts, acting when a new email is received that has a certain label, etc. certainly seems appealing for another day. 回答1: Did you try Email::Send::Gmail? 回答2: You could always send with SMTP. The server is smtp.gmail.com, it

Cannot run cgi, show plain text only (Ubuntu 13.10 Apache 2.4)

那年仲夏 提交于 2021-02-06 10:06:58
问题 I just install Ubuntu 13.10 and I am trying to install Apache. But when I tried to run a perl file in cgi-bin, the browser showed only plain text. My default.conf of Apache is below: AddHandler cgi-script .cgi .pl ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +Indexes +ExecCGI +MultiViews +SymLinksIfOwnerMatch #Order allow,deny Require all granted Allow from all </Directory> This is my perl cgi file: #!/usr/bin/perl print "Content-type: text

How to insert the whole matched text in the replacement in Perl?

回眸只為那壹抹淺笑 提交于 2021-02-05 12:20:48
问题 I want to add a string ( A ) after all specific other strings ( bbc ). So, I match bbc and want to replace it with itself with A appended ( 'aabbcc' => 'aabbcAc' ). Is there a replacement back-reference that gets substituted with the whole match? $0 doesn't seem to work – its content is always "-e", for some reason: $ echo 'aabbcc' | perl -p -e 's/bbc/$0A/g' aa-eAc 回答1: Use $& , see http://perldoc.perl.org/perlvar.html echo 'aabbcc' | perl -p -e 's/bbc/$&A/g' aabbcAc 来源: https://stackoverflow

How to insert the whole matched text in the replacement in Perl?

牧云@^-^@ 提交于 2021-02-05 12:20:03
问题 I want to add a string ( A ) after all specific other strings ( bbc ). So, I match bbc and want to replace it with itself with A appended ( 'aabbcc' => 'aabbcAc' ). Is there a replacement back-reference that gets substituted with the whole match? $0 doesn't seem to work – its content is always "-e", for some reason: $ echo 'aabbcc' | perl -p -e 's/bbc/$0A/g' aa-eAc 回答1: Use $& , see http://perldoc.perl.org/perlvar.html echo 'aabbcc' | perl -p -e 's/bbc/$&A/g' aabbcAc 来源: https://stackoverflow

Perl Named Captured Group

限于喜欢 提交于 2021-02-05 11:41:33
问题 I have created two named capture variables in the regex and the second one doesn't seem to return any value while the first one can. I am not sure why..here is the code. my $string = 'test [google] another test [windows]'; my $regex=qr/\w*\[{1}(?<firstBracket>\w+)\]{1}(?<secondBracket>\w*)/ip; $string=~ /$regex/; say $+{secondBracket}; I am expecting that "secondBracket" will return. I can do $+{firstBracket} , but not the second one...Can someone help please? Thanks. 回答1: You probably mean:

Perl Named Captured Group

一笑奈何 提交于 2021-02-05 11:41:06
问题 I have created two named capture variables in the regex and the second one doesn't seem to return any value while the first one can. I am not sure why..here is the code. my $string = 'test [google] another test [windows]'; my $regex=qr/\w*\[{1}(?<firstBracket>\w+)\]{1}(?<secondBracket>\w*)/ip; $string=~ /$regex/; say $+{secondBracket}; I am expecting that "secondBracket" will return. I can do $+{firstBracket} , but not the second one...Can someone help please? Thanks. 回答1: You probably mean:

Why am I having “Missing argument in printf at …” in perl?

蹲街弑〆低调 提交于 2021-02-05 11:23:06
问题 I have perl code where am printing to file. I give the format my $format = "%4d %2d %2d %2d %2d %2d" . " %7.2f" x 9 . "\n"; because I am writing year month day hour minute second and 9 float values. Then I write to my output file as printf $format, @data; # print data on the screen printf OUT $format, @data; # print data into the file Both of the above statements print, but always with a warning of "Missing argument in printf at (line number)". What is the correct way of writing the formt and

split one line regex in a multiline regexp in perl

浪尽此生 提交于 2021-02-05 09:43:25
问题 I have trouble spliting my regex in multiple line. I want my regex to match the line given: * Code "l;k""dfsakd;.*[])_lkaDald" So I created this regex which work: my $firstRegexpr = qr/^\s*\*\s*Code\s+\"(?<Code>((\")*[^\"]+)+)\"/x; But now I want to split it in multiline like this(and want it to match the same thing!): my $firstRegexpr = qr/^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\"/x; I read about this, but I have trouble using it: / ^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\" /x My last