Perl

26K

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

Hi all,

 How to compare string within an array? That string contains backslashes, colon and paranthesis.

sample program:

use strict;
use warnings;

sub perl_func {
    my ($z, $x) = @_;

    print "\n";
    print "z: $z\n\n";
   
    my @lx=@$x;
    foreach my $tx (@lx)
    {
       
        if ($z !~ m|$tx|)
        {
            print "$z !~ $tx\n";
        }
        else
        {
            print "$z == $tx\n";
            return 1;
        }
    }
   
    print "\n";
    return 0;
   

}

#my @x = ("One", "Two", "Three", "Four", "Five");
#my $z = "Four";
#works fine for above x & z

my @x = ("One\\OnesPosition:Num (NumPerl)", "Two\\TensPosition:Num (NumPerl)", "Three\\HundresPosition:Num (NumPerl)", "Four\\ThosandsPosition:Num (NumPerl)", "Five\\TenThousPosition:Num (NumPerl)");
my $z = "Four\\ThosandsPosition:Num (NumPerl)";


if(perl_func($z, \@x))
{
    print "\nfound element\n";
}
else
{
    print "\nnot found element\n";
}
0
HTML5 and CSS3 Fundamentals
LVL 12
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

what is the perl regular expresssion to compare "machinename\\username" in perl scripts?

sample code:
print "Hello World!\n";
$mname="BVM";
$user = "test";
$mu_reg = "^(?i)$mname/\/\$user \$";
$mu_str = "164AUTH/\/\chris";



$ipstr="$mu_str ";
$ipstr_re = "^(?i)mu_reg \$"; # regex failed with two backslashes. How to fix it?
if ($ipstr !~ /$ipstr_re/) {
    print "It doesn't match\n";
}
else {
    print "It matches\n";
}
0
Code is here:

my $a1 = ‘a1_v’;
my $c1;
my $varName;

my $code = qq(
      \$varName = ‘a1’;
      eval(‘\$c1 = \$\$varName;’);
);

eval($code);

