Perl

25K

Solutions

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

I have this code

while (<FILE>) {
open FILE, "1.vim" || die "unable to open file:$! \n";

chomp()
@array=split(/\s+);
$columns{'Col1'}{$array[0]}+=1;
$columns{'Col2'}{$array[1]}+=1;
$columns{'Col3'}{$array[2]}+=1;
$columns{'Col4'}{$array[3]}+=1;
}
foreach $key (keys %columns) {  #first Hash columns
      print "$key\npattern,count\n";
     foreach $pattern (sort keys %{$columns{$key}}) { #pattern sort
             print "$pattern,$column{$key}{$pattern}\n";      
     }
}

What code could I add to the end which would enable me just to have the perl script do that without opening the command window, and where do I put that code ?
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

I have columns of numerical data, with which I have to identify and count which numbers are present in each individual column.

so, I can have between four and twelve columns, but if it is easier just to code for four at the moment, that would be great. There is likely to be between 30 and 70 different numbers.

so if the data looked like this

123 123 165 134
134 123 165 134
165 165 165 165
243 243 245 165
245 165 245 123
234 123 165 123
123 165 165 245
134 123 165 245
165 165 123 245

I need some code which will create an output like this or similar so that I can import it into MS Excel spreadsheet.

col 1

123 2
134 2
165 2
234 1
243 1
245 1

col 2

123 4
134 0
165 4
234 1
243 1
245 0

col 3

123 1
134 0
165 6
234 0
243 0
245 2

col 4

123 2
134 2
165 2
234 0
243 0
245 3

Thankyou in advance
0
I want to create a vb-ish type program using perl in ubuntu.  My question: is leaning gtk+ the correct path or is there a better way to use my effort?
my-computer.png
0
I have code which generates 6 random numbers in much the same was as the National Lottery does.

It creates one line of six numbers.

What I would like is to create 2000 lines of these numbers. Could someone alter the code in order to do this please ?

Thankyou
random.txt
0
Is it possible, with PERL, to create random numbers in a similar way to the UK National Lottery ?

That is, is it possible to choose a first number randomly (from 59) followed by a second number (this time from 58 with the number missing being the first number) and so on until 6 numbers are chosen ?

If so, could a kind PERL expert please help me out with some code for such a thing ?

Thank you
0
I am somewhat in range to creating a script to measure each line of a paragraph by a certain amount of characters, add the <br> tag (line break), create a carriage return and continue with the next word. Below is what I have so far. I included what I want to do in each line as a comment. Please help, thanks.

_______

#!/usr/bin/perl -w

my $indChar = /./g   # any character

def (readLine)
    read line < file.txt;    # read each individual line
    foreach ($indChar);
        $myTally += 1;
        if ($myTally = 100);
            # confirm if next character is a space \s $indChar ? (\s)
                # stop;
                #
            # confirm if next character is a letter \s $indChar ? (\w)
            # next;
0
I have attached a list of 2047 results for an american lottery. draw-results-1-to-2047.txt

I need to strip out only the lines with the actual draw results and do away with all the other data as per this sample file embed=file 1182640]

I know very little about PERL.
EE-sample-file.txt
0
An Application running on linux executes perl scripts in the background which connects to MSSQL database running on Windows Server. In order to connect Linux server to Windows Database server Microsoft ODBC driver needs to be installed so I have installed UnixODBC  version 2.3.0.
So when I'm going to execute the perl script it throws an error (See below)

DBI connect('DRIVER={SQLServerNew};Server=GAALPA1MSGSQL02.itservices.sbc.com;Database=Faxing-Test','M36097',...) failed:

[unixODBC][Driver Manager]Can't open lib 'SQLServerNew' : file not found (SQL-01000) at ./RightFax.pl line 104.

Can you please look into the issues since last two months I'm trying to resolve however no luck.
0
Hello,

I need help in perl script where i will be reading data from csv file and loading in to oracle database.
This is my very first experience with perl script.
 Pls help!

