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

how do you co,pare if 2 files are the same in perl?
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: 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!

Hello

we normally develop softwares on perl , we need a code structure like that for C++

	    $udp_dst_ip{$dst_ip}{src}++;
	    $udp_src_ip{$dst_ip}{$src_ip }{src}++;
	    $udp_src_port{$dst_ip}{$src_port }{src}++;
	    $udp_dst_port{$dst_ip}{$dest_port }{src}++;
	    $udp_tos{$dst_ip}{ $tos }{src}++;
	    $udp_ttl{$dst_ip}{ ($ttl) }{src}++;
	    $udp_packet_length{$dst_ip}{ $packet_length}{src}++;
	    $udp_data{$dst_ip}{$full_data }{src}++;

Open in new window


udp_dst_ip is an hash table when ever i add sth in it , it add one to souce count
for ex.

udp_dst_ip : 185.9.159.2
udp_dst_ip : 185.9.159.3
udp_dst_ip : 185.9.159.4
udp_dst_ip : 185.9.159.2


that returns -> $udp_dst_ip{185.9.159.2}{src} -> 2

and this are double layered hash tables :   $udp_src_ip{$dst_ip}{$ttl }{src}++;  

for ex.

udp_dst_ip : 185.9.159.2  & ttl : 115
udp_dst_ip : 185.9.159.2  & ttl : 116
udp_dst_ip : 185.9.159.2  & ttl : 117
udp_dst_ip : 185.9.159.2  & ttl : 115
udp_dst_ip : 185.9.159.2  & ttl : 115

and this time  $udp_src_ip{185.9.159.2 }{115}{src} returns 3


is there any mechanism on C++ like that ?
0
Hello

We have 2 layered scalars like
$scalar1{scalar2}{scalar3}

values sth like that

bbb -> 15
bbb -> 17
bbb -> 14
bbb -> 15
ccc -> 16
ccc -> 16
ccc -> 14
ccc -> 13
ccc -> 16

We need to find that the maximum counts like that

bbb -> 15   (2 times)
ccc -> 16 (3 times)


should some body help us to deal with that , we are now using sth. like this but it is very slow :



	    $udp_packet_length{%udp_dst_ip}{ sprintf("0x%X", trim($packet_length))}{src}++;


				my $udp_packet_length_max=0;
				foreach $key_udp_packet_length (keys %{$udp_packet_length{$key_udp_dst_ip}} ){
					my $yeni = $udp_packet_length{$key_udp_dst_ip}{$key_udp_packet_length}{src};
					if($yeni>$udp_packet_length_max){
						$udp_packet_length_max=$yeni;
						$udp_packet_length=$key_udp_packet_length;
					}
				}

Open in new window

0
In my previous server I wasn't running mod_perl, but in the new environment I'm setting up I need to.  There are some fundamental differences that I need some help with.

In the current environment, I have a lib folder under the cgi-bin directory.  All of my scripts reference it relatively.  
ie.
require "lib/function.lib";

For my packages I just use:
use lib "lib";
use MyPackage;

This works really well for me for a number of reasons.  I have a dev and production environment that are completely identical and completely separate, but living on the same machine.  I can move programs from dev into production at will without having to change anything.  It's made life much easier.

However in mod_perl it doesn't seem to run in the cgi-bin directory but somewhere else entirely.  I'm not sure if it possible to get the same functionality or how to do it.  Any help would be appreciated.
0
Hello,
I've an email field of a certain array (say $Fields[0]) that usually contains only a mail of a correct ad desired form, say:
$Fields[0] = foo.eee@desiredMail.com

sometimes this desired mail is mixed with other ones, and sometimes is absent, eg:

$Fields[0] = foo.eee@desiredMail.com --- xyz@notdesired1.com ---- abc@nodesired2.com
$Fields[0] = foo.eee@NOTdesiredMail.com

(please note that "---" is NOT a standard separator, it can varies).

I must check this situation and maintain only the desired addresses.
So I've written the following conditional statement:

            
if ( $Campi[0] =~ /\@desiredMail.com/) {
		$Campi[0] =~ m/^([-a-z0-9]+)\desiredMail.com$/; #keep only the @desiredMail.com address
		} else {
			$Campi[0] = "lacks mail @desiredMail.com"; #print a standard msg about the absence of @desiredMail.com
		}

Open in new window

The line
$Campi[0] =~ m/^([-a-z0-9]+)\desiredMail.com$/; #keep only the @desiredMail.com address

Open in new window

does not return the desired result: please can you help me?
Thanks a lot,
Fabiano
0
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
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
Enroll in August's Course of the Month
LVL 9
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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
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
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
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
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 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
I need an example of Perl using sqlite3 for a database in Memory and then writing it to disk afterwards. Later reading it from disk to convert it to in memory
0
"Search Time": "2017-05-08 15:03:20.561",

my $t = Time::Piece->strptime($searchTime, "%Y-%m-%d %H:%M:%S");

I get an error saying
garbage at end of string in strptime: .124 at C:/Perl64/lib/Time/Piece.pm line 481

I am using ActivePerl in Windows. There are packages that I could not install like Time-modules. Actually, I am having so many issues with new packages to install. I need a solution that might not require specific packages as I can get stuck.

perl -v

This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x64-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2017, Larry Wall
0
I just got EE's help to make copies of an svg file with Perl.  How do I make inkscape automatically open an svg file when I double click it?
array.txt
0
I declared an array in perl using the "strict" and "warnings" pragmas.  I annoyingly had to explicitly declare EACH member of the array because I didn't see any pattern in the cemetery lot numbers.  Around element 102 I added a fake value for a lot number (it's clearly marked) just to declare the element.  If I comment or uncomment this line Ige "undeclared variable" warnings.  I'm getting confused.  I think the code is almost there but I'm missing something.
arrays.txt
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.