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.
...
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...
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...
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...
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.
...
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 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 ...
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.
...
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...
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(
...
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";
...
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.
...
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/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:...
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...
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,...
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 ";
}
...
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...
Obviously, I want to avoid raster images as intermediate step.
...
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?
...