perl

Is there a simple way to test if a Moose attribute is read-only?

I currently use a block eval to test that I've set an attribute as read-only. Is there a simpler way to do this? Example from working code: #Test that sample_for is ready only eval { $snp_obj->sample_for('t/sample_manifest2.txt');}; like($@, qr/read-only/xms, "'sample_for' is read-only"); UPDATE Thanks to friedo, Ether, and Robert P...

How can I terminate a system command with alarm in Perl?

I am running the below code snippet on Windows. The server starts listening continuously after reading from client. I want to terminate this command after a time period. If I use alarm() function call within main.pl, then it terminates the whole Perl program (here main.pl), so I called this system command by placing it in a separate Pe...

How do I check if a scalar has a compiled regex in it with Perl?

Let's say I have a subroutine/method that a user can call to test some data that (as an example) might look like this: sub test_output { my ($self, $test) = @_; my $output = $self->long_process_to_get_data(); if ($output =~ /\Q$test/) { $self->assert_something(); } else { $self->do_something_else(); ...

How can I call a PL/Perl function from another PL/Perl function?

CREATE FUNCTION foo() RETURNS text LANGUAGE plperl AS $$ return 'foo'; $$; CREATE FUNCTION foobar() RETURNS text LANGUAGE plperl AS $$ return foo() . 'bar'; $$; I'm trying to compose results using multiple functions, but when I call foobar() I get an empty result. ...

How do I find the parent directory of a file in Perl?

Is there some function that returns the parent directory of a file in Perl? ...

How can I extract URLs from plain text with Perl?

I need the Perl regex to parse plain text input and convert all links to valid HTML HREF links. I've tried 10 different versions I found on the web but none of them seen to work correctly. I also tested other solutions posted on StackOverflow, none of which seem to work. The correct solution should be able to find any URL in the plain te...

What does Carp::carp do in Perl?

Can anyone please explain me about carp subroutine with sample Perl code? ...

How can I make an HTML pop-up menu with Perl?

I need to create HTML pop-up menu using Perl. Can anyone help me? ...

How can I display a Perl/Tk window in the bottom righthand corner?

I have planned to do the chatting the exercise Perl socket. In this I want to display the require window using Perl/Tk. Here my requirement is that the window has to display in the bottom right corner. It is like Gmail Chat window. What do I need to achieve this? By default it displays in top left corner. ...

How can I get the output of a command terminated by a alarm() call in Perl?

Case 1 If I run below command i.e iperf in UL only, then i am able to capture the o/p in txt file @output = readpipe("iperf.exe -u -c 127.0.0.1 -p 5001 -b 3600k -t 10 -i 1"); open FILE, ">Misplay_DL.txt" or die $!; print FILE @output; close FILE; Case 2 When I run iperf in DL mode , as we know server will start listening in cont. mo...

What's the best strategy to delete a very huge folder using Perl?

Hi, I need to delete all content (files and folders) under a given folder. The problems is the folder has millions of files and folders inside it. So I don't want to load all the file names in one go. Logic should be like this: iterate a folder without load everything get a file or folder delete it (verbose that the file or folder "...

How do I delete a [sub]hash based off of the keys/values of another hash?

Lets assume I have two hashes. One of them contains a set of data that only needs to keep things that show up in the other hash. e.g. my %hash1 = ( test1 => { inner1 => { more => "alpha", evenmore => "beta" } }, test2 => { inner2 => { more => "charlie", somethingelse => "delta" } }, test3 => { inner9999 => { oh...

What are the reasons to use dos batch programs in Windows?

Question What would be a good (ideally, technical) reason to ever program some non-trivial task in dos batch language on a modern Windows system as opposed to downloading either PowerShell, or ActiveState Perl? To be more specific, I make the following two assumptions for the duration of this question: anyone technical enough to be a...

Can I use POSIX signals in my Perl program to create event-driven programming?

Is there any POSIX signals that I could utilize in my Perl program to create event-driven programming? Currently, I have multi-process program that is able to cross communicate but my parent thread is only able to listen to listen at one child at a time. foreach (@proc) { sysread(${$_}{'read'}, my $line, 100); #problem here chomp($l...

How to add Scrollbar to the Mainwindow using Perl TK

I want to add scroll bar in my main window. How can I add scroll bar in my main window. Please help me. ...

Application process never terminates on each run

I am seeing an application always remains live even after closing the application using my Perl script below. Also, for the subsequent runs, it always says that "The process cannot access the file because it is being used by another process. iperf.exe -u -s -p 5001 successful. Output was:" So every time I have to change the file name $...

How do I get the output of Win32::Process command in Perl?

I am using use Win32::Process for my application run as below. It runs fine, but I did not get any way to get the output to a .txt file. I used NORMAL_PRIORITY_CLASS rather than CREATE_NEW_CONSOLE to get the output on the same terminal itself, but I don't know how to redirect it to a txt file. /rocky #!/usr/bin/perl use strict; use w...

Insertion with Regex to format a date (Perl)

Hello. Suppose I have a string 04032010. I want it to be 04/03/2010. How would I insert the slashes with a regex? ...

Talking with a Bittorrent client listening on a port?

I have one of my computers seeding a torrent file on port 45000. I am trying to write a small client in python (or perhaps perl) that helps me to determine the types of messages this client supports for which I need to perhaps do a handshake with the client. In Azureus, this is done using a call like peer.getSupportedMessages(). Is it po...

Perl - Internal File (create and execute)

I have a quick question about creating files with perl and executing them. I wanted to know if it was possible to generate a file using perl (I actually need a .bat script) and then execute this file internally to the program. I know I can create files, and I have with perl, however, I'm wanting to do this internally to the program. S...