perl

How can I know how a perl script was started?

Any way for a perl script to know who called it and/or how? Be it another script, or an executable. Straight from the command-line or the cron scheduler. ...

File Glob in C++

What's the C++ way of Perl's idiom: my @files = glob("file*.txt"); foreach my $file (@files) { # process $file } ...

DBD::CSV: Problem with file-name-extensions

In this script I have problems with file-name-extensions: if I use /home/mm/test_x it works, with file named /home/mm/test_x.csv it doesn't: #!/usr/bin/env perl use warnings; use strict; use 5.012; use DBI; my $table_1 = '/home/mm/test_1.csv'; my $table_2 = '/home/mm/test_2.csv'; #$table_1 = '/home/mm/test_1'; #$table_2 = '/home/mm/tes...

How do I filter or retain duplicates in Perl?

I have one text string which is having some duplicate characters (FFGGHHJKL). These can be made unique by using the positive lookahead: $ perl -pe 's/(.)(?=.*?\1)//g'] For example, with "FFEEDDCCGG", the output is "FEDCG". My question is how to make it work on the numbers (Ex. 212 212 43 43 5689 6689 5689 71 81 === output should be ...

As Perl is GPL licensed, are my Perl scripts forced to be GPL licensed?

I am trying to make sure I license some personal Perl scripts correctly. Do any Perl scripts that I create need to be licensed as GPL (i.e a copyleft license) due to using the GPL licensed Perl interpreter? Please can you back up any answers with appropriate links. Thanks ...

How should I organize many Perl modules?

Consider that I have 100 Perl modules in 12 directories. But, looking into the main Perl script, it looks like 100 use p1 ; use p2 ; etc. What is the to best way to solve this issue? ...

Perl Windows Automation Scripting

I want to learn it. Where can I get some good information to start learning? ...

Email/Web server type discovery - using PHP or Perl

Fairly simple question (I think): I have a list of domains, and I want to loop through them, hitting their email and web servers, and determining the type of server software running. Something like this: LOOP over domain list ... Socket connect with www.[domain-name] over Port 80 ... Get return handshake volley of server type >...

Why doesn't my Perl code work when I put it in a foreach loop?

This code outputs the scalars in the row array properly: $line = "This is my favorite test"; @row = split(/ /, $line); print $row[0]; print $row[1]; The same code inside a foreach loop doesn't print any scalar values: foreach $line (@lines){ @row = split(/ /, $line); print $row[0]; print $row[1]; } Wh...

FreeTDS runs out of memory from DBD::Sybase

When I add client charset = UTF-8 to my freetds.conf file, my DBD::Sybase program emits: Out of memory! and terminates. This happens when I call execute() on an SQL query statement that returns any ntext fields. I can return numeric data, datetimes, and nvarchars just fine, but whenever one of the output fields is ntext, I get th...

XML::XML2JSON "0" Element

I'm using XML::XML2JSON in Perl to convert JSON data to XML, I am passing through the following data (snippet): {"question":{"isrequired":{"$t":"0"}}} and when I use the XML:XML2JSON->json2xml function to convert the JSON data into XML, I get the following (snippet): <isrequired/> I need to retain the "0" element in the "isrequired...

Keyboard input: how to separate keycodes received from user

Hello, I am writing an application involving user input from the keyboard. For doing it I use this way of reading the input: #include <stdio.h> #include <termios.h> #include <unistd.h> int mygetch( ) { struct termios oldt, newt; int ch; tcgetattr( STDIN_FILENO, &oldt ); newt = oldt; newt.c_lflag &...

How do I implement a dispatch table in a Perl OO module?

I want to put some subs that are within an OO package into an array - also within the package - to use as a dispatch table. Something like this package Blah::Blah; use fields 'tests'; sub new { my($class )= @_; my $self = fields::new($class); $self->{'tests'} = [ $self->_sub1 ...

What should I use for a Perl script's shebang line?

Which of these is better or faster to use as the shebang line for a Perl script? #! perl #! perl.exe #! fullpath/perl(/perl.exe) #! partialpath/perl(/perl.exe) And, when using #!perl, when it works on a particular system, how do I find out in the script which perl interpreter I'm using so I can put that one into the shebang line? ...

In DBD::CSV what does a /r in the f_ext attribute mean?

Why does only the second example append the extension to the filename and what is the "/r" in ".csv/r" for. #!/usr/bin/env perl use warnings; use strict; use 5.012; use DBI; my $dbh = DBI->connect( "DBI:CSV:f_dir=/home/mm", { RaiseError => 1, f_ext => ".csv/r"} ); my $table = 'new_1'; $dbh->do( "DROP TABLE IF EXISTS $table" ); $dbh->d...

What is the most updated book on programming TCP/IP sockets with Perl?

What is the most updated book on programming TCP/IP sockets with Perl? ...

Decoding MIME (HTML+Attachments)

I'm planning to write an application that should handle incoming mails. Basically it will act more like a ticketing system than a webmail, so I'm only interested in receiving emails, and not sending them. I have made a simple prototype that downloads mails and displays the text with downloadable attachments in a web page, but handling m...

What is the universal way to use file I/O API with unicode filenames?

In Windows there is a common problem: the filenames should be converted to local codepage, before they are passed to open(). Of course, there is a possibility to use Win32::API for that, but I don't want my script to be platform-dependent. At the moment I have to write something like: open IN, "<", encode("cp1251", $filename) or die $!;...

What's the fastest way to get CRUD over CGI on a database handle in Perl?

TL;DR: Want to write CGI::CRUD::Simple (a minimalist interface module for CGI::CRUD), but I want to check first if i overlooked a module that already does that. I usually work with applications that don't have the niceties of having frameworks and such already in place. However, a while ago i found myself in a situation where i was aski...

DBD::CSV: Problem with userdefined functions

From the SQL::Statement::Functions documentation: Creating User-Defined Functions ... More complex functions can make use of a number of arguments always passed to functions automatically. Functions always receive these values in @_: sub FOO { my( $self, $sth, $rowhash, @params ); } #!/usr/bin/env perl use 5.012; use warning...