perl

Is "map" a loop?

While answering this question, I came to realize that I was not sure whether Perl's map can be considered a loop or not? On one hand, it quacks/walks like a loop (does O(n) work, can be easily re-written by an equivalent loop, and sort of fits the common definition = "a sequence of instructions that is continually repeated"). On the ot...

Can't create socket using IO::Socket

when I run the following code, the execution is just hanging there, No response at all. does any of you can tell me what's wrong with the sample code? use strict; use warnings; use IO::Select; use IO::Socket; my $s = new IO::Socket ( LocalPort => 8889, Proto => 'tcp', ...

how to make a python or perl script portable to both linux and windows?

I was wondering how to make a python script portable to both linux and windows? One problem I see is shebang. How to write the shebang so that the script can be run on both windows and linux? Are there other problems besides shebang that I should know? Is the solution same for perl script? Thanks and regards! ...

how to escape slashes in perl text used in a regular expression?

end_date=$(date +"%m/%d/%Y") /usr/bin/perl -pi -e "s/_end_date_/${end_date}/g" filename I want to replace string '_end_date_' with current date. Since current date has slashes in it(yes I want the slashes), I need to escape them. How can I do this? I've tried several ways like replacing slashes with "\/" using sed and perl itself but ...

Perl and Multimap

Is there way to implement a C++ multimap in perl? ...

Permission denied (publickey,keyboard-interactive)

Permission denied (publickey,keyboard-interactive) got this error while i am trying to cvs checkout from perl. what is issue and how to reslove this ? Code : system ( "CSVROOT:--- CVSRSH:--- cvs co a "); # i have proper value in cvs root and cvs rsh . its running alone and using ssh key ...

Adding an Include Path for a Module in a Simple Perl Tutorial

I'm trying to do a simple tutorial but I'm having trouble getting started. My problem seems to be installing and getting the correct path to the modules. 1. Here is the original code:* #!/usr/bin/perl -w use strict; use LWP 5.64; my $browser = LWP::UserAgent->new; my $url = 'http://www.cspan.org/RECENT.html'; my $response = $browser->...

perl debugger freezes

First time perl user and I am trying to debug some script to follow project logic and of course syntax. Using cygwin after entering at command line $ $ perl -d sample.pl Loading DB routines from perl5db.pl version 1.3 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(sample.pl:5): pr...

Perl Regular Expression [] for <>

So I am trying to read an XML file into a string in Perl and send it as part of a SOAP message. I know this is not ideal as there are methods for SOAP sending files, however, I am limited to having to use the SOAP that is set up, and it is not set up for sending with file support. Therefore I need to parse out the markup tags <> and re...

How do you break on a specific line of a require'd file in the Perl debugger?

I've got a Perl script, let's call it A.pl where the first two lines look something like this: require 'B.pl'; require 'C.pl'; Where both B.pl and C.pl each have their own cavalcade of requires. I need to set a breakpoint on a specific line of C.pl. In GDB I'd do something like: b C.pl:830 However that doesn't seem to work at all...

How do I use google API within perl CGI script?

The google API example shows that you should have the javascript within the head tag but I am using perl module CGI and in there they suggest that you use "print header;" instead of writting out your headers explicitly. So if I want to use the perl CGI module and the google API javascript what is the correct way to do this? I tried w...

How can I pass an array resulting from a Perl method by reference?

Some XML::LibXML methods return arrays instead of references to arrays. Instead of doing this: $self->process_items($xml->findnodes('items/item')); I want to do something like: $self->process_items(\$xml->findnodes('items/item')); So that in process_items() I can dereference the original array instead of creating a copy: sub proc...

How do I stop cpan from reconfiguring each time? + More

I'm running on a Mac (version 10.6.3) and am struggling to understand what is going on with my Perl installation. I let the system do a copy from my previous mac, and I appear to have a second perl installed, which appears earlier in my path. I can't tell (or remember) if I might have installed it with fink, macports or CPAN or what. t...

Deleting N lines from every start point

How would I delete the 6 lines starting from every instance of a word i see? ...

How can I store and access a filehandle in a Perl class?

please look at the following code first. #! /usr/bin/perl package foo; sub new { my $pkg = shift; my $self = {}; my $self->{_fd} = undef; bless $self, $pkg; return $self; } sub Setfd { my $self = shift; my $fd = shift; $self_->{_fd} = $fd; } sub write { my $self = shift; print $self->{_fd} ...

Perl OO frameworks and program design - Moose and Conway's inside-out objects (Class::Std)

This is more of a use-case type of question... but also generic enough to be more broadly applicable: In short, I'm working on a module that's more or less a command-line wrapper; OO naturally. Without going into too many details (unless someone wants them), there isn't a crazy amount of complexity to the system, but it did feel natur...

Is it possible to use a Perl hash in a manner that has `O(log(n))` lookup and insertion?

Is it possible to use a Perl hash in a manner that has O(log(n)) lookup and insertion? By default, I assume the lookup is O(n) since it's represented by an unsorted list. I know I could create a data structure to satisfy this (ie, a tree, etc) however, it would be nicer if it was built in and could be used as a normal hash (ie, with %...

Can I use a filehandle instead of a filename for creating DBM files?

I'm using MLDBM to persist some Perl data structures and I'm wondering if there's an alternative to the following: tie %hash, "MLDBM", $dbm_file, O_CREAT | O_RDWR, 0644; Primarily, I'd like to be able to use STDOUT, rather than a known file name. This could then be redirected to a file on the shell-side. I've been searching with keyw...

Programmatically determining the status of a file download

Is there a way I can programmatically determine the status of a download in Chrome or Mozilla Firefox? I would like to know if the download was aborted or completed successfully. For writing the code I'd be using either Perl, PHP or Python. Please help. Thank You. ...

Perl throws an error message about syntax

So, building off a question about string matching (this thread), I am working on implementing that info in solution 3 into a working solution to the problem I am working on. However, I am getting errors, specifically about this line of the below function: next if @$args->{search_in} !~ /@$cur[1]/; syntax error at ./db_index.pl line 16...