Perl

25K

Solutions

11

Articles & Videos

10K

Contributors

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects.  Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi

I am updating an XML file and using XML::LibXML

My attribute value that I am replacing is

DESCRIPTION="== Conversion Messages Start ==

Message ID : INF11004 (31284-19308)
Description : An empty RBC is added..

== Conversion Messages End ==
FTP to FTP"

When i try to substitute using the following code the data is not changed.
just trying to move the last line to the beginning line.

$AA =~ s/(.*)== Conversion Messages End ==(.*)/$2 $1== Conversion Messages End ==/;

Output is

== Conversion Messages Start ==

Message ID : INF11004 (31284-19308)
Description : An empty RBC is added..

 == Conversion Messages End ==
FTP to FTP


where it should be

FTP to FTP
== Conversion Messages Start ==

Message ID : INF11004 (31284-19308)
Description : An empty RBC is added..

 == Conversion Messages End ==


I believe its due to the line endings which is causing it to not get the first (.*)


not sure how to get the correct output.

Thanks for the help

Mike
0
Enroll in June's Course of the Month
LVL 8
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

** I know very little about perl

Could someone help me please, with code which will count how many rows of data that start with the same number.

for example, my data list is about 1 million rows

345 654 345 432 236
345 654 345 432 236
345 654 345 432 236
654 345 345 432 236
654 345 345 432 236
654 345 345 432 236
710 654 345 345 436
710 654 345 345 432
710 654 345 345 433
710 654 345 345 433
710 654 345 345 433

I need to count how many rows are present by the first number, so referring to the above set

345   3
654   3
710   5

With the out put to a file

The numbers vary a fair bit.

Thankyou
0
I currently login to the time from website using the following script.


browser = webdriver.Chrome('E:/Shared Folders/Users/runnerjp/chromedriver/chromedriver.exe')
browser.get("https://www.timeform.com/horse-racing/account/sign-in?returnUrl=%2Fhorse-racing%2F") 
time.sleep(3)
username = browser.find_element_by_id("EmailAddress")
password = browser.find_element_by_id("Password")
username.send_keys("usr")
password.send_keys("pass")
login_attempt = browser.find_element_by_xpath("//input[@type='submit']")
time.sleep(3)
login_attempt.submit()

Open in new window


it works but I find using Chrome web driver is hammering my CPU. Is there an alternative code I could use that does not mean I need to physically load the page to sign in?
0
I had this question after viewing adding leading zeros and trailing zeros.

I have the following:

C  --------------                                                                                                                                                                                    
P  IMAGE PANEL                                                                                                                                                                                        
C  --------------                                                                                                                                                                                    
C                                                                                                                                                                                                    
C                                                                                                                                                                                                    
C  ALIGN BOARD RECORDS :   # I need to match this pattern                                                                                                                                                                          
C                                                           …
0
It seems I need to write an Inkscape extension to fill in names from a csv file and write the name on gravesites in cemetery lots.  There are about 100 lots with 12 gravesites per lot.  I could draw all of the names by hand but it seems like more fun to learn perl, python, and extensions.   Does anybody have any hints?
0
I am having a very complex string that I need to tokenize and also create name pair values when possible. Here is a sample of the strings I have

Recod Style 1
Search Result Queries;SomeHotel.com;PT\=89030726\;PA\=-1119567914\;PS\=1547518063;2017-05-13 01:43:36.719;Search Results Query BT SPLIT=checkInDate\=5-13-2017&checkOutDate\=5-14-2017&numberOfAdults\=1&propertyIds\=MS140|MS741|MS1290|MS1334|MS1349|MS4557|MS4568|MS4783|MS4854|SS6029,Web Requests - Client IP=50.251.11.233;Execution Time Informix=2404.003662109375,DB Count=2.0,DB Time=2404.0037887319922;false;;2424.760498046875;2424.760498046875;8.655830353498459;2424.7605440989137;;;;SomeHotel_PROD;dyntrc-mgmt.SomeHotel.com


Recod Style 2
Search Result Queries;Mobile App;PT\=89031695\;PA\=-1119567914\;PS\=1547518063;2017-05-13 01:44:17.772;Search Results Query BT SPLIT=checkInDate\=5-13-2017&checkOutDate\=5-14-2017&corporatePlusNumber\=&numberOfAdults\=1&propertyIds\=MS1173%7CMS4961%7CMS4376%7CMS4281,Web Requests - Client IP=66.115.209.42;Execution Time Informix=1762.662109375,DB Count=5.0,DB Time=1759.847623437643;false;;1781.0732421875;1781.0732421875;10.074070394039154;1781.0732627734542;;;;SomeHotel_PROD;dyntrc-mgmt.SomeHotel.com

