perl

What's the best way to document Perl code?

Any suggestion how I can document my Perl code? What do you use and what tools are available to help me? Which module do you use to convert pod to html? ...

How do I use constants from a Perl module?

If I define a constant in a Perl module, how do I use that constant in my main program? (Or how do I call that constant in the main program?) ...

How do I know if a system has powered on?

I am writing a script that powers on a system via network. And then i need to run a few commands on the other host. How do I know whether the system has powered on? My programming language is Perl and the target host is RHEL5. Is there any kernel interrupt or network boot information that indicates the system has powered on and the os...

How do I efficiently empty a Perl DBM file?

I've inherited a piece of code with a snippet which empties the database as follows: dbmopen (%db,"file.db",0666); foreach $key (keys %db) { delete $db{$key}; } dbmclose (%db); This is usually okay but sometimes the database grows very large before this cleanup code is called and it's usually when a user wants to do something import...

What does "select((select(s),$|=1)[0])" do in Perl?

I've seen some horrific code written in Perl but I can't make head or tail of this one. It's in some networking code that we use to communicate with a server and I assume it's something to do with buffering (since it sets $|). But I can't figure out why there's multiple selects or the array reference. Can anyone help me out? ...

What's the best way to clear the screen in Perl?

Ideally, something cross-platform. ...

How do I use raw sockets in Perl?

How can you get a raw socket in Perl, and then what's the best way to built a packet for use with it? ...

Is it worth learning BASH when I know Perl?

All my scripting is done in Perl, I can execute one liners at the command line, and Perl regex seems way easier. Is there anything I can do in BASH that I can't do in Perl? I just don't feel like a true hacker unless I spend the time to delve in BASH and start using Sed and Awk as well. Is it worth it, or am I just asking for pain and...

Why would the rollback method not be available for a DBI handle?

For some reason I am having troubles with a DBI handle. Basically what happened was that I made a special connect function in a perl module and switched from doing: do 'foo.pl' to use Foo; and then I do $dbh = Foo->connect; And now for some reason I keep getting the error: Can't locate object method "rollback" via package "...

How do I convert CSV into an HTML table using Perl?

In my code, I want to view all data from a CSV in table form, but it only displays the last line. How about lines 1 and 2? Here's the data: 1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern 2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern 3,hf35,08-Oct-08...

What's a good way to process RTF-encoded files and convert them to XML?

I have never done huge amounts of RTF processing, I always used a library to read or generate one and that was a long time ago. Now I need to get more intimate with the format again, and eventually convert it to XML. Can you recommend a good path to do it so that I have a lot of control on how RTF chunks are parsed and processed? Initi...

How can I localize Perl variables in a different stack frame?

I have some auto-generated code which effectively writes out the following in a bunch of different places in some code: no warnings 'uninitialized'; local %ENV = %ENV; local $/ = $/; local @INC = @INC; local %INC = %INC; local $_ = $_; local $| = $|; local %SIG = %SIG; use warnings 'uninitialized'; When auto-generating code, som...

Perl & mod_fcgid- how can I be sure it's working?

I have a couple Perl scripts I'm taking public soon, and I want to make sure they'll run under mod fcgid in order to keep the server load as low as possible. Previously, I've only ever run scripts that test FastCGI (ie, while ( my $q = new CGI::Fast ) { $count++; echo $count;}) or taken advantage of larger Perl packages (like MovableTyp...

How do I connect to a MSSQL database using Perl's DBI module in Windows?

How do I connect to a MSSQL database using Perl's DBI module in Windows? ...

How do I match only fully-composed characters in a Unicode string in Perl?

I'm looking for a way to match only fully composed characters in a Unicode string. Is [:print:] dependent upon locale in any regular expression implementation that incorporates this character class? For example, will it match Japanese character 'あ', since it is not a control character, or is [:print:] always going to be ASCII codes 0x20...

Why shouldn't I use UNIVERSAL::isa?

According to this http://perldoc.perl.org/UNIVERSAL.html I shouldn't use UNIVERSAL::isa() and should instead use $obj->isa() or CLASS->isa(). This means that to find out if something is a reference in the first place and then is reference to this class I have to do eval { $poss->isa("Class") } and check $@ and all that gumph, or el...

Is there a Perl function to turn a string into a regexp to use that string as pattern?

I have trouble using Perl grep() with a string that may contain chars that are interpreted as regular expressions quantifiers. I got the following error when the grep pattern is "g++" because the '+' symbols are interpreted as quantifiers. Here is the output of for program that follows: 1..3 ok 1 - grep, pattern not found ok 2 - grep,...

How do I get a directory listing in Perl?

I would like to execute ls in a Perl program as part of CGI script. For this I used exec(ls), but this does not return from the exec call. Is there a better way to get a listing of a directory in Perl? ...

How do I distinguish a file from a directory in Perl?

Hi, I'm trying to traverse through all the subdirectories of the current directory in Perl, and get data from those files. I'm using grep to get a list of all files and folders in the given directory, but I don't know which of the values returned is a folder name and which is a file with no file extention. Does anyone know how to tel...

What is the best way to slurp a file into a string in Perl?

Yes, There's More Than One Way To Do It but there must be a canonical or most efficient or most concise way. I'll add answers I know of and see what percolates to the top. To be clear, the question is how best to read the contents of a file into a string. One solution per answer. ...