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
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
Cloud Class® Course: Certified Penetration Testing
LVL 12
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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 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
I have some forms in some Perl CGI scripts, having an issue to get the values from the boxes that is checked.

In the example below, this will print all entries that is in an array with the boxes checked when displayed on the web page, what I need to do is have the user "uncheck" any values that is no longer needed then I can remove them as needed.

The problem is I'm not able to get the values of them or which ones has the checkbox unchecked. I've tried using the CGI "parma" to put them in an array but not working probably because I return the boxes to display in $Return.

 
if ($currentAdminType) {
    if (scalar(@{$userDetails{'admintype'}})) {
      # checkbox list to deselect item
      $Return.="Uncheck the appropriate checkbox to delete particular value<br />\n";
      foreach $Value (@{$userDetails{'admintype'}}) {
        $Return.="<input type=checkbox name=type checked value=\"$Value\" />".
                 "$Value<br />\n".
                 "<input type=hidden name=type value=\"$Value\" />\n";
      }
    } else {
      $Return.="Attribute is blank, so cannot be modified\n";
    }
}

Open in new window


The code will display the values with all having a checked box, to print to the web page I then pass $Return to a small sub that prints the page as needed.
Any help on how to get these values would be much appreciated.
0
Hi

I have a multidimensional hash slimier to bellow

How do I count hash sub keys?

Do I have to loop though the hash first?

my Actual data looks a bit like this
$HoH{$PolyNum}{$GroupNum}{$PointNum}={ Long=>$Long, Lat =>$Lat, Etc=>$ETC};

Open in new window


Due to data coruption I can't rely on PointNum I have to count them so I need to know how many points are in each GroupNum so I know if its a point (1), Line(2) , or Polygon(>2)  so I can process accordingly
I Know you can have more than 2 points on a line but this data does not

In the test bellow I get "Experimental keys on scalar is now forbidden at main.pl line 38."

use strict;
use warnings;

print "Hello World!\n";

my %hash = ( "barney" => "dinosaur", "elmo" => "monster");

# this works 
print  scalar keys %hash;
my %HoH;

$HoH{4}{ mash } = {
    captain  => "pierce",
    major    => "burns",
    corporal => "radar",
};

$HoH  {1} {flintstones} = {
        husband   => "fred",
        pal       => "barney",
    };
$HoH  {2} {jetsons}=  {
        husband   => "george",
        wife      => "jane",
        "his boy" => "elroy",  # Key quotes needed.
    };
