perl

How can I find out the file name of a require'd file in Perl?

How do I find out the name of a file that was require'd, from within that file? I can look into %INC to find the names of all files that were loaded, but I am looking for something like $0 that would serve as the key into %INC. ...

How do I read a single character from STDIN using Perl on Windows?

Using Perl, how do I capture a single character from STDIN without needing the user to hit enter (similar to C's getch() function)? Perl has a getc() function, but according to the perlfunc: However, it cannot be used by itself to fetch single characters without waiting for the user to hit enter. The perlfunc docs do provides...

How can I output a die() message without the location information?

I've got a script that throws an exception via die. When I catch the exception I want to output the message without the location information attached. This script: #! /usr/bin/perl -w use strict; eval { die "My error message"; }; if($@) { print $@; } outputs My error message at d:\src\test.pl line 7. I would prefer just to...

How can I avoid zombies in Perl CGI scripts run under Apache 1.3?

Hi guys, Various Perl scripts (Server Side Includes) are calling a Perl module with many functions on a website. EDIT: The scripts are using use lib to reference the libraries from a folder. During busy periods the scripts (not the libraries) become zombies and overload the server. The server lists: 319 ? Z 0:00 [scriptnam...

Dissallow deletion of Master branch in git

I'm trying to setup a git hook that will disallow anyone to delete the master, alpha, and beta branches of our repository. Can anyone help with this? I have never done a git hook so i don't want to try my luck in developing my own without a little help. Thanks in advance. ...

How can I read from a Perl filehandle that is an array element?

I quickly jotted off a Perl script that would average a few files with just columns of numbers. It involves reading from an array of filehandles. Here is the script: #!/usr/local/bin/perl use strict; use warnings; use Symbol; die "Usage: $0 file1 [file2 ...]\n" unless scalar(@ARGV); my @fhs; foreach(@ARGV){ my $fh = gensym; ...

How can I reorder substrings in a string?

How do I do the following conversion in regex in Perl? British style US style "2009-27-02" => "2009-02-27" I am new to Perl and don't know much about regex, all I can think of is to extract different parts of the "-" then re-concatenate the string, since I need to do the conversion on the fly, I felt my approach will be pretty slow ...

Is there a faster alternative to Perl's stat?

I'm traversing an entire partition, stat()'ing each file and then checking the returned values for mtime, size and uid against hashed values. stat() however is far too slow in Perl and I'm wondering if there's any quicker alternatives I may be overlooking. ...

Is there a safe way of using eval to unthaw Data::Dumper output in Perl?

I have an object that uses freezes data as such: sub frozen_data { my $self = shift; $Data::Dumper::Indent = 0; $Data::Dumper::Terse = 1; return Data::Dumper->Dump( [ $self->{_DATA}, ] ); } and a corresponding thaw: sub thaw_data { my ($self) = @_; $self->{_DATA} = eval $self->{DATA}; } this seems to work...

Why does my jzip process hang when I call it with Perl's system?

I am definitely new to Perl, and please forgive me if this seem like a stupid question to you. I am trying to unzip a bunch of .cab file with jzip in Perl (ActivePerl, jzip, Windows XP): #!/usr/bin/perl use strict; use warnings; use File::Find; use IO::File; use v5.10; my $prefix = 'myfileprefix'; my $dir = '.'; File::Find::find( ...

How can I print the first to the fifth from last array elements in Perl?

I'm running the following code and I'm attempting to print the first element in the @rainbow array through the fifth-from-last element in the @rainbow array. This code works for any positive indices within the bounds of the array, but not for negative ones: @rainbow = ("a".."z"); @slice = @rainbow[1..-5]; print "@slice\n"; ...

How can I monitor the Perl call stack?

I'm using ActivePerl 5.8 on Windows XP. use strict; use warnings; use Data::Dumper; There are three subroutines used in my script. To detect the call stack, I can only insert some print "some location"; and check the print result from console Window. Is there any good method to monitor it? Thank you. ...

How can I find all the packages that inherit from a package in Perl?

I have a number of different sites that I download data from and massage into other formats (using Perl) for use at work, that are all run from one Perl script kinda like so: #! /usr/bin/perl use strict; use My::Package1; use My::Package2; my $p1 = My::Package1->new; $p1->download; my $p2 = My::Package2->new; $p2->download; and so ...

How do I put an array on the POE heap and push or pop data?

How do I put an array on the POE heap, and push/pop data to/from it? I'm trying to put the following array on the heap: @commands = ( ["quit",\&Harlie::Commands::do_quit,10], ["part",\&Harlie::Commands::do_part,10], ["join",\&Harlie::Commands::do_join,10], ["nick",\&Harlie::Commands::do_nick,10], ["module",\&Harlie:...

How do I remove white space in a Perl string?

If I declared a variable $myString with the value '3 ' (notice the white space). Is there any function to remove the white space for the return value. A little like SomeFun($myString) then return '3' (without white space). #!C:\Perl\bin\perl.exe use strict; use warnings; use Data::Dumper; my $fh = \*DATA; print Dumper parse_constan...

How can I get a directory listing from DOS in Perl?

I need to get directory names from the path passed to the Perl script as run time argument. Here is the code I'm using: $command ="cd $ARGV[0]"; system($command); $command="dir /ad /b"; system($command); @files=`$command`; But it still returns the directory names inside the directory from which I'm running this Perl script. In short,...

How can I check if a Perl string contains letters?

In Perl, what regex should I use to find if a string of characters has letters or not? Example of a string used: Thu Jan 1 05:30:00 1970 Would this be fine? if ($l =~ /[a-zA-Z]/) { print "string "; } else { print "number "; } ...

What's the difference between single and double quotes in Perl?

I am just begining to learn Perl. I looked at the beginning perl page and started working. It says: The difference between single quotes and double quotes is that single quotes mean that their contents should be taken literally, while double quotes mean that their contents should be interpreted When I run this program: #!/usr/l...

How do I embed EPS into a PDF with PDF::API2?

Obviously, I want to avoid raster images as intermediate step. ...

How can I determine the bitness of the OS using Perl on Windows?

Using Perl, how can I determine whether my program is running on 32 bit Windows or 64 bit Windows? Is there any API available? I can think of a couple of options.. Check the PE_HEADER of some windows file (eg: c:\windows\explorer.exe) - maybe I can use the details in How can I test a windows dll to determine if it is 32bit or 64bit? ...