# I hope this line print a1_v, but print nothing
print “$c1\n”;
0
When we get threat intels info for hashes to be added to Trendmicro
Officescan, the MD5 or SHA1 hash value has to be entered into an
IOC Editor (we use Mandiant's ie
 https://www.fireeye.com/content/dam/fireeye-www/services/freeware/ug-ioc-editor.pdf)
 to generate 2 values indicated by 1st value & 2nd value enclosed in "...'  below.

However, sometimes, the intel that comes in can be more than a hundred, so this makes
it very tedious to manually generate the values & populate into the IOC file for Officescan
to read in.  Is there an automated way / script to generate the 2 values for each hash &
auto-populate (using script etc) or an easier way for Officescan to read in just the hash
values?    Have logged a case with Trendmicro & was advised to do it manually which
does not help at all.

attached the full IOC file.


   Sample IOC file's content:
   ====================
<?xml version="1.0" encoding="us-ascii"?>
<ioc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="2146113a-1513-4be6-b07e-f43969847a6a" last-modified="2018-12-02T02:19:17" xmlns="http://schemas.mandiant.com/2010/ioc">
  <short_description>Default</short_description>
  <authored_date>2017-09-26T02:58:26</authored_date>
  <links />
  <definition>
    <Indicator operator="OR" id="a1c825b0-ae7f-4461-85dd-25a20720acac">          <== 1st value enclosed in "...";  once only for entire IOC file
      <IndicatorItem …
0
Hi

I have a Perl question.

I have an input that is "x                               "   it is 23 characters and I will get a number to adjust the x character back or forward with in the 23 character field.

Example

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
X

I might get -4 which means I need to adjust back 4 and would make it

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
                                                                                    X


The problem is I am not sure how to program this.

I could get +5 or -10

Any help would be appreciated

Thanks

Mike
0
Enroll in these five web development courses: RESTful Services: Data, JAX-RS and Jersey, RESTful Services: Fundamentals, Selenium Fundamentals, Bootstrap 3.1: Fundamentals, and Perl Fundamentals. Then learn to perform data analysis in Microsoft Excel to measure your success.
1
LVL 4

Administrative Comment

by:Stacy Richard
Comment Utility
Published for Nicole
0
Nagios Core 4.3.4
Nsclient 4.3
Windows 10

Just restarted my Windows 10 Desktop VM after November Updates and Nagios reports this warning on two checks

 Error: Can't locate perl510.dll


Check Windows Temp Folder WARNING 11-14-2018 22:01:47 0d 0h 32m 58s 10/10 Error: Can't locate perl510.dll


Explorer WARNING 11-14-2018 22:28:58 0d 0h 33m 34s 20/20 Error: Can't locate perl510.dll

I have the exact same checks on other Windows 10 VMs and Physical Windows 10 Desktop and they all work

I have no perl program installed on any of y computers

Searching for this dll shows nothing any where.


Any ideas?
0
Hi, we have a gift certificate form. magickitchen.com/gift/gift-certificates.html  - cart is written in PERL,

In the amount window, if someone enters a dollar sign before the number, they get an error. Error: Invalid input for VALUE: $|$35|

Is there a simple way to remove the $ sign if someone enters it, as the form is submitted? Or is there another simple solution?

As an interim measure, I'll be changing the placeholder text. Thanks.
0
On a new RHEL 7.5 server, I'm trying to get mod_fcgid to run on a simple perl script. I had previously been using mod_perl on an older server, with no issues.  I have confirmed that fcgi_module is installed and running. Server is Apache 2.4.6.

httpd.conf:
AddHandler fcgid-script .fcgi

hello.fcgi:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "hello world";

Error log:
[Fri Oct 12 17:33:50.655808 2018] [fcgid:warn] [pid 13551] (104)Connection reset by peer: [client xxx.xxx.xxx.xxx:xxxxxxx] mod_fcgid: error reading data from FastCGI server
[Fri Oct 12 17:33:50.655891 2018] [core:error] [pid 13551] [client xxx.xxx.xxx.xxx:xxxxxx] End of script output before headers: hello.fcgi
0
Experts,

In a file I need to have the possibility to grep a pattern in the first or in the second column.  If found the entire line is returned.
Comes with it that that pattern is a variable.

Grepping the var in the first column is easy, but I can't get it to work for the second column (sep is >).

var=MSPROXML


MSUPDSEOT>MSPROXMLH
VSRFUMVTT>MSPROXMLH
FT0Y6600_T>MSPROXMLH
MSINSMSGT>MSPROXMLH
MSPROXMLT>XGGENEXTH
MSPROXMLT>CD0E0100_H
MSPROXMLT>FT0Y3600_H
MSPROXMLT>PC0R3420_H
MSPROXMLT>WO0A0020_H

This is what would need to be returned:

MSUPDSEOT>MSPROXMLH
VSRFUMVTT>MSPROXMLH
FT0Y6600_T>MSPROXMLH
MSINSMSGT>MSPROXMLH

Thank you for  your help.
Watnog
0
C++ 11 Fundamentals
LVL 12
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hi Everyone

I have a perl script and I have an array and am using a foreach and am looping many times to update an XML file.
There are 2 foreach loops in the script. The outer loop is the data and the inner is searching the XML file to add the data to the specific node.
I'm using the XML::LibXML to search and add.

My question is:

Once I use the element in the array I want to get rid of it to make the foreach loop execute faster as the array would decrease in size.

The program now runs 3 hours. It would be good to speed it up.

Is there an easy way to do this?

Thanks for the help

Mike
0
Hello Friends,

Is there any way to use floating point numbers in rrdtool? Some patch? Some RRDTool fork?

The reason for the question is that I would like to use the RRDTool to monitor balance / quote of cryptocurrencies...  For security reasons I do not want to use any existing tools for this... (yes, I'm a bit paranoid)  :)
0
In my current Perl script I want to modify a string that identifies my database RAC zone cluster.  Currently using:  nslookup `hostname` to get my fully qualified hostname.  However, this is not the name I need to use for my network administration HOST string in my "tnsnames.ora" file.  So, please help me modify this string:
   
       An example   dbserver01.dpsn.local  -->  need this string to be  dbzonecluster.01.dpsn.local

In general I will always want to replace what comes before the first '.' character in the file with some predefined string.  Can't figure out how Perl function substr would help, or something like  $myZoneClusterName =~ s/xxxxx/yyyy/g
0
My plan is to automate our current Database STIG Audit process.  I want to write a short Perl script to:

   1)  Read XML STIG File (i.e.  U_Oracle_Database_12c_V1R10_Manual-xccdf.xml)
   2)  Parse out all the STIG #s, with the accompanying SQL Query Statements
   3)  Write new ascii text output to new file

Please help me with Perl file example to do this parsing?
U_Oracle_Database_12c_STIG_V1R10_Man.xml
0
I had this question after viewing Unix AIX compare column of 2 files.

Hi Experts,
I try to make these lines work:

#!/bin/ksh
file1=file1.txt
file2=file2.txt
while read LINE ; do
FileSystem=`echo $LINE | awk '{print $3}'`
GrowthTreshold=`echo $LINE | awk '{print $5}'`
if [ "$GrowthTreshold" -ge 0 ] 2>/dev/null  ; then
echo $GrowthTreshold
perl -ane '$k=$F[0].$F[2]; print if exists($h{$k}) && $F[3]-$h{$k}>='$GrowthTreshold'; $h{$k}=$F[3]' $file1 $file2 >>ExceptionList.txt
else
echo ""$FileSystem" could not be checked"
fi
done <$file1.txt

###

I attach a file1.txt and a file2.txt

Values of file2.txt are compared to those of file1.txt
In this example:
- the first line is one that should be logged: 78 to 88 = 10 so that exceeds the allowed growth treshold of 5
- and also the last line: 34 to 40 = 6 so that exceeds of the allowed growth treshold of 5