$HoH  {3} {simpsons} = {
        husband   => "homer",
        wife      => "marge",
        kid       => "bart",
    };
  
  for my $num (sort keys %HoH){  
        for my $TV (sort keys %{$HoH{$num}} ){
print "\nNum keys $num " . scalar keys $HoH{$num}{$TV};
}

Open in new window

0
Hi all,
I have one Mysql 5.6 that has been installed in windows server 2012.  When I tried to run mysqldumpslow, the command not able to found the executable, how do I get this command added into Mysql in windows ? FYI I have installed active PERL  and in teh PERL Package Manager I can't find the package that contains this Mysqldumpslow.
0
The below code snippet  generates a extra "," at end of each line.
The first line prints out without the comma at end of line. The extra "," occurs from second line onward..

How to prevent the trailing , ?

      
my @allrows;
      my @columns;
      my $getfilename = join '', $partition_key,'.csv';
      my $rc  = $genextract->fetchrow_hashref() or $nodata = 1;
               my @row = @{$genextract ->{NAME}};

      foreach my $col (@row) {
          my $name = $col;
          $name =~ s/\s+//g;
          my $data = $rc->{$name};
          push @allrows, $data;
          push @columns, $name;
      }
      my $dumpdir = "$wkdir/RECgen_$getfilename";

      open (OUT, ">$dumpdir") or die(" - Could not open $dumpdir for export. $!");

      # List out all the columns/rows with header information and generating a csv outfile..
      $" = ",";
      print OUT "@columns\n";
      print OUT "@allrows\n";

      while (my $row = $genextract->fetchrow_hashref()) {
      
        foreach my $col (@columns) {
     
           print OUT $$row{$col},",";        
        }
        print OUT "\n";
      }
      close(OUT);

Open in new window



output given
10/01/2015,0784626443000,ACACIA,ACACIA_UNIT_1,BRYAN SOLAR LLC (RE),RN,80.743461
10/01/2015,0432268853000,AUSTPL,BOULDERPL_DENV2,LOWER COLORADO RIVER AUTHORITY (RE),OS,7.656099,
10/01/2015,930187393,AV,AV_DG1,TX LFG ENERGY LP (RE),RN,94.34616,
10/01/2015,0791659493000,BAFFIN,BAFFIN_UNIT1,BAFFIN WIND LLC (RE),RN,101.595611,
10/01/2015,0791659493000,BAFFIN,BAFFIN_UNIT2,BAFFIN WIND LLC (RE),RN,110.031439,

Open in new window



EXPECTED OUTPUT
10/01/2015,0784626443000,ACACIA,ACACIA_UNIT_1,BRYAN SOLAR LLC (RE),RN,80.743461
10/01/2015,0432268853000,AUSTPL,BOULDERPL_DENV2,LOWER COLORADO RIVER AUTHORITY (RE),OS,7.656099
10/01/2015,930187393,AV,AV_DG1,TX LFG ENERGY LP (RE),RN,94.34616
10/01/2015,0791659493000,BAFFIN,BAFFIN_UNIT1,BAFFIN WIND LLC (RE),RN,101.595611
10/01/2015,0791659493000,BAFFIN,BAFFIN_UNIT2,BAFFIN WIND LLC (RE),RN,110.031439

Open in new window

0
Cloud Class® Course: Microsoft Office 2010
LVL 12
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

I get an error on my script on line 47, which outputs few database columns to a file.  Attempting to alias to_char(starttime...) as studdate (student date) but it fails with an error - invalid identifier. How do I resolve the error?  

I am trying to have file output column as Studdate and not "TO_CHAR(STARTTIME 'MM/DD/YYYY')".

Line 47
do_dataset($timeparm,'_STUDLOC_', [qw(STUDNAME STUDCODE TO_CHAR(STARTTIME 'MM/DD/YYYY')  "STUDDATE" TOTALS)], status => "'N'");

Open in new window




Here's the complete script ...
use strict;
use warnings;
use DBI;
use Date::Manip;
use File::Path;

Date_Init('TZ=US/Central','Internal=1');

$| = 1;

my ($db, $user, $pw, $wkdir, $firstday, $lastday, $timeparm)  = @ARGV;


#Check to see if required parameters are received by appworx
unless($db && $user && $pw && $wkdir && $firstday && $lastday && $timeparm)
{
  die("\n\n  - ERROR:  The Required number of arguments were not received.  Verify that the AppWorx prompts are correct and reset the module..\n\n");
}

# Connectivity check to the database else display failed connectivity
my $dbh = DBI->connect("dbi:Oracle:$db", $user, $pw, { AutoCommit => 0, RaiseError => 1 }) or die("Cannot connect to Database '$db' " . DBI->errstr());

# Create the directory passed in by appworx in event the directory does not exist, do nothing if the directory already exists
mkpath("$wkdir");
 
my $partition_key = join '', $firstday ,'_',$lastday;
print("Partition Key : $partition_key \n\n");


my $sthcounts

Open in new window

0
Hi

Can anyone see why this errors on the regex?
I'm assuming it's to do with the '#'

use strict; use warnings;
use HTML::TreeBuilder;
use HTML::Element;

my $Base = "H:\\Path\\To\\";
my $Sub = "Sub Folder needs changing 123456 ";

my $body =HTML::TreeBuilder->new_from_file(*DATA);
my @DIVs =  $body -> look_down('_tag', 'div');  
for my $div (@DIVs){
    my $id = $div->attr('id');
    if((defined($id)) && ($id=~m/post_message_(\d.*)/)  ){
        my $PN = $1;
        print "ID = $id PN = $PN\n";
        my $Fold = $Base . $Sub . $PN;
        if(-d "$Fold"){
            print "HeLlo $Fold\n";
            }
        else{
              print "Can''t find $Fold\n";
            }
        
        my @font = $div-> look_down('_tag', 'font', 'color', 'red');
        for my $ft (@font){
        my $FText = $ft ->as_trimmed_text;

### this errors with Global symbol "$FTest" requires explicit package name at 
        if($FTest =~ m/(.*\#\d*)\s/  ){
            $FText =$1;
            } 
        print "FText = $FText\n";
            
        }
    }
}
  
print "Finished \n";

__DATA__
<div class="postbody">
<div class="postrow has_after_content">
<div class="content">
<div id="post_message_30829574">
<blockquote class="postcontent restore ">
<div style="text-align: center;"><i><b><font color="red"><font size="5">I want this #123456 but not this</font></font></b></i><br />
<br />

Open in new window

0
In this snippet of code:
printf("<email preferred=\"true\">\n") if ( $Campi[0] ne "");

Open in new window

I should add another condition:
if $Campi[0]  does not begin with ">>"
I've tried something like
printf("<email preferred=\"true\">\n") if (( $Campi[0] ne "") OR ( $Campi[0] !~ m/^>>/=true));

Open in new window

but without luck
Thanks,
Fabiano
0
Need Perl script to assist with the following:  I need to modify a configuration parameter file based on the environment it is to run on.  Ninety-eight percent of the file is static and does not change.  One definition is missing, and the hostname needs to be updated based on the environment configuration; other than that the file is static.  My plan is to use a file template, whereas 99% of the file is exactly as it should be and good to go; and then use a tag, i.e. “<hostname>” to denote what my global substitution.  I would like to read in my Oracle database network configuration file and updated it with added entry plus the actual hostname based on the host the script will be executed on.
0
replacing parts of a line in a file (/etc/group).

If I have the following line in my group file, I want to remove all of the "sdb" entries, but leave anything else.  For instance:

sdba::1014:sdb,sdb,david,sdb

would need to be changed to:

sdba::1014:david

I'm trying to do this with perl -pi -e if I can.  This SORT of gets me there, but removes the "david" entry.

egrep "^sdba:" $TEMP && perl -pi -e "s/^sdba::.*/sdba::1014:/g" $TEMP

Thanks!
David
0
Hi, Dear Experts
I've made a simple script with two calls to the CURL command:

#!/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);

		
	system("curl -X POST  -H \"Content-Type: application/xml\" \"https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&department=BIB1PETFSCATFLO&work_order_type=CATFLO&done=true&apikey=xxx\"\n");
	system("curl -X POST  -H \"Content-Type: application/xml\" \"https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&circ_desk=DEFAULT_CIRC_DESK&done=true&apikey=xxx\"\n");

	$cntRecord++;
}

# close(FD_IN);

Open in new window



The script runs as:
perl script.pl<input.csv>output.txt
I need a quick way -inside the script- for formatting the CURL output registered on output.txt

Thanks a lot,

Fabiano
0
I am having the below parameters called in from a command line and using the param $timeparm in my script.  

my ($db, $user, $pw, $wkdir, $firstday, $lastday, $timeparm)  = @ARGV;

Open in new window


The script has a condition check based on  value of $timeparm and the outfile generated has a concatenation and writing the file to a  ooutput directory "outdir".

However, the code snippet below gives an error on Line 9 states as
"global symbol $getfilename requires explicit package name at......"

I can get past the error by using a declare of the  my$ getfilename prior to the if statement, but that will cause the filecontatenatio to be incorrect.

How do I resolve the error and get the expected answer for getfilename?


if (lc $timeparm eq 'yearly') {
		  my $filedate = substr($firstday,0,4);	#example of the value here is YYYY or 2018 	
		  my $getfilename = $timeparm.$file.$filedate.'.csv';	#getfilename expected is = 'yearly_sales_2010.csv"   
		 } else {
			my $filedate = join '',substr($firstday,4,2), substr($firstday,0,4); #example of value here is MMYYYY or 012018
			my $getfilename = $timeparm.$file.$filedate.'.csv';	#getfilename expected is "monthly_sales_012010.csv"
		}

 my $outdir = "$wkdir/$getfilename";  # the error occurs on this line..

Open in new window

0
I am migrating a website developed in PERL from one ISP to another. This is not proving to be a straight forward exercise - I think I have jumped through most of the hoops but have one that I am not getting anywhere with.

(Disclaimer: I did not write the code - I am just doing someone a favour moving their site)

In the index.pl there is this line of code
print $q->redirect('group_admin/clients.pl');

Open in new window

$q is defined as follows
#!/usr/bin/perl

use strict;

use CGI::Carp qw(fatalsToBrowser);
require '/home/domain/public_html/myconfig.conf';
&start();

sub start() {
	my $q = new CGI;
	my $e = new MyConfig($q);

	if( $e->manage_session() ) {
		&display($q, $e);
	}
	return 1;
}

sub display() {
  print $q->redirect('group_admin/clients.pl');
  ....
}

Open in new window

The effect of the above is to output the following to the browser
Status: 302 Found Location: group_admin/clients.pl

Open in new window

In the response these are over two lines
Status: 302 Found
Location: group_admin/clients.pl

Open in new window

In other words the page does not redirect.
If I manually enter the URL to group-admin/clients.pl the correct page loads.

What have I missed that is causing the redirect to fail?

NB: This code base works as is on the current server.
0
In reference to https://www.experts-exchange.com/questions/29079671/How-to-generate-multiple-files-from-a-perl-script.html
The related question was assisted by wilcoxon and his expertise on Perl!



For the files from the do_dataset, how would I append the below to the end of the files generated from the do_dataset?  

For files 1 - 4: append  "_MonYY" to filename (example Detail_ESIID --> Detail_ESIID_Dec17)
For file 5: append "MonYY" to the filename (example RecLoad --> RecLoadDec17 )


For files 1 - 4: append "_YYYY" to filename (example Detail_ESIID --> Detail_ESIID_2017)
For file 5: append "YYYY" to the filename (Recload --> RecLoad2017)

The year and MonYY would be derived from firstday and lastday

For (example firstday = 20100101 for Jan 1, 2010, lastday = 20101231 for Dec 31, 2010)
The YYYY would be 2010 and MonYY would be Jan10 for firstday

Here's the code snippet:

use strict;
use warnings;
use DBI;
use Date::Manip;

Date_Init('TZ=US/Central','Internal=1');

$| = 1;

my $nodata = 0;
my ($db, $user, $pw, $wkdir, $firstday, $lastday)  = @ARGV;

# Display parameter values passed by the appworx

print("\n");
print("Database Instance  : $db \n");
print("Connected as User  : $user \n");
print("Output Directory is : $wkdir \n");
print("First Day : $firstday \n");
print("Last Day : $lastday \n\n");


#Check to see if required parameters are received by appworx
die("\n\n  - ERROR:  The Required number of arguments were not received...\n\n") 

Open in new window

0
Cloud Class® Course: SQL Server Core 2016
LVL 12
Cloud Class® Course: 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.

A question to you - wilcoxon,

This question is in reference to (https://www.experts-exchange.com/questions/29079671/How-to-generate-multiple-files-from-a-perl-script.html)

This question is related to related to a question you helped resolve lately.  So Am addressing this to you as you may be able to easily identify the issue.

The script below writes contents to the cmd screen when run.  For some reason, the data in not getting written to a out file. I can see the data dump  from the database table on the cmd screen but the outfile generated is only listing out the column headers, but no data is generated to the file?


use strict;
use warnings;
use DBI;
use Date::Manip;

Date_Init('TZ=US/Central','Internal=1');

$| = 1;

my $nodata = 0;
my ($db, $user, $pw, $wkdir, $firstday, $lastday)  = @ARGV;

# Display parameter values passed by the appworx

print("\n");
print("Database Instance  : $db \n");
print("Connected as User  : $user \n");
print("Output Directory is : $wkdir \n");
print("First Day : $firstday \n");
print("Last Day : $lastday \n\n");

#Check to see if required parameters are received by appworx
die("\n\n  - ERROR:  The Required number of arguments were not received, PROCESS ABORTING!!!\n\n") unless $lastday;

#The condition below checks to see if the month for first/last are the same and if not the same then checks to see if the years are the same.

my ($fyr, $fmon, $fday, $lyr, $lmon, $lday);
if ($firstday =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
    

Open in new window

0
Hello,
I must "execute" some commands on some books (scan-in of the items) using POST API and I've tought at a call to the CURL command via system.
Say we have a input.csv with all the books data.
The script is called via:
perl script.pl<input.csv>output.txt

Open in new window

the simple script 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);

		
	system("curl -X POST  -H \"Content-Type: application/xml\" \"https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/".$Campi[2]."/holdings/".$Campi[1]."/items/".$Campi[0]."?op=scan&library=PETFS&circ_desk=DEFAULT_CIRC_DESK&done=true&apikey=xxxxxxxxxx\"\n");

	$cntRecord++;
}

# close(FD_IN);

Open in new window


In output.txt I've some interesting data returned by the server at EVERY CURL call.
The question is simple: my I add a bit of format to output.txt (I.E. separe the output of every CURL call with something like "***BEGIN NEW OUTPUT****)?

Thanks,
Fabiano
0
Hi, I need some help installing Test::More and Text::Template Perl modules. These modules are required by OpenSSH 7.6p1 and OpenSSL 1.1.0g installations.

I'm running Red Hat Enterprise Linux Server 7.4 (Maipo)‬ and Perl 5.16.3.

I checked the installed modules and those two modules are not listed and I don't think they are available from the repos on my system.

I need to make sure they are properly installed so that I can proceed to install OpensSSH 7.6p1 on my server.

Thanks,

Jorge Batres.
0
Hi I'm trying to Capitalize First Letter of Each Word in a file name but keep the file extension lower case
I'm already removing the rubbish from the  name and I would like the results to look like this

"The.Best.TV.Show.S01E01.720p.Mkv"

my $Ext = "\.mp4|\.mkv|\.avi|\.srt";
while (my $file = <DATA>){

    my $new =  $file;
    $new =~ s/^(.+?(720|1080)p).+($Ext)$/$1$3/i;
    $new =~ s/\b(\w).*(?<=$Ext)/\U$1/g;
    print "new = $new\n";
    
}

__DATA__
the.best.TV.show.s01e01.720p.crap.here.mkv
the.best.TV.show.s01e02.1080p.mp4
the.best.TV.show.s01e03.720p.mpg
the.best.TV.show.s01e04.720p.avi
the.best.tv.show.jpg

Open in new window

0
I am moving some scripts I have from a Windows to a Linux system and so need to replace the MSXSL exe.

Currently I make calls like the following to reference my XSLT scripts and pass the needed parameters.

sub run {
  my $Command = $_[0];
  print "Running Command : $Command\n";
  system($Command);
}

sub ProduceSingleFile($;$)
{
  my $file = $_[0];
  my $outputPrefix = $_[1];
  my $input_file = basename($file);

  #croak "Can't cd to working directory: $!\n" unless chdir $nzrb_process_dir;

  if ($input_file =~ /(.*)\.xml$/)
   {
   	run("MSXSL $file Produce_People_Names.xsl -o $people_file");

     $temp_file = $outputPrefix.'output/'.$1.'.tmp';
     print("$file => $temp_file\n");

     run("MSXSL $file APNZ_Main.xsl -o $temp_file people_file=$people_file nzpa_testing=$nzpa_testing");
 
   unlink $temp_file
    }
}

Open in new window


I have attempted using XML::XSLT in the following way
    
        my $xslt = XML::XSLT->new ("Produce_People_Names.xsl");
        # transform XML file and print output
        print $xslt->serve($input_file);
        # free up some memory
       $xslt->dispose();

Open in new window


But get an error "Can't locate object method "new" via package "XML::XSLT". My XML::XSLT version is 0.31

What would be the best method for achieving my goal. My XSL scripts do not contain any "extras" and just use the basic commands.
0
The below perl script reads a database table generates output to a csv file.

use strict;
use warnings;
use DBI;
use Date::Manip;

Date_Init('TZ=US/Central','Internal=1');

$| = 1;

my $nodata = 0;
my ($db, $user, $pw, $wkdir, $firstday, $lastday)  = @ARGV;

# Display parameter values passed by the appworx

print("\n");
print("Database Instance  : $db \n");
print("Connected as User  : $user \n");
print("Output Directory is : $wkdir \n");
print("First Day : $firstday \n");
print("Last Day : $lastday \n\n");

#Check to see if required parameters are received by appworx
unless($db && $user && $pw && $wkdir && $firstday && $lastday) {
	
  die("\n\n  - ERROR:  The Required number of arguments were not received...\n\n");
  
}

# Connectivity check to the database else display failed connectivity
my $dbh = DBI->connect("dbi:Oracle:$db", $user, $pw, { AutoCommit => 0, RaiseError => 1 }) or die("Cannot connect to Database '$db' " . DBI->errstr());

# Capture counts for distinct partitions for given firstday and lastday dates
my $partition_key = join '', $firstday ,'_',$lastday;
print("Partition Key : $partition_key \n\n");

my $sthcounts = $dbh->prepare(qq(select count(distinct r.execution_id) from REGION r where r.partition_key = ? AND r.status = 'N'));
# Values of partition key will be passed on by appworx will be parameterized in the script
$sthcounts -> execute($partition_key);

# Get value of rowcount returned from Count of partition keys from REGION table
my $rowcount = 

Open in new window

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.