perl

Non greedy text matching and extrapolating in bash

前提是你 提交于 2020-07-04 02:05:12
问题 I have a utility that can parse the attributes within a large xml tag, such as <mytag name="value" name="value"../> I have written the utility in perl. It uses basic non-greedy text matching, like this: while(<XML>) { if (/name=\"(.+?)\"/) { print("Value is: $1\n"); } I know the names of the name/value pairs I want to extract, so I hardcode them into the utility. This works for me quite well...how can I do this in bash? I have tried using awk but it is not working for when I have an attribute

Not able to read complete cookie in perl

天大地大妈咪最大 提交于 2020-07-03 13:01:41
问题 I am receiving below cookie from my source system ExternalAccess=unixtime=1593603710&oracletime=01-jul-20 12:41:50_Hash_thNnmggU2ex3L5XXeMNfxf8Wl8STcVZTxscSFEKSxa0 At destination system [PERL based], using below code to read the cookie my $extSysCookie = $Query->cookie('ExternalAccess'); i am getting below output External Access cookie = unixtime=1593603710 and not able to read full value.All characters after & are getting omitted. Can anyone help? 回答1: First of all, that's not a valid cookie

Not able to read complete cookie in perl

旧城冷巷雨未停 提交于 2020-07-03 13:01:29
问题 I am receiving below cookie from my source system ExternalAccess=unixtime=1593603710&oracletime=01-jul-20 12:41:50_Hash_thNnmggU2ex3L5XXeMNfxf8Wl8STcVZTxscSFEKSxa0 At destination system [PERL based], using below code to read the cookie my $extSysCookie = $Query->cookie('ExternalAccess'); i am getting below output External Access cookie = unixtime=1593603710 and not able to read full value.All characters after & are getting omitted. Can anyone help? 回答1: First of all, that's not a valid cookie

Range operator decrementing from largest to smallest: 10..1 [duplicate]

元气小坏坏 提交于 2020-07-03 06:37:21
问题 This question already has answers here : Alternate for making such a thing work in perl : `for(10…0)` (3 answers) Closed 5 years ago . Perl has a range operator, which when used in a foreach loop, does not create a temporary array: foreach (1 .. 1_000_000) { # code } If the first integer is smaller than the second integer, then no iterations are run: foreach (1_000_000 .. 1) { # code here never runs } I could use the reverse built-in, but would this keep the optimisation of not creating a

To Convert CSV File to Hash Structure using TEXT::CSV_XS Module in perl

时光毁灭记忆、已成空白 提交于 2020-06-29 06:39:12
问题 I've below code which is used to read a csv file and convert to hash. The Keys are dependent on the number of key columns that user need. use warnings; use strict; my %hash; my $KeyCols = 2; while (<DATA>) { chomp; my @cols = split /,/, $_, $KeyCols+1; next unless @cols > $KeyCols; my $v = pop @cols; my $k = join '', @cols; $hash{$k} = $v; } I need help in achieving the same logic using TEXT::CSV_XS package for efficiency. Please help. 回答1: The real reason for using Text::CSV_XS is for

Perl: Parse json response for next curl request

醉酒当歌 提交于 2020-06-29 04:17:17
问题 Is there a way in perl to parse json response for the next curl request? e.g. I have a command: curl -H "Content-Type: application/json" -H "Authorization: Bearer DS_12345" -X GET https://api.xxx The response is: { "method":"a", "users":["user@xxx.com "], "status":"DONE", "export-url":"https://api.xxx/v1/export/DP_6789xxx" } When (Wait until) the response includes "status":"DONE", instead of "FAIL" or "PROCESSING", run the next step by taking response "export-url":"https://api.xxx/v1/export

XML::Twig and save order of attributes

混江龙づ霸主 提交于 2020-06-27 15:59:05
问题 I am editing some XML files using XML::Twig below are the code : my $twig = XML::Twig->new( pretty_print => 'indented', twig_handlers => { Vendor => sub { $_->set_att( 'ID' => $_->{'att'}->{'att1'} ); $_->set_att( 'ID' => $_->{'att'}->{'att2'} ); $_->set_att( 'ID' => $_->{'att'}->{'att3'} ); $_->set_att( 'ID' => $_->{'att'}->{'att4'} ); }, }, ); $twig->parsefile('myfile'); $twig->flush; The problem is that this code does not save the xml attributes in the same order in the edited file. for

how to eval regular expression with embedded perl code

喜欢而已 提交于 2020-06-27 15:47:05
问题 So I tested out a regular expression that utilizes the experimental embedded code features. My tests worked, so I expounded upon it to do a more sophisticated script, but ran into errors. I traced the errors to a simple use of a variable in the regular expression not in the embedded code. I tried doing the regex in the suggested eval, but discovered that that wouldn't work because I could not access special variables after the eval'ed regular expression. I eventually re-wrote the code to not

How can I view the contents of a hash in Perl6 (in a fashion similar to the Perl 5 modules Data::Dump or Data::Show)?

风流意气都作罢 提交于 2020-06-27 07:07:05
问题 In Perl 5, if I want to see the contents of a hash, I can use Data::Show, Data::Dump, or Data::Dumper. For example: use Data::Show; my %title_for = ( 'Book 1' => { 'Chapter 1' => 'Introduction', 'Chapter 2' => 'Conclusion', }, 'Book 2' => { 'Chapter 1' => 'Intro', 'Chapter 2' => 'Interesting stuff', 'Chapter 3' => 'Final words', } ); show(%title_for); Which outputs: ======( %title_for )======================[ 'temp.pl', line 15 ]====== { "Book 1" => { "Chapter 1" => "Introduction", "Chapter 2

How to replace all unicode characters except for Spanish ones?

十年热恋 提交于 2020-06-23 07:38:27
问题 I am trying to remove all Unicode characters from a file except for the Spanish characters. Matching the different vowels has not been any issue and áéíóúÁÉÍÓÚ are not replaced using the following regex (but all other Unicode appears to be replaced): perl -pe 's/[^áéíóúÁÉÍÓÚ[:ascii:]]//g;' filename But when I add the inverted question mark ¿ or exclamation mark ¡ to the regex other Unicode characters are also being matched and excluded that I would like to be removed: perl -pe 's/[^áéíóúÁÉÍÓÚ