When I run the script as it is now this is returned:

...
syntax error at -e line 1, near ">=;"
Execution of -e aborted due to compilation errors.


Thank you for your help.
Watnog
file1.txt
file2.txt
0
I'm trying to ingest a large text file into PostgreSQL Full details here

I may need to run  a script against the file to either remove the problem rows into a separate file, or insert into the database via DBI and was wondering how perl handles diacritics?

I'm sure perls native I/O file handle is UTF8 but not certain about the diacritics or non roman characters
0
Hi
I need to run multiple sql queries (These are built elsewhere in the script  with no possibly why of introducing SQL injection)

Rather than writing multiple prepare /   execute statements I thought about  using a foreach loop something like bellow but I get error
Use of uninitialized value $sql in concatenation (.) or string at main.pl line 19.

Any idea how I might do this?

use strict;
use warnings;
use  DBI;
my $dbi = DBI->connect('DB Connection string', {
    PrintError =>0;
    HandleError => "OH No!"}
)or print DBI->errstr;
# built elsewhare
my $Q1 = "insert into my_table 'ABC'";
my $Q2 = "insert into my_table 'EFG'";
my $Q3 = "insert into my_table 'XYZ'";

foreach($Q1,$Q2,$Q3){
   my $sql = $1; 
    print $sql . "\n";  # line 19
#    my $qa = $dbh->prepare($sql);
#    $qa->execute();
#    if(defined(DBI->errstr)){
 #       print DBI->errstr . "\n";
  #  }
}

Open in new window

0
Hello
I changed the top of the page from guestbook.html, addguest.html and guestlog.html
     <?xml version="1.0" encoding="iso-8859-1"?>  to   <?xml version="1.0" encoding="utf-8"?>
And also add
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
But some garbage value appears on the screen instead of Urdu ( Pakistani Language) .
Then I changed all encoding="iso-8859-1   to   encoding="utf-8" in guestbook.pl but same garbage value appears on the screen instead of Urdu.
nms-guestbook is very attractive and I want to use it, so please help me.

 kindly check this link http://www.punjabiandpunjab.com/guestbook.html
Thanks
0
<FileDetails>
 <FileName>abcd<1234</FileName>
 <FileSize>10KB</FileSize>
</FileDetails>

how to parse this in perl
0
Why Diversity in Tech Matters
LVL 12
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

how to compile 64 bit version of libperl.a from perl 5.28 source code on solaris.

Tried with -fPIC while configuring. But, no luck.
0
hi,

I am setting up the first MySQL cluster and I need to install the auto install rpm first, but that one said it depends on community server rpm first, which asking for the client to be install, but when I install the client it complain:

when installing MySQL client
so how can I get ride of that error when installing the client?

what is perl (Class::MethodMaker) ? how to install it?

I download all component from https://dev.mysql.com/downloads/cluster/

and now the files list is:

MySQL  Cluster binary downloaded.
anything missed?
0
Hi experts,

Need help on how to convert a string of values in both 2nd and 3rd fields that are actually Date and Time in GMT and then calculate the difference in seconds.
Preferably using the following scripting methods:  BASH or PERL

Sample source file in CSV:  inputfile.csv

Label,StartDateTime,EndDateTime,status
info01,20171231155000,20171231161000,complete
info02,20180101023025,20180101024045,complete
info03,20180430222210,20180430223002,complete
info04,20180612113050,20180612113502,complete

Open in new window




===============================================================================================

Required Output File: Start and End Date/Time in GMT+8, plus the Date/Time difference or Duration (in seconds) inserted as a new column (4th field)

Output CSV File:  outputfile.csv

Label,StartDateTime,EndDateTime,Duration(Seconds),status
info01,20171231235000,20180101001000,1200,complete
info02,20180101103025,20180101104045,620,complete
info03,20180501062210,20180501063002,472,complete
info04,20180612193050,20180612193502,252,complete

Open in new window

0
I'm migrating my website to a secure server, and a certain cgi script is not being found when it is needed.  I've attached an excerpt from the server's error log, specifying what happened.  I don't know how to interpret this error log text, or how to remedy the issue.  The script which isn't being found is properly situated in the cgi-bin folder.Error-loading-SecureForm.txt
0
Hello,

A cgi script that was functioning properly when accessed via IP address, is currently not working when accessed via domain name (now that the nameservers have propagated.)
Instead it is producing a message to open or save the cgi file.

I have checked the scripts in cgi-bin and the permissions are all correct 755.

Thanks for your help.
0
Hi

I have 2 arrays and in one there is data that matches the x lines that are in the other array.

how can I delete the data that matches exactly from the other array.


@A = qw ( AA,
                   BB,
                   DD,
                   CC,
                   DD,
                   EE );

@B = qw( DD,
                  EE );




So I need to delete the DD,EE from @A. And in that order of DD,EE.


Thanks

Mike
0

Perl

26K

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.

Top Experts In
Perl
<
Monthly
>