perl

Why do my Perl threads execute randomly on the first run but in order on subsequent runs?

In the course of testing the code for the question How can I store per-thread state between calls in Perl? I noticed that the first I time execute the script the threads execution are fairly well interleaved with each other. But on all subsequent executions of the script all the threads run almost perfectly in the order of their creatio...

Why does DBD::CSV complain about "Loose unescaped quote"?

Hello! Why does reading from __DATA__ work and reading from the file doesn't (Loose unescaped quote)? #!/usr/bin/env perl use warnings; use strict; use 5.010; use DBI; my $table = 'klassik_CD.csv'; print qx(cat $table); print qq{\n"data" or "Enter" : }; chomp( my $aw = <> ); if ( $aw eq 'data' ) { $table = 'te_mp_fi_le.csv'; ...

How can I extract parts of this filename in Perl?

In my Excel sheet with column Changeset I am getting the changeset like: C:\ccviews\hgdasdff-9302\dfcsz\ahgrt\kjhssl\ASGHLS@@\main\ajsdkljlat\hahdasdhfk\1\test.txt\sub\hsdaklfl\3 I need to use split function in a Perl script so that there will be two ouput (input as the above string) the part before @@ (e.g-here C:\ccviews\hgdasdff-...

How can I fix "Execution of -e aborted due to compilation errors" in a Perl module Makefile?

I'm on Windows using Strawberry Perl. I run perl Makefile.pl for the Buckwalter Encode module, that works fine. When I run make, it says Execution of -e aborted due to compilation errors What is -e? Which file do I go to fix the error? Apparently there's a missing curly bracket on line 1, but I don't know which file has that missi...

Are there any use cases where string eval is necessary in Perl?

Can you provide any examples where using eval EXPR is really necessary? I'm asking because its generally discouraged. ...

Are keys and values of %INC platform-dependent or not?

I'd like to get the full filename of an included module. Consider this code: package MyTest; my $path = join '/', split /::/, __PACKAGE__; $path .= ".pm"; print "$INC{$path}\n"; 1; $ perl -Ipath/to/module -MMyTest -e0 path/to/module/MyTest.pm Will it work on all platforms? perlvar The hash %INC contains entries for each ...

Is Perl's inet_aton thread-safe?

Is inet_aton Thread-Safe? I know according to UNP that POSIX doesn't require a lot of the Sockets API to be thread safe, and so I have to assume they're not, but in general how do I know if something is thread safe in Perl? To what extent do I need to lock library function that I call? And how do I lock them? When I try something lik...

How does this obfuscated Perl code work?

How does this code work at all? #!/usr/bin/perl $i=4;$|=@f=map{("!"x$i++)."K$_^\x{0e}"} "BQI!\\","BQI\\","BQI","BQ","B","";push @f,reverse@f[1..5];@f=map{join"",undef, map{chr(ord()-1)}split""}@f;{;$f=shift@ f;print$f;push@f,$f;select undef,undef, undef,.25;redo;last;exit;print or die;} ...

How can I represent a file system's symbolic links in a Perl hash?

On Server Fault, How to list symbolic link chains? (not my question) talks about listing all the symbolic links and following them. To make this doable, let's consider a single directory at first. I want to write a short utility that does this. It looks easy to put pairs from symbolic links into a hash and then process the hash. But ...

Why can't I add a chart to my Excel spreadsheet with Perl's Spreadsheet::WriteExcel

When creating a chart in a spreadsheet using Spreadsheet::WriteExcel, the file it creates keeps coming up with an error reading Excel found unreadable content in "Report.xls" and asks me if I want to recover it. I have worked it out that the problem line in the code is where I actually insert the chart, with $chartworksheet->inse...

How do I change, delete, or insert a line in a file, or append to the beginning of a file in Perl?

People keep asking this question and I keep answering it with the same answer from perlfaq5. Now it's something we can point to on Stackoverflow. ...

Are MooseX::Declare and MooseX::Method::Signatures production ready?

From the current version (0.98) of the Moose::Manual::MooseX are the lines: We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare. However, these modules, while used regularly in production by some of the more insane members of the community, are still marked alpha just in case backwards in...

ack does not work when run from "grep-find" in Emacs on Windows

I'm trying to use ack-grep as a replacement for grep + find in Emacs on Windows, but ack-grep exits immediately (successfully) without printing any matches. I've tried just about every conceivable combination of command-line parameters to ack-grep, but nothing seems to work. M-x grep-find Enter "ack html" to search for files containin...

How can I diagnose problems with Perl's getc?

I am having this strange problems with the getc function. I use getc to get a character from a socket file handler. I need to simulate message exchanges between pc and a mobile device. For the first few messages, getc works fine. But for this one, getc couldn't get anything from the socket. The whole Perl program blocked until I reset th...

How do I manage multiple subprocesses in Perl?

I have a Perl program that needs to run about half a dozen programs at the same time in the background and wait for them all to finish before continuing. It is also very important that the exit status of each can be captured. Is there a common idiom for doing this in Perl? I'm currently thinking of using threads. ...

How can I run passwd -S and capture its output in Perl?

I want to scan the passwd file and print only lines if the user is not locked. That is, passwd -S $user does not return "Password: locked." I can do easily in ksh. What is the best way to do this in Perl? ...

Capture or redirect open browser window event from a Java program

Hi. I have a Java program, that opens a new browser window when I click on on a menu. The Java program requires login, so the html page has a Session ID. I want to access this page with my C# program, so that I can extract some data from it. Unfortunately, the only way to get to this html page is through the Java client's menu, so the...

How can I execute Perl code specified on the command line?

I want something like.. all_objects.pl my $sub = $ARGV[1]; ... @objs = get_all_objects(); for my $obj (@objs) { // invoke subroutine $sub with param as $obj. } now if I say all_objects.pl "print 'x '" all_objects.pl "print '$_ '" I should get obj1 obj2 obj3 ... i.e. the command line arg act as a subroutine in some wa...

How can I pull a line out of /etc/passwd if its corresponding shadow entry is 999999?

I want to compare each user in the passwd file with his entry in the shadow file, and print out the whole line of the passwd file if the entry in the shadow file matches 999999. What is the easiest way in Perl to do this? Or I suppose I could awk the values out of one file and match in the other file? What is the best way of doing this...

How can I escape code-like things in a Perl string?

Hi, this code: $i=1; while($i<3) { print << "EOT"; def px$i = new E(user) if (!px$i.hasErrors()) { println "${px$i.name} / ${px$i.empr.to} OK" } EOT $i++; } produces the error: Can't call method "px" without a package or object reference at borrar.pl line 3. How can I "escape" the if ? Thanks....