perl

How to replace string and preserve its uppercase/lowercase

Perl question: I want to replace one string with the other; both are of the same length. I want to replace all occurrences of the string (case insensitive), but I want that the case of the letter will be preserved. So if the first letter was upper case, the first letter after the replacement will be upper case also. For example, if I w...

Using PHP session variable in perl

Can I use a session variable that I have created with php in perl? ...

ActiPerl + Tcl.pm *** glibc detected *** munmap_chunk(): invalid pointer: 0x09b5e0d8

I installed ActivePerl 5.10.1.1007 on my Ubuntu 10.04 machine. I have a very simple Perl script with the following lines: use lib "/opt/ActivePerl-5.10/lib"; use Tcl; my $Interpreter = new Tcl; $Interpreter->Eval('puts "Hello world"'); $Interpreter->Eval('set ::env(TESTVAR) 55') The output is the following: $ /opt/ActivePerl-5.10/...

efficient way to merge a head file and part of a tail file and then to stdout

Actually I am in great agony recoverying a corrupt gzip file, possibly due to interrupted ftp transfer and then resume. After googling I found Recovering a damaged .gz file and am trying as it reads. What I'm doing now is merging a gzip header file with some last part of the damaged file varying the size of the last part. Then I test th...

How can I uniquely identify all of the calls to a function?

I know that caller will give me the file name and line number where a function was called, but how can I get the character or byte offset? It is okay if I must drop down to XS for it (the function will probably wind up being XS anyway). What I am trying to do is uniquely identify all of the calls to a function, so, if there is a better...

Perl Rename Folders And Files With File::Find

I'm using this code to process my folders and files with two subs: "sub folders" for folder names only "sub files" for file names with extensions only But I realized that "sub folders" messes with my files with extensions during the rename process. How to distinguish the processes from one another or what is the intelligent way to te...

Script to change FTP password

I have the following script to update one of my FTP passwords every 15 days through a cronjob and e-mail the appropriate people after the attempt has been made. It randomly will fail and so I will run it again manually and it will work. I can't seem to find where it's going wrong. The script is connecting to a local mysql database grabb...

CGI Application Authentication using multiple drivers

Hi I have been trying to authenticate my CGI application through 2 drivers, one that uses username/password stored in the database and other using ldap active directory. following is the code $self->authen->config( DRIVER => [ 'DBI', DBH => $self->dbh, TABLE => 'user', CONSTRAINTS => { 'user.username' => '...

Parsing Java Class From Perl or Python

I want to get a .java file, recognize the first class in the file and getting information about annotations, methods and attributes from this class. Is there any module in both languages that already does that? I could build up a simple regexp to do it also, but I don't known how to recognize in the regexp the braces indicating the end ...

Recursive calls to database in perl

I know there's an easy way of doing this, but my recursion abilities are out of practice. Given a database table that has three fields: id label child_id I should be able to put together a recursive function that will give output like this: child (input of program) parent1 parent2 grandparent1 great-grandparent1 gr...

Perl: How to pass and use a lexical file handle to a subroutine as a named argument?

I want to pass a lexical file handle to a subroutine using a named argument, but the following does not compile: #!/usr/bin/perl -w use strict; my $log_fh; my $logname = "my.log"; sub primitive { my ($fh, $m) = @_; print $fh $m; } sub sophisticated { my ($args) = @_; print $args->{m}; print $args->{fh} $args->{m} ; } ...

How do I convert epoch time to normal time in Perl?

I am attempting to write a Perl script that parses a log where on each line the second value is the date. The script takes in three arguments: the input log file, the start time, and the end time. The start and end time are used to parse out a certain value on each line that that falls between those two times. But to properly run this...

convert a python code to a perl code

can you convert this python code to perl code (i search about it but dont find a good result) for i in xrange(20): try: instructions except : pass Thanks ...

Can anybody explain this read-only exception to me?

Below is my code (don't worry there's a USUW at the top of the module) I'm testing if an array ref is readonly, and if that is the case then I'm copying it into another array ref. The tests show that the array is not read-only, yet when it runs, it fails with that error. ( For those of you not familiar with me or Smart::Comments--those ...

Why does FileHandle::getpos on a newly-opened handle return the empty string rather than 0?

I'm trying to use getpos in Perl. I am using a FileHandle object in the code below, and it doesn't seem to be working. Can anyone tell me what I'm doing wrong? use strict; use warnings; use FileHandle; my $fh = new FileHandle; $fh->open("<test.txt") or die "$!"; my $pos = $fh->getpos; print "pos: \"$pos\"\n"; The output is: pos: "" ...

Perl sub optimisation push string into csv using split.

I would like to optimise this Perl sub: push_csv($string,$addthis,$position); for placing strings inside a CSV string. e.g. if $string="one,two,,four"; $addthis="three"; $position=2; then push_csv($string,$addthis,$position) will change the value of $string = "one,two,three,four"; sub push_csv { my @fields = split /,/, $_[0]; # ...

Getting a Bareword error on Perl Tutorial

I'm making progress but I've run into a new problem. This is the new code: #!/usr/bin/perl -w use strict; use LWP::Simple; use HTML::TreeBuilder; my $url = 'http://oreilly.com/store/complete.html'; my $page = get( $url ) or die $!; my $p = HTML::TreeBuilder->new_from_content( $page ); my($book); my($edition); my @links = $p->look_dow...

syntax error! jqGrid problem parsed by Catalyst server.pl

Hi I'm new to Catalyst, I found server.pl built-in in catalyst module can not parse jqGrid correctly. Below is error messages: Error: syntax error Source File: http: //xxx:3000/site/static/js/i18n/grid.locale-en.js Line: 2 Source Code: Error: syntax error Source File: http ://localhost:3000/site/static/js/jquery.jqGrid.min.js Line...

Perl: Multiple global "or"-separated regex conditions in while block leads to an infinite loop?

Hi all, I'm learning Perl and noticed a rather peculiar quirk -- attempting to match one of multiple regex conditions in a while loop results in that loop going on for infinity: #!/usr/bin/perl my $hivar = "this or that"; while ($hivar =~ m/this/ig || $hivar =~ m/that/ig) { print "$&\n"; } The output of this program is: th...

How can I get entire command line string?

I'm writing a perl script that mimics gcc. This my script needs to process some stdout from gcc. The part for processing is done, but I can't get the simple part working: how can I forward all the command line parameters as is to the next process (gcc in my case). Command lines sent to gcc tend to be very long and can potentially contai...