Both record styles happen in the same file.

Main delimiter above is;
some values are name-value pairs delimited on \= or =
Some fields contain other fields and delimited by &

Any ideas on how to parse this so I can convert it to some CSV or json
0
I Need the Permissions for Today In History By Craig Patchet and Matthew Wright the unix permissions chmod for cgi that makes Today In History work  I have the cgi and perl cookbook by Craig Patchet and Matthew Wright but I cannot find it I even asked Craig Patch he said it was in the code section, I looked there but it was not in the code section in the book  could you please give me the 6 numbers I need to properly set the unix permissions chmod work for Today in History so it works on my website?  Thanks  Matt
0
I work on an ubuntu Box in my company. I have limited Admin rights. I am behind firewall and proxy. cpan and cpanm not working. Need to be able to load packages and install manually on the box.
I can install on my windows personal and move the corporate box.

Can you give me directions?
0
Hello experts,
I have a perl script that does the following::
-get log files from a directory;
-zip them
-send them over smtp to a given mailbox
-redownload them from the mailbox
-crypt them using pgp
-crypted files gets pushed on ftp
-delete the original file

What i would like to do is:
-Delete the ftp sending part, instead move the files in a local given directory

Attached you will find the script.

Thank you in advance!!!!
export.pl.txt
0
I would like to have a PERL Script that executes the following

The universe that this is updating is about 144 million rows.

UPDATE APR2017_v2 AS T1 INNER JOIN ESEQUENCE_03062017 AS T2 ON T1.ID16 = T2.ID16 SET T1.ESequence = T2.sequence, T1.EMatchLevel = T2.match_code WHERE T1.ESequence IS NULL AND T1.ZIP5 BETWEEN '01000' AND '99499'

We could perhaps change the
...T1.ZIP5 BETWEEN '01000' AND '99499'
to a
"T1.ZIP5 = '01000'
and then up tick the ZIP one chunk at a time. Or even do something like
T1.ZIP5 BETWEEN '01000' AND '06999'
and then have it move up to the next chunk like this
T1.ZIP5 BETWEEN '07000' AND '12999'
(by 5000 at a time) So it is only updating a portion at a time.
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I have never messed with PERL but understand it is probably what I want to be using to import due to the file sizes I am dealing with.

Environment : Linux MariaDB server.

I have 7 data files of roughly 24 million rows each.

Normally I am importing these via SSH mysql command after I move the ".csv" files over to the server running the following command for each file.

LOAD DATA LOCAL INFILE '/home/APR17/20161003_FULL FILE_01.csv' INTO TABLE FD_MASTER FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;

Open in new window


Then I run this query to code the batch that got loaded.

UPDATE FD_MASTER
SET LoadInputFile = '01'
WHERE LoadInputFile IS NULL

Open in new window


So my question is how do I create a PERL script that will load each of the 7 files one at a time, and in between each load run the Update Query.

It would be nice if it at the end provided a simple report of what it did including how long each segment took to load.

After this there are a series of queries that I also run on that Master file which I would like to also add to this process, but those can wait.
0
I have stored all my passwords in a text file.Now i want to encrypt the text file containing password for security.my question is how to encrypt the password file so that later i can easily read passwords out of it and validate through perl
0
I'm trying to write a Perl script to name cemetery files in an organized manner.  The files are for lots in section B of the cemetery.  Each lot is designated by a 3 digit number and so I'm trying to name them:
Blot043, Blot100, etc.  
My script doesn't work.  What wrong with it?
0
Hi,
I need a perl that will list down all the files in the given folder and its subfolder that are modified 'x' minute ago say (20min ago) compared to localtime or system time.Please help me out if you have any idea of how to do this because I am very much new to perl.
0
Hi

I have a script that I am executing and need to get the full value for a child.

<?xml version="1.0" encoding="ISO-8859-1"?>
<DEFTABLE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Folder.xsd">
  <SMART_FOLDER DATACENTER="DEV" CREATION_DATE="20170406" CREATION_TIME="113155" FOLDER_NAME="AAA_TEMPLATE" USED_BY_CODE="0" ADJUST_COND="N" FOLDER_ORDER_METHOD="" APPLICATION="CRITICAL" RUN_AS="DEFAULT_RUN_AS" CREATED_BY="DEFAULT_CREATED_BY" CONFIRM="0" CRITICAL="0" JOBNAME="AAA_TEMPLATE" SUB_APPLICATION="BATCH" DESCRIPTION="== Conversion Messages Start ==&#13;&#10;&#13;&#10;Message ID&#9;: INF11004 (2-5)&#13;&#10;Description&#9;: An empty RBC is added..&#13;&#10;&#13;&#10;== Conversion Messages End ==&#13;&#10;New Chain Template" TIMEFROM="" TIMETO="" PRIORITY="U7" CREATION_USER="5" PLATFORM="UNIX">
