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
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 a perl app that is currently connected to a MYSQL Database, but we would like to migrate the app to a sql server database. A page in the app executes two queries, the 1st is the primary and the second  gets its filter value from the 1st. The problem i'm having is, only the last row from the 1st query being executed in the second query. For instance if the 1st query returns the following
CrsNo   |Customer  | Response
723         Bill                  Urgent
724         Ken                 Urgent
725         Bob                 Urgent

The second query should query the database for each customer number that the first query provided, however, the only query that is executed is CrsNo 725. I have confirmed this with the sql profiler. The odd thing is the same code works fine with MYSql, I only run into this issue with sql server. Below is PERL Code and sql queries.
################## First Query

my $str = "select  distinct q.CRSNo,q.CustomerName,q.ResponseAction,
                           from crs.tbl_customer q
                         where q.CustomerName = '$cname' order by q.CRSNo";
my $temp1 = $dbh->prepare("$str");

      $temp1->execute;
while (my @aray = $temp1->fetchrow_array)
{
($crsno,$crscust,$response) = @aray;

################Second Query
$str2 = "select q.DepartmentInitial,q.ReviewStatusName
                                       from crs.tbl_department as q
                                       where q.CRSNo ='$crsno'  order by q.DepartmentNo";

$#dpt = -1;
      $#dptresp = -1;
      $temp2 = $dbh->prepare("$str2");
      $temp2->execute;

0
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
Hello ,

I need to write a script that reads the mark & masqueraded packets and for every 1/2 of a second it will ask to backend and reply the same answer to each question that comes from udp.
For ex.
Tsource is a counter strike packet. S.b. is making spoofed traffic of tsource , i want to masquerade this traffic to my perl module with marking packets with the destination ip. My script will see the mark and ask to the backend the answer of Tsource. and will answer this packet same for every half of second .
This samples should be given more like teamspeak TSINIT or other udp apps. Is that possible ?

If i block the tsource packet all the server is locking down , there is no logical solution like droping first packet (because the attacker sending 2 packets to server)  or blocking flood (because a companies all servers getting tsource at least once for giving game information , if i block floods for a number this time game lists are closing) . I need to find a way to build a proxy for this kind of application firewall proxies.
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
On Demand Webinar - Networking for the Cloud Era
LVL 9
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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
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
Free Tool: Path Explorer
LVL 9
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

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.