-jn
0
in Linux I'm getting below error message

    grep: support for the -P option is not compiled into this --disable-perl-regexp binary
0
[Live Webinar] The Cloud Skills Gap
LVL 4
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Darwin -bash: use: command not found Why can't I use this module & why is -bash come come up?
0
Help - Mac Darwin Perl 5.18  -bash: use: command not found
0
I have xlc compiler version 8 and perl 5.10 running on AIX 7.1. I have been able to install DBI.pm module successfully, but now am in need to install DBD::ORACLE module. The oracle version is 12 (64bit)

perl Makefile.PL runs fine for the DBD::ORACLE module, however the "make" command is throwing below error:
I attempted to fix the issue by changing the object mode value, but that end up giving a different type of error.
Can you advise on the solution ?

#make
        rm -f blib/arch/auto/DBD/Oracle/Oracle.so
        LD_RUN_PATH="/u01/app/oracle/product/12.1.0/client_1/lib:/u01/app/oracle/product/12.1.0/client_1/rdbms/lib" ld  -bhalt:4 -G -bI:/usr/opt/perl5/lib/5.10.1
            /aix-thread-multi/CORE/perl.exp -bE:Oracle.exp -bnoentry -lpthreads -lc -lm -L/usr/local/lib Oracle.o  dbdimp.o  oci8.o /lib/crt0_64.o -bI:/usr/lib/iocp.
            exp  -o blib/arch/auto/DBD/Oracle/Oracle.so     -L/u01/app/oracle/product/12.1.0/client_1/lib/ -lclntsh -lclntshcore -lld -lm -ldl -lc -lm -lpthreads -
            lodm
            -lbsd_r -lld -lperfstat -lm -lpthreads
ld: 0711-736 ERROR: Input file /lib/crt0_64.o:
        XCOFF64 object files are not allowed in 32-bit mode.
make: The error code from the last command is 8.

#bootinfo -K
64

#ORACCENV='cc=xlc_r'; export ORACCENV

#export OBJECT_MODE=64
#make
        rm -f blib/arch/auto/DBD/Oracle/Oracle.so
        LD_RUN_PATH="/u01/app/oracle/product/12.1.0/client_1/lib:/u01/app/oracle/product/12.1.0/client_1/rdbms/lib" ld  -bhalt:4 -G …
0
I recently upgraded AIX from 6.1 to 7.1, which resulted in perl getting upgraded from 5.8 to 5.10 as well and in process i no longer have a dbi.pm module under perl 5.10.

I have been unable to find binary version for dbi.pm for perl 5.10 so i am trying to compile it but running into an issue with it.
I am using steps of running perl Makefile.PL, make, make test, make install to compile.
I am able to successfully run perl Makefile.PL from the dbi.pm directory that i saved in /tmp from cpan.org, but when i run the "make" command, i get following error.

Skip blib/lib/DBI/ProfileData.pm (unchanged)
        xlc_r -q32 -c    -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=-1 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -qlanglvl=extended -I/usr/local/include -q32 -D_LARGE_FILES -qlonglong -O    -DVERSION=\"1.636\"  -DXS_VERSION=\"1.636\"  "-I/usr/opt/perl5/lib/5.10.1/aix-thread-multi/CORE"   Perl.c
/bin/sh: xlc_r:  not found
make: The error code from the last command is 127.

I do have xlc compiler installed.
  vac.C                      8.0.0.0  COMMITTED  IBM XL C Compiler
  vac.C                      8.0.0.0  COMMITTED  IBM XL C Compiler
  vacpp.cmp.core             8.0.0.0  COMMITTED  IBM XL C/C++ Compiler
  vacpp.cmp.core             8.0.0.0  COMMITTED  IBM XL C/C++ Compiler
  xlC.aix61.rte             12.1.0.3  COMMITTED  IBM XL C++ Runtime for AIX 6.1

