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

I have the code below, which generates the error message:

#Global symbol "%lines" requires explicit package name at 002comparitor.pl line 20.

Could you explain how I can solve this error please ?

code:

#!usr/bin/perl

use strict;
use warnings;

my $fil = shift; # command line argument is the file to read lines from

open (INPUT,"<C:/Users/mickg/Desktop/Lessons/comp/master.txt") or die "can not open INPUT";
open (MATCH,"<C:/Users/mickg/Desktop/Lessons/comp/match.txt") or die "can not open MATCH";
open (NONMATCH,"<C:/Users/mickg/Desktop/Lessons/comp/nonmatch.txt") or die "can not open NONMATCH";


my @lines = map { chomp; $_ } <INPUT>;


while (@lines > 6) {
   
    # check first 5 lines against the 6th line
    my @match = grep { $_ eq $lines[5] } @lines[0..4];
    my @nomatch = grep {$_ ne $lines[5] } @lines{0..4};
   
    # do whatever you want with the matches and no-matches
   
    print MATCH @match;
   
    # get rid of first line so next loop will be 2-6 and so on
    shift @lines;
   
}

close (INPUT);
close (MATCH);
close (NONMATCH);
0
JavaScript Best Practices
LVL 13
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

I do not know much about programming.

What is the best way to write the contents of an array to a text file, with a space between each item in the text file ?

using PERL.
0
I know very little about programming.

Could you please help me with code that will read 5 lines of a file, and compare the contents of these five lines to the sixth line, entering the values which match and those that dont match into separate arrays ?

so, eg, reading lines 1-5, compare all values with those in line 6, then reading lines 2-6 and comparing all values with those in line 7, and so on..... each time entering the values that match and those that do not into two separate arrays.

thankyou
0
Could anyone tell me please why this code does not list the files *.pl in my directory ?

#!/usr/bin/perl

$source="C:/Users/mickg/Desktop/PERL Lessons/*.pl";

@list = glob($source);
$size=@list;


print "total number of files in the directory: $size\n\n";


foreach(@list)
{
	print substr($_,38) . "\n";
}

Open in new window

0
I keep getting this error: Can't call method "desiredCompressionLevel" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/Archive/Zip/Archive.pm line 249.

Here's the code (which seems to work right up to "$questionaire->addFile($doc)").  Is there a spot I'm missing where the Compression Level is declared?

    my $who     = 'FORM_LETTERS~CHANGE_BILLING_TO_15TH.doc~ml1/pacific/stpac/repac/aj359,FORM_LETTERS~LETTER_OF_ERROR-_POLICY.doc~ml1/pacific/stpac/repac/aj359';
    my ( @docs )   = split /,/, $who;
    $file       = 'ml1/pacific/stpac/repac/aj359/Questionaire.zip';   #  WRITE-TO FILE THAT WILL BE SENT TO USER

    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
   
    my $questionaire  = Archive::Zip->new();  #  NEW INSTANCE

    #
    #  GET THE FILES TO CONSOLIDATE
    #
    foreach my $doc( @docs ){
        $questionaire->addFile( $doc );
    }
    $questionaire->writeToFileNamed("$file");

    #
    #  EXPORT ZIP FILE TO USER
    #
    print "Content-Type:application/x-download\n";
    print "Content-Disposition:attachment; filename=$file\n\n";
    print $file;
0
Our team typically uses Perl in our Solaris Oracle database environment.  We need a Perl script, that will receive parameter, such as, “-keep 30, -keep 60, -keep 90”.

Script called (example):  CleanUpOraDbFiles -keep 60
 
Also, PERL script will move gzip up files older than 60 days, and move to a larger file share of the filesystems. Need good example what this script would look like.  Looking to archive-off ( listener.log, audit logs, alert logs, etc.. )
0
This script isn't pinging the servers.  I know $serverlist is getting populated because I'm able to print them.  It's not throwing any errors, it just doesn't do anything.  It looks like this "$p->ping($server)" isn't working.


#!/usr/bin/perl

