perl

How to do sum of hash reference slice?

ぃ、小莉子 提交于 2021-02-08 14:54:33
问题 I'm trying to get a sum of a hash reference slice, but I am failing #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use feature 'say'; use autodie ':all'; use List::Util 'sum'; my %h = ( 'a' => 1, 'b' => 2, 'c' => 3 ); my @letters = ('a','b'); say sum(@h{@letters}); # 1+2 = 3, which is correct my $h = \%h; # create a reference #say sum(@{ $h->{ @letters } }); # says "uninitialized value" #say sum(@{ $h }->{@letters}); # not an array reference say sum(@h->{@letters}); # @h

retrieve patterns that exactly match all regex in Perl

白昼怎懂夜的黑 提交于 2021-02-08 14:22:36
问题 I have a database of subgraphs that looks like this: t # 3-231, 1 v 0 94 v 1 14 v 2 16 v 3 17 u 0 1 2 u 0 2 2 u 0 3 2 t # 3-232, 1 v 0 14 v 1 94 v 2 19 v 3 91 u 0 1 2 u 0 3 2 u 1 2 2 t # 3-233, 1 v 0 17 v 1 91 v 2 16 v 3 94 u 0 1 2 u 0 3 2 u 1 2 2 t # 3-234, 1 v 0 90 v 1 93 v 2 102 v 3 95 u 0 1 2 u 0 3 2 u 1 2 2 I would like to retrieve all transactions that contains the following patterns: 'u 0 1 2' and 'u 0 2 2' along with transaction id (ex. line starts with t #). I used the following code

retrieve patterns that exactly match all regex in Perl

微笑、不失礼 提交于 2021-02-08 14:22:25
问题 I have a database of subgraphs that looks like this: t # 3-231, 1 v 0 94 v 1 14 v 2 16 v 3 17 u 0 1 2 u 0 2 2 u 0 3 2 t # 3-232, 1 v 0 14 v 1 94 v 2 19 v 3 91 u 0 1 2 u 0 3 2 u 1 2 2 t # 3-233, 1 v 0 17 v 1 91 v 2 16 v 3 94 u 0 1 2 u 0 3 2 u 1 2 2 t # 3-234, 1 v 0 90 v 1 93 v 2 102 v 3 95 u 0 1 2 u 0 3 2 u 1 2 2 I would like to retrieve all transactions that contains the following patterns: 'u 0 1 2' and 'u 0 2 2' along with transaction id (ex. line starts with t #). I used the following code

Perl comprehensive phone number regex [duplicate]

牧云@^-^@ 提交于 2021-02-08 12:12:43
问题 This question already has answers here : How to validate phone numbers using regex (42 answers) Closed 2 years ago . I have a file that contains phone numbers of the following formats: (xxx) xxx.xxxx (xxx).xxx.xxxx (xxx) xxx-xxxx (xxx)-xxx-xxxx xxx.xxx.xxxx xxx-xxx-xxxx xxx xxx-xxxx xxx xxx.xxxx I must parse the file for phone numbers of those and ONLY those formats, and output them to a separate file. I'm using perl, and so far I have what I think is a valid regex for two of these numbers my

Perl comprehensive phone number regex [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-08 12:11:19
问题 This question already has answers here : How to validate phone numbers using regex (42 answers) Closed 2 years ago . I have a file that contains phone numbers of the following formats: (xxx) xxx.xxxx (xxx).xxx.xxxx (xxx) xxx-xxxx (xxx)-xxx-xxxx xxx.xxx.xxxx xxx-xxx-xxxx xxx xxx-xxxx xxx xxx.xxxx I must parse the file for phone numbers of those and ONLY those formats, and output them to a separate file. I'm using perl, and so far I have what I think is a valid regex for two of these numbers my

How to Ctrl-Z in Perl script

ⅰ亾dé卋堺 提交于 2021-02-08 11:15:24
问题 I am writing a Perl script and I need to execute Unix Ctrl + Z on the script. How can I do it in Perl ? thanks. 回答1: From perl you can send signals to processes with the function kill, which has the same name as the Unix command line tool that does the same thing. The equivalent to Ctrl + Z is running kill -SIGTSTP pid you need to find out what numeric value your TSTP signal has on your system. You would do this by running kill -l TSTP on the command line. Let's say this returns 20 Then in

How to Ctrl-Z in Perl script

微笑、不失礼 提交于 2021-02-08 11:14:07
问题 I am writing a Perl script and I need to execute Unix Ctrl + Z on the script. How can I do it in Perl ? thanks. 回答1: From perl you can send signals to processes with the function kill, which has the same name as the Unix command line tool that does the same thing. The equivalent to Ctrl + Z is running kill -SIGTSTP pid you need to find out what numeric value your TSTP signal has on your system. You would do this by running kill -l TSTP on the command line. Let's say this returns 20 Then in

Directory Handle in Perl Not Working Properly

a 夏天 提交于 2021-02-08 10:58:35
问题 I am trying to read files inside a folder in Perl using Directory Handle. The script is able to show the file name but it is throwing two errors: readdir() attempted on invalid dirhandle DIR and closedir() attempted on invalid dirhandle DIR . I am calling a subroutine and passing two values: if($fileEnding eq "directory") { print "$fileName is a directory\n"; FolderInvestigator1($a, $fileName); } $a holds the directory name and its path which is being passed via command-line argument. I am

moving a perl script/dbm to a new server, and shifting out of dbm?

旧巷老猫 提交于 2021-02-08 06:35:35
问题 I've been tasked with mirroring a site onto a new server. The old site has a few Perl scripts that, as far as I can see internally (i know nothing about Perl, though I have a pretty good understanding of coding generally, and specifically PHP/js/etc) aren't reliant on the old server. That said, when I try to run this script, which looks through a database file to find the appropriate article file, it doesnt retrieve anything. Basically, this is a rudimentary old CMS, as I explain it, where it

issue accessing elements of hash in perl

孤者浪人 提交于 2021-02-08 05:30:33
问题 I have the below hash: my %releaseMap = {"rel1.2.3" => { "supporedPorts" => ["lnx86", "lnppc"], "branch" => ["DEV"], }, "rel2.4" => { "supporedPorts" => ["lnx86", "lnppc"], "branch" => ["DEV"], } }; I want to get the values rel1.2.3 and rel2.4 in the variable $rel, I want to get the values lnx86 and lnppc in $port and I want to get the value DEV in $branch. I am new to the Hash concept in perl, I am not able to figure out how this can be done. Can someone please help. Thanks 回答1: Assuming you