</SMART_FOLDER>
</DEFTABLE>

Code is

#!/usr/local/ActivePerl-5.20/bin/perl-static

  use XML::LibXML;
  my $filename = "$ARGV[0]";
  my $dom = XML::LibXML->load_xml(location => $filename);

  foreach my $smart_folder ($dom->findnodes('/DEFTABLE/SMART_FOLDER')) {
      print $smart_folder->getAttribute('FOLDER_NAME'), ":::";
      print $smart_folder->getAttribute('JOBNAME'), ":::";
      print $smart_folder->getAttribute('DESCRIPTION'), ":::";
      print "\n";
  }


output is

AAA_TEMPLATE:::AAA_TEMPLATE:::== Conversion Messages Start ==

Message ID      : INF11004 (2-5)
Description      : An empty RBC is added..

== …
0
I want to ssh to another server and be able to remove the last line from the /etc/sudoers file. I'm NOT very good at one-liners, but I need one here.  Any help would be greatly appreciated!

Thanks!
David
0
Hello Experts!

I have a question regarding a Perl script that evidently has no output and I need to figure out what I'm doing wrong. I've attached some of the debug as well. Is it the line "next if int(length($data))<128;" that's causing the issue?

OS: Ubuntu Yakkety (WIN 10 is also available with Strawberry Perl)
Attached: Perl script and Sql dump I'm attempting to extract from

==Script==
##!/usr/bin/perl

use strict;
use vars qw { $FILE };

$FILE = shift;
if ($FILE eq "") {
    die "Syntax: $0 [filename]\n";
}

&parse($FILE);

sub parse {
    my($FILE) = @_;
    open(FILE, "<$FILE") || die "$FILE: $!";
    mkdir("./maptiles-output", 0755);
    while(<FILE>) {
        chomp;
        my $j = 0;
        my $contents = $_;
        next unless ($contents =~ /^INSERT /);
        my ($junk, $sql, $junk) = split(/\(|\)/, $contents);
        my ($zoom, $x, $y, $flags, $length, $data) = split(/\,/, $sql);
        $data =~ s/^X'//;
        $data =~ s/'$//;
        my $filename = "./maptiles-output/$x,$y\@$zoom.png";
        next if int(length($data))<128;
        print $filename . "\n";
        open(OUT, ">$filename") || die "$filename: $!";
        print int(length($data)) . "\n";
        while($j < length($data)) {
            my $hex = "0x" . substr($data, $j, 2);
            print OUT chr(hex($hex));
            $j += 2;
        }
        close(OUT);
    }
    close(FILE);
}

++ Debug Output (partial) ++
maptiles.sql
0
I want to know if it's possible to map two arrays of different size into one hash. One array (arr1) has a list of directories and the other (arr2) has a list of 30 files under each directory.  The size of arr1 is 122 elements and the size of arr2 is 3660 elements.  Since keys have to be unique, the keys would be the files and the values would be the directories.  Below are examples of how the arrays are populated and the possible hash from combining them:

arr1 = (dir1, dir2, dir3, ... , dir122 );
arr2 = (dir1_file1, dir1_file2, dir1_file3, ... , dir1_file30, dir2_file1, dir2_file2, dir2_file3, ... ,dir2_file30, dir3_file1,.... etc );

%hash = (

dir1_file1 => dir1
dir1_file2 => dir1
dir1_file3 => dir1
....
dir1_file30 => dir1
dir2_file1 => dir2
dir2_file2 => dir2
dir2_file3 => dir2
....
dir2_file30 => dir2
dir3_file1 => dir3
dir3_file2 => dir3
dir3_file3 => dir3
....
dir3_file30 => dir3
dir4_file1 => dir4
....
dir122_file30 => dir122
);

Open in new window


