perl

How to make lists automatically instantiate on use in Python as they do in Perl?

In Perl, I can do this: push(@{$h->[x]}, y); Can I simplify the following python codes according to above Perl example? if x not in h: h[x] = [] h[x].append(y) I want to simplify this, because it goes many places in my code, (and I cannot initialize all possible x with []). I do not want to make it a function, because there is no...

How do I install Encode::HanExtra for ActivePerl?

I want to enable Encode::HanExtra on Windows XP environment. I can't find the name HanExtra or Encode-HanExtra in PPM GUI. Is there any alias name for it? ...

Why can't Perl's DBD::DB2 find dbivport.h during installation?

We are using a Perl utility to dump data from DB2 database. We installed DBI package and it is asking for DBD package also. We dont have root access and when we try to install DBD package we are getting the following error: ERROR BUILDING DB2.pm [lijumathew@intblade03 DBD-DB2-1.78]$ make make[1]: Entering directory '/home/...

How can I run a command on a remote machine with Perl?

I'm using following code to connect to a remote machine and try to execute one simple command on remote machine. #!/usr/bin/perl #use strict; use warnings; use Net::Telnet; $telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die'); $telnet->open('172.168.12.58'); $telnet->waitfor('/login:\s*/'); $telnet->print('admin'); $telnet->waitfor(...

Can the Perl compiler tell me if I have an unchecked exception in my code?

Is there a way in Perl to declare that a method can throw an error (or die)? EDIT: What interests me the most is a way to get the compiler or IDE to tell me I have an unchecked exception somewhere in my code. I always loved how in Java, a method could handle an Exception and/or throw it. The method signature allows to put "throws MyExc...

What's happening in this Perl foreach loop?

I have this Perl code: foreach (@tmp_cycledef) { chomp; my ($cycle_code, $close_day, $first_date) = split(/\|/, $_,3); $cycle_code =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/; $close_day =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/; $first_date =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/; #print "$cycle_code, $close_day, $first_date\n"; $cycledef{$cycle_code...

finding the missing values in a range using any scripting language - perl, python or shell script

I got stuck in one problem of finding the missing values in a range and the range is also variable for the successive rows. input 673 673 673 676 676 680 2667 2667 2668 2670 2671 2674 output should be like this 674 675 677 678 679 2669 2672 2673 This is just one part and the row values can be more also If you need any clarification,...

Can I use Catalyst to display images or graphs?

I have simple Perl/CGI scripts based web server which is mainly used to display graphs and images. I am looking to make it more technical and come to know about Catalyst. I have installed all the required Perl modules on my test platform and created an application called myweb. Also, I am going through the Catalyst documents to reach my ...

Why does Email::MIME split up my attachment?

Why does the attachment(ca. 110KiB) split up in 10 parts(ca. 11KiB) when I send it with this script using Email::MIME? #!/usr/bin/env perl use warnings; use strict; use Email::Sender::Transport::SMTP::TLS; my $mailer = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.my.host', port => 587, username => 'username', ...

How can I create 2 Perl/TK text areas with scrollbars that when I scroll one both text areas scroll at the same time?

Is it possible using TK to create to text areas with scrollbars that when you scroll one the other moves as well? What I want to create is a text area with headers in and then text areas underneath row headings in one and data in the other. Kind of Like when you freeze panes in Excel. I have the data in a set of arrays for each line, so...

How can I check the MIME type of an uploaded file using Perl CGI?

I'm trying to get the MIME type of an <input type="file" /> element using Perl, but without actually examining the contents of the file itself, In other words, just using the HTTP headers. I have only been able to get the "multipart/form-type" Content-Type value, but my understanding is that each element will get its own MIME Type? How...

How can I generate an XML using Perl and XSLT?

I want to generate an XML file using Perl and XSLT. Is it possible to achieve this by updating the XSLT dynamically by uusing values from a hash? Or is there any better solution for wirting a simple XML file using Perl? ...

How can I check that I downloaded the entire file in Perl?

Does the test of the file-size make sense here? I tried to cut the connection while downloading, but it looks like the size-test is never reached. #!/usr/bin/env perl use warnings; use strict; use 5.012; use LWP::Simple; my $url = 'http://www.kernel.org/pub/linux/kernel/v2.6/next/patch-v2.6.34-rc5-next-20100428.bz2'; my $file = 'next...

Why do I get "Bad File Descriptor" when I try to read a file with Perl?

I'm trying to read a binary file 40 bytes at a time, then check to see if all those bytes are 0x00, and if so ignore them. If not, it will write them back out to another file (basically just cutting out large blocks of null bytes). This may not be the most efficient way to do this, but I'm not worried about that. However, right now I'...

What is the Perl equivalent to C's #include?

Possible Duplicate: How do I include functions from another file in my Perl script? I have a couple simple perl scripts that share some subroutines. I'd like to pull those subroutines out into another file, but I'm not sure how to go about doing that. All I need is an equivalent to C's #include. I found a couple things onli...

How can I insert content between the 2nd and 3rd paragraphs in HTML, using Perl?

I'm trying to match the point between 2nd and 3rd paragraphs to insert some content. Paragraphs are delimited either by <p> or 2 newlines, mixed. Here's an example: text text text text text text text text <p> text text text text text text text text </p> <--------------------------- want to insert text here <p> te...

What is the difference between `$this`, `@that`, and `%those` in Perl?

What is the difference between $this, @that, and %those in Perl? ...

spawn an entirely separate proccess in linux via bash

I need to have a script execute (bash or perl or php, any will do) another command and then exit, while the other command still runs and exits on its own. I could schedule via at command, but was curious if there was a easier way. ...

Perl not closing TCP sockets if clients are no longer connected?

The purpose of the application is to listen for a specific UDP multicast and then to forward the data to any TCP clients connected to the server. The code works fine, but I have a problem with the sockets not closing after the TCP clients disconnects. A socketsniffer utility shows the the sockets remain open and all the UDP data continue...

How can I specify which port to use in Perl's IO::Socket::INET?

I am using IO::Socket::INET to create inter-process communication in my program. I need to use a specific port number in my TCP client. I was following the example in Perl doc, but it doesn't work. Here is my code: old code(working): tx_socket = new IO::Socket::INET->new('127.0.0.1:8001') || die "Can't connect to 127.0.0.1:8001 : $!\n"...