/usr/vacpp/bin/xlC -qversion
IBM XL C/C++ Enterprise Edition V8.0 for AIX
Version: …
0
Hi

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

My attribute value that I am replacing is

DESCRIPTION="== Conversion Messages Start ==&#xA;&#xA;Message ID : INF11004 (31284-19308)&#xA;Description : An empty RBC is added..&#xA;&#xA;== Conversion Messages End ==&#xA;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
Hello

I have list of data

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

through which I need to find repeat entries row on row, over about one million rows.

Manually I have to take the first row and check for a repeat of any of the values of that row with the next row. If there are any repeat values, then I have to mark down how many. Then I move onto the next row and repeat the process.

I then have to tally how many rows had whatever number of repeated values.

so the out put would look like

4
4
4
0
2
2
3
3
4
4
(for each row)

total

0 values were repeated on 1 rows
2  values were repeated on 2 rows
3   values were repeated on 3 rows
4   values were repeated on 5 rows

Could someone help me for code with this, output to a VIM file please ?
0
** 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
Hi Experts,

Im trying to convert a series of scripts that we use internally to a vb.net applicaiton with a GUI that can be passed on to the BAU teams. Unfortunately my knowledg around encryption is pretty non existant.

Would anyone be so kind as to explain to me how to convert the below perl to VB.NET? Or at least point me in the correct direction as far as namespaces etc are concerned?

use DBI;
use strict;
use warnings;
use Crypt::CBC;
use MIME::Base64;
use Encode;
use Digest::MD5 qw(md5_hex);
use warnings;


my $encrypted = <FILE>;

my $iv  = '0000000000000000';
my $utf_decoded = encode_utf8($iv);
my $key = "854EE3617FDDA2D3";


#create Cipher based on AES
my $cipher = Crypt::CBC->new(
				-key => $key,
				-literal_key => 1,
				-iv => pack('H32',$utf_decoded),
				-header => 'none',
				-padding => 'standard',
				-blocksize => 16,
				-keysize => 16,
               -cipher => "OpenSSL::AES"
);

my @dec = decode_base64($encrypted);
my $count = 0;

foreach my $entry (@dec) {
	my $temp = $cipher->decrypt($entry);
	$temp =~ s/[\x0D]//g; 
	$count++;
	print "$temp";
}

exit();

Open in new window



Here is what i have so far.... not going so great.

Public Function AES_Decrypt(ByVal input As String)

Dim KeyStr As String = "854EE3617FDDA2D3"
        Dim IVstr As String = "0000000000000000"
        

        Dim IV(15) As Byte
        For I = 0 To 15
            IV(I) = IVstr.Substring(I, 1)
        Next

        Dim AES As New RijndaelManaged
        Dim Hash_AES 

Open in new window

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
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 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
Im runinnig a linux server
although my qmail queu was very quite I was listed in more than 10 blacklist sites for sending spams. then from my tcpdump I saw that there is hundreds of perl processes owned by apache  user making thousands of smtp connection. however I could not locate this perl script.
is there a way to find the full path of what this perl is runinnig?
0
I have a file with a character that translates into 272 when I do:
od -xc

The character looks like an A with a caret on top with a degree sign to the right. I am attaching an image of the character as well. I have tried sed, perl and tr and none of them are working.

For example:
sed -e 's/'$(echo "272")'/ /g' input_file > output_file

This does not work.

Any suggestions?
Image.jpg
0
I am new to perl and need some help in doing the following:

I have the following:
#P 0.725 22.425
#P 17.275 22.175
#P 17.275 1.575
#P 0.725 1.575

I need to add a leading zero for numbers that are less than two digits before the DOT  and add trailing zeros to the number to add a total of six digits after the DOT. Output should look like the following:

#P 00.7250 22.4250
#P 17.2750 22.1750
#P 17.2750 01.5750
#P 00.7250 01.575 0
Thanks for helping
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

Perl

25K

Solutions

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.