No idea how to code this as I'm weak with hashes so any help is appreciated. Thanks in advance!
0
We are having 1 perl script that run as windows service and its task is to update VM Virtual NIC Card in every 10 seconds.This period is fed to acript by some eternal .DAT file.
The to get the status of the NIC Card in every 10 seconds, it logs in and logged out to and from VM HOST.And we observer frequent failure in that (from VM Host log (hostd.log), we can see the same.The Perl script uses the vSphere Credential Store Subroutine module as depicted below.
 
VM Get NIC card status  

The problem is when ever there is a failure in log in , I am not able to monitor the NIC status and it happens very frequently.
VM Ware Esxi version is 6.0.0
VM Ware CLI 6.0.0.7357

Is there any remedy of the problem? The below is the logs captured from hostd.log file.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
2017-03-01T18:56:09.571Z info hostd[31301B70] [Originator@6876 sub=Vimsvc.ha-eventmgr opID=9b80d4e2 user=root] Event 656195 : User root@172.31.77.98 logged out (login time:Wednesday, 01 March, 2017 18:56:04, number of API invocations: 0, user agent: VI Perl)
[module:pam_lsass]pam_do_authenticate: error [login:root][error code:2]
[module:pam_lsass]pam_sm_authenticate: failed [error code:2]
[module:pam_lsass]pam_do_authenticate: error [login:root][error code:2]
[module:pam_lsass]pam_sm_authenticate: failed [error code:2]
0
Announcing the Most Valuable Experts of 2016
LVL 6
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Hi Experts,

I'm writing a web application, which allows authorised people to login and view/modify some private information of other people.  The application works, but after logging off I can click my browser's "back" button and see that private information which came up while I was logged on!  This means an unauthorised person (e.g. family member) could come to the PC after the session, and see things they aren't allowed to.

How can I make my website prevent this from happening?

I notice that some websites prevent such reviewing of the session by going back afterwards, including banking sites.

The solution must be driven from the website, not by the user, because I can't rely on users to take extra steps (or extra time) to guard against this by clearing their cache or whatever each time they logoff.

I'm using the Perl programming language, and I have a Let's Encrypt security certificate, (in case that makes any difference).

Thanks.
tel2
0
I am new in this environment. Need to create a monitor which will monitor the queue size of different topic og ActiveMq  and if queue size more than we expected to we need trigger the nagios to send some kind notification . Tool we can use is jmx4perl, check_jmx4perl.
Your guidance will  be appreciate
Your inputs will be highly appreciate.

Thanks
0
i have a form that has two fields
1.field1     selectbox1
2.field2     selectbox2
now i get values in selectbox1 from the database and the option i get in this selected field shows in alert as
field1  :radha
filed2: sharma
i have alert value that i get in response.
now i want that as i select field1 ,than field2 should show value as sharma in the form just after a click on the option of selectbox1

\$(document).ready(function () {
      

\$('#CONTRACT_NO').on('change', function()
{
            
                        
            var CONTRACT_NO = \$('#CONTRACT_NO').val();
                  var CONTRACT_DATE = \$('#CONTRACT_DATE').val();
     
\$.ajax
({
                  type: "POST",
                  url: "macrocall.cgi",
                  data: {
                              macro: "ajax/name",
                              CGISESSID:"$CGISESSID",
                              FIELD1:FIELD1,
                              FIELD2:FIELD2,
                              
                              action : 'FIELD1'
                              },
                              dataType: 'text',
                              success: function(data){
      
alert(data);});
0
I have a large list of proxies in the same directory as my perl script, I would like to use a proxy from the list in my script, if it fails to connect it cycles to the next proxy and so on. How would i call this into my script from an external txt file. Is it possible?
0
Here's my VERY simple line of code (with error). This should be a no brainer but I've just setup Eclipse version 4.6.2 (Build 20161208-0600) and it's all new to me. It also appears that the escaping the forward slashes weren't needed either as that didn't work. :)

--- CODE Begin ---
use strict;
use warnings;

use LWP::Simple;

sub main {
    print get("http://www.SomeWebsiteThatWorks.com/"); <-- ** Error = Use of uninitialized value in print at (line of code or this line). **
}

main();
--- CODE Ends ---

Thanks!
0
I have a perl script that worked as a “middle men” between a local program and an external interactive website.

The problem is that the external website migrated from plain tcp connection to a websocket connection.

When the server was using tcp, after initial connection, the client (the script) and the server (external website) will go thru a handshake, then the script will send the username and password and server will finally respond with some encryption keys, afterwards the script will go into an infinite loop and waited for data from both connections and then process that data and "print" back to the connections as needed.

I had been able to establish the websocket connection with the server using the Mojo::UserAgent as well as with protocol::websocket, go thru the handshake and the other information exchange (username, password, etc), but I have not been able (or better said: I do not know how) to "throw" the websocket connection into the infinite loop via IO::Select ( The reason I want to use IO::Select is because doing so will require minimal changes to the script, but other suggestions are definitely welcome).

The relevant parts of the script are as follows:

   
 # Creating connection for local program
    $lsn=new IO::Socket::INET(
        Proto => 'tcp',
        LocalPort => 6000,
        Listen => 1,
    );
    unless(defined $lsn){
        print"$0: $!\n";
        exit 1;
    }
    print"Waiting for local program connection on port 6000\n";
  

Open in new window

0

Perl

25K

Solutions

11

Articles & Videos

10K

Contributors

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects.  Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.