perl

perl: how to sort a JSON structure on something other than "root" key attributes

Perl: How can I sort a complex structure using JSON::PP ? From the JSON Documentation: As the sorting routine runs in the JSON::PP scope, the given subroutine name and the special variables $a, $b will begin 'JSON::PP::'. Here is my attempt, does not seem to work open my $fh, ">", $file or warn " exportAsJSON: can't open f...

Perl, counting words with special characters

I need to count number of words including special characters like % ,$ in a particular section of an XML document. I need to write this in Perl script using regular expressions. Anyone has any suggestions on where I can start to look for more info as this is my first perl script. I need help with isolating the section and its data. ...

How to simulate a cron job

I want to run a script once day (and only on weekends), however, I cannot use cron job for that. I was thinking about having an infinite while loop, sleep for 24 hours, check if it is a weekend, and if so execute the script. What it's a good solution under bash on linux? my current implementation: #! /bin/bash while [ true ]; do ...

3-way communication via sockets

Good Afternoon Gurus, I am pretty familiar with basic socket programming, and the IO::Socket module but I need to code something now that I have not encountered before. It will be a 3 tier application. The first tier is an event-loop that sends messages upstream when certain events are encountered. The second tier is the 'middle-ware' ...

Regular Expression Help

I am learning regular expressions and I am trying find this string day1otlk_XXXX.gif where the 4 X's will be 3 to 4 random digits. This is what I have so far am I close? qr/day1otlk_\d++\.gif/i ...

python equivalent to perl's qw()

I do this a lot in Perl: printf "%8s %8s %8s\n", qw(date price ret); However, the best I can come up with in Python is print '%8s %8s %8s' % (tuple("date price ret".split())) I'm just wondering if there is a more elegant way of doing it? I'm fine if you tell me that's it and no improvement can be made. ...

How can I run perl and ruby scripts as tasks in ant?

I would like to be able to run ruby and perl scripts from build.xml in ant. ...

perl - help with hash and dumping of records

I have a perl script that is only keeping the last set of records for a named set and I have more than one set of records. So its over writing the data in the hash and just keeping the last set. I need help in printing out all the records. Thanks! Here's a copy of my script: #!/usr/local/bin/perl use strict; use warnings; use Data::D...

How to count connections to a host over a given time period? TCP logs?

If I do a sudo netstat -tup | awk '{print $5}' | sort | uniq -c | sort -n I can get a list and count of how many connections I have to each host. But how can I tell how many times I've been connecting to that host ever minute/hour/day? Is there a TCP log somewhere that I can grep through to see how and when I'm connecting to what? I...

find and replace double newlines with perl?

I'm cleaning up some web pages that for some reason have about 8 line breaks between tags. I wanted to remove most of them, and I tried this perl -pi -w -e "s/\n\n//g" *.html But no luck. For good measure, I tried perl -pi -w -e "s/\n//g" *.html and it did remove all my line breaks. What am I doing wrong? edit I also tried \r\n\r\...

A Moose role of roles

I'd like to set up a convenience Moose role made up of other smaller roles. For example, if I have WithAddress and WithPhone I would like a single WithContacts that provides both WithAddress and WithPhone and anything contact methods I add in the future. How can I do this with Moose? ...

Perl regex parse forward only; not end-to-start

Parsing HTML with regex is a bad idea, but it seems suitable for this situation. Description: Given a .html file, I must parse the internal links, extract the indent level, text of the link and the page number it resides on to an external .txt file which is then passed on to someone else. So given this sample HTML: <TR valign="bottom"...

How to read a file in and replace the value with a name

...

Deep cloning Moose object with attributes that are ArrayRef[Object] and Set::Object

I've got a Moose object: class My::Game { has 'players' => (isa => 'Set::Object', ...) has 'action_sequence' => (isa => 'ArrayRef[My::Game::Action]', ...) } Now I want to be able to clone this object with a call like $game2 = $game->clone; How do I deep clone it so that the objects in the ArrayRef are cloned? And more trickily, th...

How safe is the data being parsed by RTF editors like TinyMCE?

Hi Everyone, I have a great concern in deploying the TinyMCE editor on a website. Looking at the code parsed by the editor it does a great job, and I leave the HTML button off the toolbar configuration so users can not inject their own source. However, from what I read in the TinyMCE docs, it claims to degrade nicely to a regular texta...

How to check if variable is declared in perl?

I am using use strict; in perl and with that I use the following statement. unless(defined($x)){ print "Not defined"; } Where $x is not declared anywhere. So I expect it to print "Not defined" but it returns an error Global symbol "$x" requires explicit package name at *********** in line 15. ...

Splitting a string to remove surrounding < and > characters

I have a string like this <name>, I want to chop off the <> and take out only name and put it into a variable. How to do it using perl "split" function? ...

How to create multi-language topics/pages in TWiki?

Is there a "standard" way to create multi-language topics in TWiki? I am preparing a multilanguage site using TWiki as platform. TWiki has a descent I18N support. The user interface is translated in quite a lot of languages, but I want to create topics which has content in more than one language. Creating separate topics per language wou...

How do I visit consequent result pages at wigle.net using Mechanize?

I have the following code which uses the WWW::Mechanize and HTML::TableExtract modules. Everything works like a charm, except that I'm not capable of moving to the next pages. I'm trying to get a list of hotspots from http://www.wigle.net/gps/gps/main. The UserID is natty_a, the password is natty. Click on [searching], and then on Query....

Perl default variable $_

Hi all, I thought I understood map however the following has results that I don't understand. I know why it's happening I just don't know how it is happening. The problem is that the contents of @array are changing because $_ is being reset during _do_stuff_to_file call. so what is printed is here: \nhere:\n when I expect it to be her...