We help IT Professionals succeed at work.

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.

Hi

I need to convert MGRS coordinates into digital Latitude Longitude

The metacpan module Geo::Coordinates::UTM  achieves this  by

($latitude,$longitude)=mgrs_to_latlon(23,'30VWK1254306804')

Open in new window



However if the MGRS coordinates  are incorrect it fails by crashing the script

How do I test the  MGRS coordinates prior to conversion? without killing the script but report error to user

Tried this but still crashes
if( ($latitude,$longitude)=mgrs_to_latlon(23,$mgrs) ){
  ## Do something with $mgrs
}
else{
 print "$mgrs incorrect in $InputDoc\n"
}

Open in new window



BTW I need to test all the  MGRS coordinates within the In put Doc so I can report it to the user
0
Given the code snippet bellow  I need to extract each Place Name & Coord string

There might be zero 1 or many however I can't be sure what the delimiter will be when there are multiple the two samples are either  a comer or semi colon
I do know
 Place Name (Coord string) are in this format

print "Hello World!\n";
my @examples=("Place Name (Coord string )","Place Name2 (Coord string 2);Place Name3 (Coord string 3);Place Name4 (Coord string 4)","Place Name5 (Coord string 5), Place Name5 (Coord string 5),Place Name6 (Coord string 6)","Not Wanted");

foreach my $example (@examples){
    if($example =~ m/(.*)\((.*)\)([,;])?/g){
        
        my $Place =$1;
        my $Coord = $2;
        
        # do stuff with each
        print "$Place  $Coord\n";
    }
    
}

Open in new window



I thought about splitting on the delimiter then pushing into an array which might work for multiple but seems to fail for single
0
Hi

I have a string of text that should have 1 or more sub string inside brackets whats the best way to extract each wanted sub string, I then need to do stuff with each of these

The code bellow only grabs the first "Wanted"

print "Hello World!\n";

my $text = "Lorem ipsum dolor sit amet,(Wanted 1) consectetur adipiscing elit. (Wanted 2) (Wanted 3) Nunc bibendum ante diam, a imperdiet purus (Wanted 4) faucibus a. Pellentesque ultricies nibh.";

my @WantedText;
if($text =~ m/\((.*?)\)/ )
  {
     push @WantedText, $1;  
  }
  
  foreach my $want (@WantedText){
      
      print $want . "\n";
  }

Open in new window

0
Hello,
I've a little script that processes csv tab-delimited files and outputs other csv modified following our needs.

The script (called arch.pl)  is the following:

#!/usr/bin/perl

# open(FD_IN, "<STDIN") || die "Errore apertura standard input";
while (<STDIN>) {
	$Riga = $_;
	$Riga =~ s/\n//;
	$Riga =~ s/\r//;
	@Campi = split("\t", $Riga);
	#eliminazione di cragna importata da filemaker
    $Campi[1] =~ s///g if ( $Campi[1] ne "" );
	$Campi[4] =~ s///g if ( $Campi[4] ne "" );
	$Campi[5] =~ s///g if ( $Campi[5] ne "" );
	
	#eliminazione di spazi bianchi iniziali e finali
	sub  trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
	    for (my $i=0; $i <= 9; $i++) {
       $Campi[$i] = trim($Campi[$i]);
    }
	#tengo solo la prima lettera della sezione
	$Campi[7] = substr($Campi[7], 0, 1);
	printf("\"".$Campi[0]."\"|\"".$Campi[1]."\"|\"".$Campi[2]."\"|\"".$Campi[3]."\"|\"".$Campi[4]."\"|\"".$Campi[5]."\"|\"".$Campi[6]."\"|\"".$Campi[7]."\"|\"".$Campi[8]."\"|\"".$Campi[9]."\"\n");
	$cntRecord++;
}
# close(FD_IN);	

Open in new window


now the script is called in console via:

> perl arch.pl<input.csv>output.csv

Open in new window


the question is: can I embed this code in a .cgi web page and pass to it the input.csv with an upload file form?
0
hello,
I've a txt file with some (1158 records) registry data on the form:
object(stdClass)#2 (1) { 
	["GetAnagraficheOrdineResult"]=> object(stdClass)#3 (1) { 
		["DtoAnagraficaDataWeb"]=> array(1159) { 
			[0]=> object(stdClass)#4 (81) { 
				ARRAY_MEMBERS
				}
			[1]=> object(stdClass)#5 (81) { 
				ARRAY_MEMBERS
				}
			......
			[1158]=> object(stdClass)#1162 (81) {
			ARRAY_MEMBERS
			}
		}
 
	}
}

Open in new window


Where ARRAY_MEMBERS has the structure:
["Field_description"]=> field_type "field_value"

Open in new window

i.e.
["ProfNome"]=> string(9) "John"
["ProfCognome"]=> string(5) "Doe"
["ProfLegalMail"]=> string(32) "john.doe@mail.com"

Open in new window

...etc...

I'd like to have a perl script that -once launched from the console- loops over all the 1158 records and construct 1158 lines contained ONLY the field_value of some selected field_descriptions "comma separated", i.e.
('Doe', 'John');

Open in new window


Thanks,
Fabiano
0
Q1:
Without TCL/Expect script, can someone provide  a Shell/Perl script  or way to automate changing of a couple
of Solaris account passwords every 60 days?  This is for nagios (& a couple other) Solaris accounts which we
have to auto-expire but we can't afford to miss, else the expired password would cause service disruption.
Passwd, usermod or RHEL's chage can't read input from a file, thus I've not been able to find a Shell/Perl
script to do this.  However, we don't want to install TCL/Expect in our Solaris 10.

Q2:
if we use sed or awk to change the 'hashed' password field of /etc/shadow,  would Solaris (or even RHEL)
deem the password has been changed or UNIX will still deem it's not changed yet as we're editing the
shadow/passwd files directly instead of using commands like passwd/usermod/chage to change
0
I have reformed a previous question.

I have this input data

1 2 3 4
1 2 3 5
1 2 4 6
1 2 3 4
1 2 3 5
1 2 4 7
4 6 3 9

I need code that will read the first five lines of this data, and compare all values found with those values in line 6. So that the output (to output.txt) is;

match:
1 2 4

no match:
7

- then for the code to move on and do the same for lines 2-6 with line 7, so the output file would read

match:
1 2 4
3 4 6

no match:
7
9

and so on down through my data.
0
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
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
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

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
>