perl

How to properly deobfusacte a Perl script?

主宰稳场 提交于 2020-01-30 14:18:28
问题 I'm trying to deobfuscate the following Perl code (source): #!/usr/bin/perl (my$d=q[AA GTCAGTTCCT CGCTATGTA ACACACACCA TTTGTGAGT ATGTAACATA CTCGCTGGC TATGTCAGAC AGATTGATC GATCGATAGA ATGATAGATC GAACGAGTGA TAGATAGAGT GATAGATAGA GAGAGA GATAGAACGA TC GATAGAGAGA TAGATAGACA G ATCGAGAGAC AGATA GAACGACAGA TAGATAGAT TGAGTGATAG ACTGAGAGAT AGATAGATTG ATAGATAGAT AGATAGATAG ACTGATAGAT AGAGTGATAG ATAGAATGAG AGATAGACAG ACAGACAGAT AGATAGACAG AGAGACAGAT TGATAGATAG ATAGATAGAT TGATAGATAG AATGATAGAT AGATTGAGTG

How to set a list of scalars from a perl hash ref?

那年仲夏 提交于 2020-01-30 08:04:40
问题 How do I set a list of scalars from a perl hash? use strict; my $my_hash = { field1=>'val1', field2=>'val2', field3=>'val3', }; my ($field1,$field2,$field3) = %{$my_hash}{qw(field1 field2 field3)}; print "field1=$field1\nfield2=$field2\nfield3=$field3\n"; 回答1: You're looking for a hash slice which in your case would look like this: my ($field1,$field2,$field3) = @{$my_hash}{qw(field1 field2 field3)}; or like this: my ($field1,$field2,$field3) = @$my_hash{qw(field1 field2 field3)}; If we

How to set a list of scalars from a perl hash ref?

心已入冬 提交于 2020-01-30 08:03:40
问题 How do I set a list of scalars from a perl hash? use strict; my $my_hash = { field1=>'val1', field2=>'val2', field3=>'val3', }; my ($field1,$field2,$field3) = %{$my_hash}{qw(field1 field2 field3)}; print "field1=$field1\nfield2=$field2\nfield3=$field3\n"; 回答1: You're looking for a hash slice which in your case would look like this: my ($field1,$field2,$field3) = @{$my_hash}{qw(field1 field2 field3)}; or like this: my ($field1,$field2,$field3) = @$my_hash{qw(field1 field2 field3)}; If we

Perl glob strange behaviour

最后都变了- 提交于 2020-01-30 06:00:06
问题 I have a piece of perl code: if (glob("$data_dir/*$archivefrom*")) { my $command1 = "zip -r -T -m $backup_dir/$archivefrom.zip $data_dir/*$archivefrom*"; my $err_cmd1 =system("$command1"); if ($err_cmd1 != 0){print "Error $command1\n";exit 1;} } sometimes the if returns true but the zip would not match anything, why would that happen? There is no concurrent processes that would remove files in the meantime, it's just glob is returning something different from zip archive match for files, it

When does ref($variable) return 'IO'?

依然范特西╮ 提交于 2020-01-30 05:16:20
问题 Here's the relevant excerpt from the documentation of the ref function: The value returned depends on the type of thing the reference is a reference to. Builtin types include: SCALAR ARRAY HASH CODE REF GLOB LVALUE FORMAT IO VSTRING Regexp Based on this, I imagined that calling ref on a filehandle would return 'IO' . Surprisingly, it doesn't: use strict; use warnings; open my $fileHandle, '<', 'aValidFile'; close $fileHandle; print ref $fileHandle; # prints 'GLOB', not 'IO' perlref tries to

Simplest way to match array of strings to search in perl?

廉价感情. 提交于 2020-01-30 04:33:57
问题 What I want to do is check an array of strings against my search string and get the corresponding key so I can store it. Is there a magical way of doing this with Perl, or am I doomed to using a loop? If so, what is the most efficient way to do this? I'm relatively new to Perl (I've only written 2 other scripts), so I don't know a lot of the magic yet, just that Perl is magic =D Reference Array: (1 = 'Canon', 2 = 'HP', 3 = 'Sony') Search String: Sony's Cyber-shot DSC-S600 End Result: 3 回答1:

Script to find duplicates in a csv file

情到浓时终转凉″ 提交于 2020-01-30 04:28:19
问题 I have a 40 MB csv file with 50,000 records. Its a giant product listing. Each row has close to 20 fields. [Item#, UPC, Desc, etc] How can I, a) Find and Print duplicate rows. [This file is a large appended file, so I have multiple headers included in the file which I need to remove, so I wanted to know exact rows which are duplicate first.] b) Find and Print duplicate rows based on a column. [See if a UPC is assigned to multiple products] I need to run the command or script on the server and

Script to find duplicates in a csv file

泪湿孤枕 提交于 2020-01-30 04:28:13
问题 I have a 40 MB csv file with 50,000 records. Its a giant product listing. Each row has close to 20 fields. [Item#, UPC, Desc, etc] How can I, a) Find and Print duplicate rows. [This file is a large appended file, so I have multiple headers included in the file which I need to remove, so I wanted to know exact rows which are duplicate first.] b) Find and Print duplicate rows based on a column. [See if a UPC is assigned to multiple products] I need to run the command or script on the server and

Positive lookbehind vs match reset (\K) regex feature

霸气de小男生 提交于 2020-01-30 04:27:43
问题 I just learned about the apparently undocumented \K behavior in Ruby regex (thanks to this answer by anubhava). This feature (possibly named Keep ?) also exists in PHP, Perl, and Python regex flavors. It is described elsewhere as " drops what was matched so far from the match to be returned ." "abc".match(/ab\Kc/) # matches "c" Is this behavior identical to the positive lookbehind marker as used below? "abc".match(/(?<=ab)c/) # matches "c" If not, what differences do the two exhibit? 回答1: It

Use of double negation (!!) [duplicate]

天涯浪子 提交于 2020-01-30 04:05:28
问题 This question already has answers here : What does !! (double exclamation point) mean? (3 answers) Closed 6 years ago . Okay so I came across a code which looks like @documents_names = sort { !!$deleted_documents_names{$a} == !!$deleted_documents_names{$b} ? uc($a) cmp uc($b) : !!$deleted_documents_names{$a} cmp !!$deleted_documents_names{$b} } @documents_names; It's the first time I'm seeing the use of double negation. What's the use of it? When would a person use it? 回答1: It converts non