perl

How can I change the colourindex of a word in a string for msword using Win32:OLE?

I am actually trying to change the color index for the first word with braces in an array so they show up in the right color in Word 2003. For example, if I have an array like this: @array=" (This) is (perl), perl is a great (language), we can do anything with perl, (perl) feels us great." I need th...

How can I identify and handle control characters and arrow keys in Perl?

I want to implement the command line features like in a linux terminal. I saw this in ftp command also. If I press tab I need to list the commands. If I press control characters I need to get that characters based on that I will do some action. And if I give any commands it should execute. For this I tried with Term::ReadKey that i...

How can I create a new file using a variable value as the name in Perl?

Eg: $variable = "10000"; for($i=0; $i<3;$i++) { $variable++; $file = $variable."."."txt"; open output,'>$file' or die "Can't open the output file!"; } This doesn't work. Please suggest a new way. ...

How can I trap Cntl-C while using Perl's Term::ShellUI?

I used Term::ShellUI and almost every thing is working as expected but the issue is when I pressed Ctrl-C I want to print: Please use ctrl+d to exit the shell For that I handle the signal but the message print only after I pressed the new line How to resolve this? ...

Why does HTTP::Message::decodable complain about "Can't use an undefined value as a HASH reference"?

I'm getting a Can't use an undefined value as a HASH reference error trying to call HTTP::Message::decodable() using Perl 5.10 / libwww installed on Debian Lenny OS using the aptitude package manager. I'm really stuck so would appreciate some help please. Here's the error: Can't use an undefined value as a HASH reference at (eval 2) l...

When should I use Perl's AUTOLOAD?

In "Perl Best Practices" the very first line in the section on AUTOLOAD is: Don't use AUTOLOAD However all the cases he describes are dealing with OO or Modules. I have a stand alone script in which some command line switches control which versions of particular functions get defined. Now I know I could just take the conditionals...

Is there some tiny perl that I can use in embedded system where the size would matter?

Is there some tiny perl that I can use in embedded system where the size would matter? ...

How can I run an external command and capture its output in Perl?

I'm new to Perl and want to know of a way to run an external command (call it prg) in the following scenarios: Run prg, get its stdout only. Run prg, get its stderr only. Run prg, get its stdout and stderr, separately. ...

How can I open a Unicode file with Perl?

I'm using osql to run several sql scripts against a database and then I need to look at the results file to check if any errors occurred. The problem is that Perl doesn't seem to like the fact that the results files are Unicode. I wrote a little test script to test it and the output comes out all warbled: $file = shift; open OUTPUT, ...

How can I get elements out of an array with Template Toolkit?

I have an array of Paths which i want to read out with Template Toolkit. How can I access the array Elements of this array? The Situation is this: my @dirs; opendir(DIR,'./directory/') || die $!; @dirs = readdir(DIR); close DIR; $vars->{'Tree'} = @dirs; Then I call the Template Page like this: $template->process('create.tmpl', $vars)...

How can I get Yahoo realtime stock quotes in Perl?

There's a fairly easy way of retrieving 15-minute delayed quotes off of Yahoo! Finance web site ("quotes.csv" API). However, so far I was unable to find any info on how to access real-time quotes. The hang-ups with real-time quotes are: Only available to logged-in user No API Non-obvious how to scrape the info - I'm somewhat convince...

How can I produce an HTML summary of Perl modules or scripts in a directory?

Is there a tool available that can produce an HTML summary list of perl modules or scripts in a directory tree? Given =head1 NAME wibble.pl - does wibble actions I would like to see something like <a href="docsforwibble">wibble.pl</a> - does wibble actions <a href="docsforwobble">wobble.pl</a> - does wobble actions ...

How can I open a binary file in Perl, change ONLY the first byte, and write it back out?

Very similar to Changing one byte in a file in C, but in Perl instead of C. How can I open a binary file in Perl, change ONLY the first byte, and write it back out? ...

Is there a better way to pass by reference in Perl?

I am doing pass-by-reference like this: use strict; use warnings; sub repl { local *line = \$_[0]; our $line; $line = "new value"; } sub doRepl { my ($replFunc) = @_; my $foo = "old value"; $replFunc->($foo); print $foo; # prints "new value"; } doRepl(\&repl); Is there a cleaner way of doing it? Prototypes ...

How can I switch timezones in Perl's Template::Plugin::Date?

I have a calendar on my website, generated in Perl using Template::Toolkit and Template::Plugin::Date. It highlights the current day. I achieve this by iterating through all the dates (as I print the calendar) and comparing against the current date. Something like this: [% IF cur_date == date.format(format = '%Y-%m-%d') %] ... [% END ...

How do I create something like a negated character class with a string instead of characters?

I am trying to write a tokenizer for Mustache in Perl. I can easily handle most of the tokens like this: #!/usr/bin/perl use strict; use warnings; my $comment = qr/ \G \{\{ ! (?<comment> .+? ) }} /xs; my $variable = qr/ \G \{\{ (?<variable> .+? ) }} /xs; my $text = qr/ \G (?<text> .+?...

How can I pass a constant to a Perl subroutine?

I have got as follows: use constant ABC => ('one', 'two', 'three'); and I want to pass this constant to variations_with_repetition(\@data, $k) subroutine as @data. How should I do that? ...

Is there a regular expression in Perl to find a file's extension?

Is there a regular expression in Perl to find a file's extension? For example, if I have "test.exe", how would I get the ".exe"? ...

How can I search and replace text that looks like Perl variables?

I'm really getting my butt kicked here. I can not figure out how to write a search and replace that will properly find this string. String: $QData{"OrigFrom"} $Text{"wrote"}: Note: That is the actual STRING. Those are NOT variables. I didn't write it. I need to replace that string with nothing. I've tried escaping the $, {, and...

How do I group my package imports into a single custom package?

Hi All.. Normally when I am writing the perl program . I used to include following package . use strict ; use warnings ; use Data::Dumper ; Now , I want like this, I will not include all this package for every program . for that I will have these all package in my own package. like following. my_packages.pm package my_packages ...