perl

Trying to run perl scripts with fast-cgi and lighttpd, but file just downloads

The problem is my .pl script is downloaded as a blank file instead of being executed. I read: http://redmine.lighttpd.net/wiki/lighttpd/ApplicationsUsingLighttpd My dispatch.fcgi is the following: (it is located in usr/bin/ #!perl #!/usr/bin/perl use strict; use CGI::Fast; use Embed::Persistent; { my $p = Embed::Persistent->new(); whi...

Replace two fields in perl

I have text file of this kind File 1 ------- ABC 123 DEF 456 GHI 111 And I have another file File 2 ------ stringaa ttt stringbb yyy Ouput ----- stringaa ABC stringbb 123 stringaa DEF stringbb 456 stringaa GHI stringbb 111 Reading the file File 1 update File2 such that the Ouput is produced, any ideas. ...

Checking version number validity with Perl

I'm struggling with checking the validity of version numbers in Perl. Correct version number is like this: Starts with either v or ver, After that a number, if it is 0, then no other numbers are allowed in this part (e.g. 10, 3993 and 0 are ok, 01 is not), After that a full stop, a number, full stop, number, full stop and number. I.e...

Counting array elements in Perl

I need to get the total items in array, NOT the last id, none of both ways I found to do this works: my @a; # Add some elements (no consecutive ids) $a[0]= '1'; $a[5]= '2'; $a[23]= '3'; print $#a, "\n"; # prints 23 print scalar(@a), "\n"; # prints 24 I expected to get 3.. Thank you in advance. ...

What does ${imagepath} refer to in a CSS file?

I am trying to adapt a perl script that is used to generate a splash page for a public wifi installation. I was only given a couple example files to work from and no documentation. After several hours on the phone with the access point vendor I was told I could "just edit" the examples in order to design our custom page. I am trying to u...

Help with byte shifting

Hello, I need to byte-shift a text file. I know absolutely nothing about perl, but I found a perfectly working piece of code in perl called moz-byteshift.pl (documentation). This does exactly what I want to do, but I need to do it in C#. Here's the source code of the perl file: #!/usr/bin/perl # To perform a byteshift of 7 # To d...

How do I generate character sequences like hexadecimal with a different base?

I have the following Perl script that generates a string based on a number: my @chars; push @chars, map(chr, 48..57), map(chr, 97..122); my $c = $#chars+1; for (0..50) { my $string; my $l = $_ / $c; my $i = int $l; my $r = ($l - $i) * $c; $string .= $chars[$r]; while ($i > 0) { $l = $i / $c; $i =...

Perl DBI dynamic fetchrow while loops

I'm trying to pass table names to a sub that gets all the field names of that table, stores them into an array, and then uses that array in conjunction with the fetchrow of another sql query to display the data in those fields. Here's the code I have now: Examples of sub calls with table names as the parameter: shamoo("reqhead_rec"); ...

How to Remember a match and its position in an array in perl?

Please help I am working with a file whose lines of data look like the one below. As can be seen, the data is divided into 4 by '|||', so I will have four arrays( if I divide it). what I want is this: I want to check if there are punctuation marks in the first array, if there is one, remember the position in the array. Go to the same ...

How can I find the strings from one file in another file in Perl?

The script below takes function names in a text file and scans on a folder that contains multiple c,h files. It opens those files one-by-one and reads each line. If the match is found in any part of the files, it prints the line number and the line that contains the match. Everything is working fine except that the comparison is no...

Transparently Handling GZip Encoded content with WWW::Mechanize

Hi, I am using WWW::Mechanize and currently handling HTTP responses with the 'Content-Encoding: gzip' header in my code by first checking the response headers and then using IO::Uncompress::Gunzip to get the uncompressed content. However I would like to do this transparently so that WWW::Mechanize methods like form(), links() etc work...

How can I share a database connection across a forked process in Perl?

I made the following programs in Perl before: my $db = DBconnection with DB2 if ($pid = fork()) { #parent } else { #child $db->execute("SELECT ****"); exit; } wait(); $db->execute("SELECT ****"); I thought that it waited for the end of the child process to have wanted to do it and would operate it for DB by a pro-pro...

Perl: extracting data from text using regex

I am using Perl to do text processing with regex. I have no control over the input. I have shown some examples of the input below. As you can see the items B and C can be in the string n times with different values. I need to get all the values as back reference. Or if you know of a different way i am all ears. I am trying to use bran...

What is the difference between parent and base in Perl 5?

There appears to be a new pragma named parent that does roughly the same thing as base. What does parent do that warrants a new (non-core) module? I am missing something? ...

Perl: adding input filename to output filename

I wrote a script that reads each file in a directory, does something and outputs results from each input file to two different files, e.g. "outfile1.txt" and "outfile2.txt". I want to be able to link my resulting files to original ones, so how can I add input filename (infile.txt) to the resulting filenames, to get something like this: ...

How can I strip multiline C comments from a file using Perl?

Can anyone get me with the regular expression to strip multiline comments and single line comments in a file? eg: " WHOLE "/*...*/" HAS TO BE STRIPED OFF....." 1. /* comment */ 2. /* comment1 */ code /* comment2 */ #both /*comment1*/ and /*comment2*/ #has to stripe...

How do I read multiple directories and read the contents of subdirectories in Perl?

I have a folder and inside that I have many subfolders. In those subfolders I have many .html files to be read. I have written the following code to do that. It opens the parent folder and also the first subfolder and it prints only one .html file. It shows error: NO SUCH FILE OR DIRECTORY I dont want to change the entire code. Any mo...

sed: using variables across multiple lines

I am attempting to "grep" out bind for a specific user from an LDAP log file. The lines I need will be spread across multiple lines in the log. Here is example input: [2009/04/28 17:04:42.414] DoBind on connection 0x7c8affc0 [2009/04/28 17:04:42.414] Bind name:cn=admin,ou=appids,o=admineq, version:3, authentication:simple [2009/04/28 17...

Condensing Perl Transpose code

Hi all, I always find myself writing code like this: my $var = $result[0]; my $var_changed = $var; $var_changed =~ s/somepattern/somechange/g; What would be a better way to do this? And by 'better' I mean: less typing while remaining understandable. Thanks. ...

Is there a way to get the progress of a file transfer using move function in a Perl script?

I am an ETL developer and I deal with a lot of data that needs to be processed from one form to the other before it can be loaded into tables. Therefore, most of the scripts that I work with, at some point, have to move a file from one place to the other. We are a windows shop. I was wondering if there was a way to see how much time a mo...