use warnings;
use strict;
use v5.10;
use Net::Ping;

my $serverlist = `grep Solaris /usr/global/bin/masterfile|grep Active|grep -v ^#|cut -d: -f1|sort`;

for my $server ( "$serverlist" ) {
        chomp( $server );
        my $p = Net::Ping->new();
        if ( $p->ping($server)) {
                print( "$server is alive\n" );
        }
        $p->close;
}
0
I'm having a problem with looping through lines in a variable.  When I run the code, there's a test "print" to make sure I'm getting all I want, but then when I print the command that I want to run, it's not using the $line variable. Here's the piece of code I run:

for my $line ( $servDescUser ) {
        print( "$line\n" );    # <-- This works correctly
        print( "\n" );
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=group:$servDescGrp\"` ");
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=shadow:$line\"` ");   # <-This works on the first $line
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=passwd:$line\"` ");   # <- This works on the first $line
}

Here are the results:

ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=GlobalUnix,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=Storage,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=TSM,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=BMC,ou=dynGroups,dc=ipaper,dc=com


`ssh unxgen01 ldapclient mod -a "serviceSearchDescriptor=group:cn=*,ou=Groups,dc=ipaper,dc=com
"` `ssh unxgen01 ldapclient mod -a "serviceSearchDescriptor=shadow:ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=GlobalUnix,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=Storage,ou=dynGroups,dc=ipaper,dc=com
0
I have this line, which works fine in ksh.

 ssh $lserver "su - oudadm -c 'nohup ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep uid'"

How can I rewrite this line Perl.  I'm trying to convert this ksh file to Perl.  I've tried several ways, but haven't found one that works. I've tried this:

system( "ssh $lserver \"su - oudadm -c ;nohup ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep $userid\"" );

and this:

system( "ssh $lserver ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep $userid" );




Thanks,
David
0
What's the best way to print a numbered list from an array?    Let's say I have this in an array:

DBA
HEWITT
INETSVC

I want to print it like this with an option of the operator choosing a number to make a selection:

1) DBA
2) HEWITT
3) INETSVC

Thanks!
David
0
Learn SQL Server Core 2016
LVL 13
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Hello all,
I have a directory on my macOS that every single name has a .dns at the end if it. for example:
PPPDDC3_0.31.172.in-addr.arpa.dns

Is there a sek, awk, perl or something I can run to remove the .dns file extension and leave it at
PPPDDC3_0.31.172.in-addr.arpa
I dont care about preserving it, just change it all

They are located in this type dir structure
/work/CTS/PPPDDC3-Export

Thank you,
Rich
0
Hello Experts -

I have a PERL script on a Linux server which I use to do a one-way sync of data from one system to another. The process takes about nine to 12 minutes to complete. Currently I have a cron job that runs the sync script every 20 minutes, but I'd like to decrease that time frame so I can get as close to continuous as possible without having runs overlap. What would be the best approach for this?

1) Set up a cron to run the script every minute and at the start of the script see if there is another invocation currently running and die there if there is?

2) Put the whole script in to a giant loop which will run forever?

3) Something else?

I'm guessing #1 is the best option. If so, what's the best way to check to see if a copy of the script is running?

Thanks in advance for any help/guidance,
-matt
0
Hi expert

good day

Is there any example for reference that was generate in perl script to capture patching result or generate report.  

such as capture result to capture for the folowing;

Get yum report for Errata info - yum list-sec --security

Get yum list update packages-- yum list updates --security

exclude in vi/etc/yum.conf ( to get information before patch)

yum list-sec --security

yum list updates --security

Get List of updates packages

yum list updates --security

Get installed packages

yum list installed

Get Errata CVE and relate info

yum updateinfo info --security |grep "Update | D\|CVE\|Severity"

The end result will show in the attachment.
Patching-report-sample.xlsx
0
Would like to add this to my existing PERL script.  Project created mapping between a Manufacturing release version and a Business release version numbers.  Based on the Manufacturing release database schema file .e.g. db_AB_17.43.03, I want to map this back to the business version.  So, given the file “db_AB_17.43.03” I want to get the Business version.  All of this is laid out in a directory hierarchy like the following.

Window Directory hierarchy structure:

CM  
        Bus-Version  --  
                Manurf-Version    
                                           DB         db_AB_17.43.03
0
I am developing a marine position database system in Perl on a Centos 6.5 server.
Users can email position reports to my system.  
My Perl script automatically processes each position report email, and sends a reply email back to the sender, acknowledging receipt of their position report.
I have also been working with the Garmin inreach explroer iridium messenger for position reporting.
I can easily configure the Garmin to send an email to my system, and my system can process the email with the position information without any problems, and store the information in my database.   This works great, but I can not send a reply back to the Garmin acknowledging receipt of the Garmin position report.
Sending the reply email to an alternate email address does not work if the sender is remove, and does not have access to email.
I need to send reply message back to the Garmin as an sms text message from an SMS phone number address.
To configure this, the Garmin would need to send the position report as an sms text message to my system, and  my system would need to reply back to the Garmin with an sms message.
The Garmin inReach Explorer can send 160 character messages to either an email addresses or to ans sms cell phone number.
Because Garmin charges for sms and email text messages, Garmin blocks all direct emails to the Garmin inReach Explorer.
Garmin will accept an sms reply message to the Garmin.
Because of this logic, I would like to find a way to send and receive …
0
Hello,

I am running into some limitations (...by design) with the XenCenter and Xenserver (Citrix Hypervisor) the issue I am facing is that when I am using GFS2 with the shares storage drives the XenCenter (mananagement console) doesn't seem to calculate the free space that's available for that particular shared storage drive.

That being said, I am looking to get some assistance writing a quick script to check the available space on a drive or file system and email if the system free space is below 20%. I will run the script a chron job every hour.
0
i'm trying to learn how to use Switch in a perl program.  i get the error "can't locate Switch.pm in @INC(you may need to install he switch module)"
how do i install switch properly?

 #!/usr/bin/perl -w
# try to compare an input string to my name
 
use strict;
use 5.010;
use warnings;
use Switch;
 
say "what is your name";
my $fn = <STDIN>;
chomp ($fn);
say "your name is $fn";


switch ($fn){
    case "dan"      {  say "How are you doing today Danny?"}
    case "donna"    {  say "How are you doing today Donna?"}
    else            {  say "get off me"                    }
}

Open in new window

ex2018_05_08.txt
0
Please recommend a Perl script that will return the latitude and and longitude for an address.
Please explain the pros and cons of signing up for a google api account to use their geo code api.
Are there any alternatives to google for obtaining a latitude and longitude for an address ?

Thanks,
Jim West
0
Hi, I am using a perl script to connect to my IMAP server and retrieve my unread messages. I am using Net::IMAP::Simple .. when I find an unread message, I get a full copy of the message. Here is part of my script:

for $i (@mylist) {
$msg = $server->get( $i );
print "Message Number $i contains:\n";
print "$msg\n";
$ret = `rm -f /tmp/msg.txt`;
open(TMP,"> /tmp/msg.txt");
print TMP "$msg";
close TMP;
$line1 = `grep "Subject: " /tmp/msg.txt`;
chomp($line1);

Open in new window


I can see the attachment in the "$msg" .. but this is what the attachment looks like:

Content-Type: image/jpeg; name="20190421_132835.jpg"
Content-Disposition: attachment; filename="20190421_132835.jpg"
Content-Transfer-Encoding: base64
Content-ID: <16a45e7d6e23c578d131>
X-Attachment-Id: 16a45e7d6e23c578d131

Content-Type: image/jpeg; name="20190421_132835.jpg"
Content-Disposition: attachment; filename="20190421_132835.jpg"
Content-Transfer-Encoding: base64
Content-ID: <16a45e7d6e23c578d131>
X-Attachment-Id: 16a45e7d6e23c578d131

Open in new window


The data for the JPEG follows after that.

I just downloaded that script to take a look at it. It is not doing exactly what I need to do, and the script has no documentation on how to use it and run it

What I'd like to do is to modify my script so that any attachments are downloaded into a folder.

Thanks!
0
Angular Fundamentals
LVL 13
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

I'm having some issues to get the values I need from some hash or hashes

I'm using a module of:
        use JSON qw( decode_json );
Then get a return of a reference using
       my $decoded = decode_json($json);

From the data structure I have in $decoded I need to get the values for
skuPartNumber
servicePlanName

But not getting the format right to pull these values.

Attached is an example of what the data structure looks like printing it out with Data Dumper

Can someone please show me how to pull these two values out.
test.txt
0
i have a text  file. it looks like:
==================================
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................

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

how do i open the file of names of people in a cemetery and return the text that goes with  ONLY that name in perl?
the file is a list of about 3000 people and the text is when they died and where they are buried.  any language will do
this but i'm trying to learn perl in ubuntu.
0
Hi
I have an unquoted CSV file that also has columns / cells with comas in
I need to fix it prior to ingesting into a database (This is it, it can't be generated properly)
 
I've wrote a short perl script isolate the rows with too many columns outputting the deliminator as a '|' pipe
I now need to edit the rest

Bringing the file into excel or open office calc can help to work out where the problems with each row is because you can see patterns in the data BUT totally messes up formatting like leading zeros and dates

Using a plane text editor keeps this formatting but is sole destroying looking at 100's lines of CSV data comparing with the spreadsheet  and error prone

Any one know of a CSV editor that can do both?

In 1 pane have an text /CSV editor  and as the deliminator  is removed or added dynamically updates a spreadsheet like interface so you can see instantly the column data lines up
0
Hello,  I have a perl script that I need it to look into a directory named mpl.  right now I run it but it does it for one file at a time. Sucks cause There are a few hundred. So If I can seek hellp to make my perl script open a whole directory and do what it does per one file but in a whole directory.

I need my script adjusted  to look into my directory mpl and read all the zonefiles and change the serial number using date with an extra number 2019011300 ; serial for example

I run the script like this on the below:

./zonechanges.pl db.apptoapp.net.new vipchange

Copy of the script:

#!/usr/bin/perl

open(ZONE,  $ARGV[0]) || die "Zone file error $!";
while ( $line = <ZONE> ) {
        chomp $line;
        push @fileLines, $line;
}
close ZONE;



# Assuming simple CSV of old_ip, new_ip
open(IPMAP, $ARGV[1]) || die "IP Map file error: $!";
while ( $line = <IPMAP> ) {
        chomp $line;
        ($old, $new) = split(/,/, $line);
        $old =~ s/\s+//;
        $new =~ s/\s+//;
        $ip{$old} = $new;
}
close IPMAP;


## For every line
for ($count=0; $count < @fileLines; $count++) {
#       print STDERR "OUTER FOR ($count)\n";
        $line = $fileLines[$count];
#       print STDERR "OUTER FOR have line $line\n";
        ## For every old address in the remap
        for $old (keys(%ip)) {
                #print STDERR "INNER FOR ($old)\n";
                ## If the line matches the old address
                if ( $line =~ /$old/ ) {
                       

Open in new window

0
I ran a web app on a EC2 instance, which is using port 3003. But it  cannot be accessed from external network

With logged in with SSH, I curled 'localhost:3003', then response returned as expected.

WAF: Mojolicious
App start command: morbo "http://*:3003" myapp.pl

This is obviously insufficient configuration on web server, but I don't know how.

I am grateful if you could advise me.
0
i'm using ubuntu 18.04 and i am trying to learn perl and get a window to appear like visual studios where i can create buttons and drop-down boxes, etc and i cannot seem to gt it installed.  i used https://www.perl.com/pub/2001/03/gui.html/ and i cannot get their examples:ptked and ptksh to execute.  these are listed in the paragraph right above: pTk Core Concepts.  is there a better example or do you see what i'm missing?
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.