perl-module

How do I compare certain values from different XML documents?

坚强是说给别人听的谎言 提交于 2019-12-08 11:35:33
问题 I want to write code in Perl that compares two XML files. A Little bit from the history... With API Documentation (get request) I get data1 form the Web Service1 and data2 from the Service2. They are presented in XML Format, but not the same. I should compare just two elements in these files (deviceName and ipAddress), if they are the same in both files, It should be a message " WebService1 already contains DeviceName "Switch1" ". If not - I would make POST request and add this device in

How does the Perl 'use' syntax work?

蹲街弑〆低调 提交于 2019-12-08 10:12:13
问题 Sample code: m1.pm my $a; my $b; sub init { $a = shift; $b = shift; } sub printab { print "a = -$a-\n"; print "b = -$b-\n"; } 1; m2.pm my $a; my $b; sub init { $a = shift; $b = shift; } 1; test.pl use strict; use warnings; use m1; use m2; init('hello', 'world'); printab(); Run: $ perl test.pl a = -- b = -- $ What happens is that the init('hello', 'world') call is mapped to m2.pm and initializes the variables ( $a and $b ) there. This kind of makes sense, but what I do not understand is why

Perl LWP::Simple HTTPS error

牧云@^-^@ 提交于 2019-12-08 00:53:19
问题 I am trying to get the contents of a website and print. The code worked how I wanted it to work with a regular HTTP website, but it will not work with HTTPS. I have looked up fixes for this issue, but they are not working in my program. This is the code I currently have: #! usr/bin/perl use strict; use warnings; use LWP::Simple; use LWP::UserAgent; use 5.014; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = LWP::UserAgent->new(); $ua->ssl_opts( verify_hostnames => 0 ); getprint('https://

Perl: when do you use system() and when do you install the package?

旧街凉风 提交于 2019-12-08 00:15:28
问题 I work in a project that uses Perl scripts on machines that are maintained by system folks, and installing packages such as Perl modules is no easy task - you usually have to call the person with the permissions to do that, wait several days, learn the API of the package, and then remember to install it on every newly configured machine ever installed. The alternative that is many times chosen is just calling system() (or backtick notation, `` , inside Perl) and using the output of the shell

HTML::PullParser splits up text element randomly

大兔子大兔子 提交于 2019-12-07 16:36:06
问题 I'm using Perl module HTML::PullParser . I noticed that it sometimes splits up a text element (as far as I can tell) randomly. For example, if I have a html file test.html with the content of <html> ... <FONT STYLE="font-family:Times New Roman" SIZE="2">THE QUICK BROWN FOX</FONT> ... </html> And my perl code looks something like my $html = HTML::PullParser->new(file => 'test.html', text => '"T", text'); while (my $token = $html->get_token) { print "$$token[1]\n"; } Then sometimes I get back

$SIG{INT}='IGNORE' not working with Net::OpenSSH

懵懂的女人 提交于 2019-12-07 11:35:34
问题 I need to execute commands via $ssh->system in background, and it is documented that this should behave just like the local "system" command: 'As for "system" builtin, "SIGINT" and "SIGQUIT" signals are blocked. (see "system" in perlfunc).' Actually, this does not seem to be true, as $ssh->system in a child is immediately terminated when SIGINT is received, even when I explicitly want to "IGNORE" it first: use warnings; use strict; use POSIX ":sys_wait_h"; use Net::OpenSSH; my $CTRLC=0; $SIG

How do I include all/some of the “sub modules” in a Perl script?

青春壹個敷衍的年華 提交于 2019-12-07 08:30:58
问题 I'll just start out by saying I am not at all experienced with creating Perl modules so I'm sorry if I'm way off here. Let's say I am creating a few modules: foo::bar foo::bar::a foo::bar::b Since I don't know what they are called, I am calling the a.pm and b.pm modules "sub modules" since they are related to the bar.pm module, but could still be somewhat independent. So one of my Perl scripts could use foo::bar::a, another script could use foo::bar::b, and maybe I have another script that

How to specify test prerequisites in the ExtUtils::MakeMaker Makefile.PL

寵の児 提交于 2019-12-07 05:02:31
问题 PREREQ_PM specifies the runtime prerequisites, but how to specify which modules are required to run the test cases? Should I use BUILD_REQUIRES for this? 回答1: As of ExtUtils::MakeMaker 6.64, there is a TEST_REQUIRES parameter. use ExtUtils::MakeMaker 6.64; WriteMakefile( ..., TEST_REQUIRES => { Test::More => 0.95, }, ..., ); 回答2: The CPAN::Meta::Spec defines how modules communicate their prerequisites to the toolchain. The version 2 spec revised the way prerequisites are listed. The test

progress bar in command line perl script

不羁的心 提交于 2019-12-07 04:49:55
问题 I am trying to print progress in % in command prompt. But it is not working properly. I want to print the progress as :: Status 10% Completed when 20% will complete it will show Status 20% Completed in that same place not in new line. Could you please help me. Code:: $count++; $per=($count/$total)*100; print "\nStatus: $per Completed.\r"; sleep 1; 回答1: You can do something like this: use strict; use warnings; use Time::HiRes qw(usleep); local $| = 1; my @nums = 1 .. 20; foreach my $c (@nums)

Read MS Word table data row wise using win32:ole perl

最后都变了- 提交于 2019-12-07 04:26:43
问题 I am new to win32:ole module in perl. I am trying to print MS word table data row wise on command prompt. But I am able to print only last row of the table. Can you please help me to solve this problem? Thanks in advance. Below is my code: #!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw( catfile ); use Win32::OLE qw(in); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 3; my $word = get_word(); $word->{DisplayAlerts} = wdAlertsNone; $word->{Visible} = 1; my