perl

Substitution regex

I want to substitute all white space that precedes the class [A-Za-z0-9_], with $. $string = "STRING sDir = sDrive"; $string =~ s/\s(?=[A-Za-z0-9_])/ \$/; It only matches one time and produces: STRING $sDir = sDrive; ...

how to use stdin on perl cgi

I am new to perl and I want to use screen input on my script. here is my script and I want the IOS command to be enter from keyboard. can some one show me where I am wrong.the problem i have now the script not read my keyboard input, I am not sure if work on my case. thanks!! # ### Show ################################################...

How do I interpret the output of Devel::Leak

I've run Devel::Leak in my program and I don't understand the output it's giving me. To start, I see it's printing a list of pointers. Can I get that list in an array? Then I can use FindRef to see where it's coming from. For example: new 0xaebc28 : SV = PVGV(0x30e7e48) at 0xaebc28 REFCNT = 1 FLAGS = (GMG,SMG) IV = 0 NV = 0 ...

perl - get filesize with -s

I am trying to find filesize using -s operator. I looks like this: my $filesz = -s $filename I tried lots of various way but it can not get this size. However, If I give static content instead of filename, it works fine For exa: $filesz = -s "/tmp/abc.txt" This works fine. I tried adding " in filename, it didn't work. I removed \n fr...

How do I use Perl's XML::Twig to count multiple tags in XML?

I am using XML::Twig to parse my input xml using Perl. I need to extact a particular node in this XML and validate that node to see if it has multiple <p> tags and then count words in those P tags. For example: <XML> <name> </name> <address> <p id="1">a b c d </p> <p id="2">y y y </p> </address> </XML> Output: Address has 2 para...

How to convert this shell script to a platform independent Perl script?

I have a cshell script that is something like this: `netstat -ap | & grep tcp | grep myprocess | awk '{print $4}' | awk 'BEGIN { FS = :"}{print $2}'` This is how it works 1. $ netstat -ap | & grep tcp | grep myprocess tcp 0 0 *:1234 *:* LISTEN 8888/myprocess 2. $ netstat -ap | & grep tcp | grep myprocess | ...

Scaling a simple Perl CGI to a high volume server

I wrote a Perl program which searches and manipulates one text file. This CGI process slurps the file directly into memory, manipulates the file based on the User's input, then generates the HTML result. It works functional wise. However, I know that once I deploy on high volume server, it will not be able to respond in due time. I sus...

How does O=Deparse work, and does Perl have and fold constant arrays?

I'm wondering, does -MO=Deparse show you all of the Perl optimizations, and why doesn't this get folded in Perl 5.10? $ perl -MO=Deparse -e'[qw/foo bar baz/]->[0]' ['foo', 'bar', 'baz']->[0]; -e syntax OK Some on IRC thought that O=Deparse might not be showing it all, but it certainly shows some constant folding. $ perl -MO=Deparse -...

Win32 Perl - Telling the difference between files and folders using a passed directory argument

Hi, I'm writing a script in perl strawberry. The first thing it needs to be able to do is take a path argument and get a directory listing for that path, and it needs to be able to distinguish between files and folders. I read some tutorials on the subject and wrote the script below, but it only works when I give it the path that the s...

Calling script and passing value from called script

I have one script i'm trying to call from another script, passing the information from the script that is being called to the calling script. When i use do or require it runs through but doesnt pass the value. ex. I have the following line at the bottom of the script that i am calling called script.pl print " $hold IS VALUE\n"; wh...

Using Curl to get a Https webpage in Windows 7

I just need to fetch an https page, and I'm using curl currently by having the curl.exe application in my Path and calling it with a Perl file. However, then I get the error "* Protocol https not supported or disabled in libcurl". I've been looking around and I can't find a solid set of instructions to get it to work. I have installed cy...

Way to learn modern perl for experienced programmer

Pretty simple, I don't want an introduction that introduces me to the concepts of loops, arrays, etc. I want a book that "gets into" perl right off the bat and is up to date enough for me to follow the conventions of modern perl use. Format doesn't matter, book, pdf, online tutorial, etc. I'd also prefer for it to be short. I can get aro...

Read and delete text between two strings in perl

I need a way to read and delete text between two different strings found in some file, then delete the two strings. Like a "cut command." I would like to have the text stored in a variable. I saw the post about reading text between two strings, but I could not figure out how to delete it as well. I intend to execute the stored text i...

How do I get the Perl debugger to not stop at "100 levels deep in subroutine calls"

I'm working with a big, old, messy, bloated framework. It regularly goes well over 100 levels deep in subroutine calls. The Perl debugger sees fit to stop and inform me of this fact... over and over again. Package::Stash::name(/usr/local/perl/5.10.1/lib/site_perl/5.10.1/Package/Stash.pm:21): 21: return $_[0]->{package}; 100 levels...

Can a Perl script modify itself?

I would like to have my scripts keep track of thier last date of revision internally as a comment. Is this possible? It seems to me that it would need to grab the date and then open its script file for an append, write the data and save the file. Thanks Everone, great answsers one and all. Based on the code snippet left by GreenMatt ...

How do I execute a Perl program on Windows without calling perl on the command-line?

I have written a small script in Perl which I am executing on Windows with ActivePerl as below: C:\Documents and Settings\Administrator> perl io.pl io.pl #!/usr/bin/perl use warnings; sub test6 { while (defined($_ = <>)) { #chomp($_); print $_; } } test6; As you can see, the code is similar to the Unix cat com...

What does this statement do: ();

I've seen perl statements that look like this: () unless $some_var; What is that intended to achieve? ...

MooseX::Declare and Perl EPIC (Eclipse IDE)?

How can I get support for jumping to Moose methods using Eclipse with the EPIC plugin? (Using F3) They're declared like class Point { method getDistance { ... } } ...

ctags support for MooseX::Declare? (Perl)

How can I get ctags to generate tags for MooseX::Declare methods, classes, attributes and such? ...

Perl read_config sub, oop or not?

Hi, I have a package (really just one subroutine) I use frequently to parse config file etc. Basically it looks like this: sub get_settings { my %config; my $config = 'path...'; unless(-r $config) { die("Couldn't read config"); } open CONFIG, '<', $config or die $!; while(...