perl

How can I create an enum type in Perl?

I need to pass back a enum value in perl, how can I do this? pulling from this thread: http://stackoverflow.com/questions/473666/does-perl-have-an-enumeration-type use strict; use constant { HOME => 'home', WORK => 'work', MOBILE => 'mobile', }; my $phone_number->{type} = HOME; print "Enum: ".$phone_number->{type}."\n...

How can I extract A records that also have TXT records in Perl?

Hi, I'm having data like this: uniqname1.foo.bar IN A 10.0.0.1 uniqname1.foo.bar IN TXT "abcdefg" uniqname2.foo.bar IN A 10.0.0.2 uniqname2.foo.bar IN TXT "xyz" uniqname3.foo.bar IN A 10.0.0.3 uniqname4.foo.bar IN A 10.0.0.4` You get the picture, not every host has a TXT, some do. I try to get a regex which would print out 3...

Why does my regular expression fail with certain substitutions?

I am new to perl and not sure how to achieve the following. I am reading a file and putting the lines in a variable called $tline. Next, I am trying to replace some character from the $tline. This substitution fails if $tline has some special characters like (, ?,= etc in it. How to escape the special characters from this variable $tline...

Is hungarian notation applicable to Perl?

In Perl, reference to anything is a simple scalar, and has the $ sigil. It's sometimes hard to say what kind of reference it is. I personally prefix variable names for references with a letter, which indicates ref type. Examples: my $aValues = []; # arrayref my $hValue = {}; # hashref my $oValue = b...

How can I set the level of precision for Perl's bignum?

I'm trying to use the bignum module in Perl and want to set the precision. I know this can be done via a one liner as detailed on the module's CPAN page: $ perl -Mbignum=p,-50 -le 'print sqrt(20)' ...which will print out the square root of 20 to 50 digits of precision, but what I'm wondering is if there's anyway to set the precision ...

How can I use a regular expression to validate month input?

Greetings, I am setting up this example Perl snippet to validate for months in a date: Some scenarios I want to accept are: MM M #!/usr/bin/perl use strict; use warnings; my $pattern; my $month = "(0[1-9]|1[012])"; my $day = "(0[1-9]|[12]\d|3[01])"; system("cls"); do { print "Enter in a month: "; chomp($pattern = <STDIN>)...

How can I create or associate a super column to a column in Perl using Net::Cassandra?

How can I create or associate a super column to a column in Perl using Net::Cassandra? ...

Where can I find some simple W3C Validator API info for Perl?

Where can I find some simple W3C Validator API info for Perl? I've tried looking and just keeps leading to page after page of documentation. Simply looking for download module or whatever is needed (I am new to Perl but I want to use it for this project) How to install it (Again, new to Perl) There was going to be a third about documen...

Reformatting code with Regular Expressions

We have an ArrayList of items in several classes which are giving me trouble every time I'd like to insert a new item into the list. It was a mistake on my part to have designed the classes in the way I did but changing the design now would be more headache than it's worth (bureaucratic waterfall model.) I should have anticipated forma...

How can I accept multiple TCP connections in Perl?

I have a problem with Perl script for Linux. It's main purpose is to be middleman between 3 applications. What it should do: It should be able to wait for UDP text (without spaces) on $udp_port When it receives that UDP text it should forward it to the TCP client that is connected Problem is my app currently works until the first t...

How can I rewrite URLs except those of a particular domain?

Hi. Can you please help me to make perl regexp to replace (http://.+) to http://www.my1.com/redir?$1 but do nothing for urls like http://www.my1.com/ or http://my1.com/ For instance I need to replace http://whole.url.site.com/foo.htm to http://www.my1.com/redir?http://whole.url.site.com/foo.htm http://www.google.com to http://www.my1.co...

What's the best way to get the UTC offset in Perl?

I need to get the UTC offset of the current time zone in Perl in a cross platform (Windows and various flavors of Unix) way. It should meet this format: zzzzzz, which represents ±hh:mm in relation to UTC It looks like I should be able to get it via strftime(), but it doesn't appear to be consistent. Unix: Input: perl -MPOSIX -e ...

Is Perl's flip-flop operator bugged? It has global state, how can I reset it?

I'm dismayed. Ok, so this was probably the most fun perl bug I've ever found. Even today I'm learning new stuff about perl. Essentially, the flip-flop operator .. which returns false until the left-hand-side returns true, and then true until the right-hand-side returns false keep global state (or that is what I assume.) My question is c...

How can I create a shell with history in my Perl program?

I'm writing a tool that is executed as a shell in Perl. I want it to have a history, so that if you press the up arrow, you go back to the previous command, just like bash or other shells. How should I go about this? -- EDIT -- Thanks to daxim for pointing me towards Term::ReadLine::Gnu. I was able to get it to work on my Linux box and...

Setting NULL datetime with Rose::DB::Object and MySQL

I could be wrong here, but it looks like there's conflicting standards here. MySQL treats a stored datetime of "0000-00-00 00:00:00" as being equivalent to NULL. (update - only, it seems, if the datetime is defined as NOT NULL) But Rose::DB::Object uses DateTime for MySQL DATETIME fields, and trying to set a null DATETIME from "0000-00...

How can I change from a sed to Perl statement in command line?

Hi everyone, I need to search a phrase in multi files and display the results on the screen. grep "EMS" SCALE_* | sed -e "s/SCALE_//" -e "s/_main_.*log:/ /" Since I am not get familiar with sed, I change it to Perl for convenient use. grep "EMS" SCALE_* | perl -e "s/SCALE_//" -e "s/_main_.*log:/ /" or grep "EMS" SCALE_* | perl -...

Why does perl complain about "Too many arguments for open" when I run it in a shell script?

I run my Perl script (gettotal.pl) and it works fine. I managed to get the sum of TOTAL.txt and append the output value to test.txt. But when I run it inside shell script (test.sh) I got this error: Too many arguments for open at /home/daily/scripts/per_NODE_HR/gettotal.pl line 29, near ""$dir")" Execution of /home/daily/scripts/pe...

How should I use Perl's scalar range operator?

What is the scalar ".." operator typical usage? Is it only selecting blocks of text? Interesting example by myself: sub get_next { print scalar($$..!$$), "\n"; } get_next for 1 .. 5; # prints numbers from 1 to 5 get_next for 1 .. 5; # prints numbers from 6 to 10 ...

Is it faster to access data from files or a database server?

If I have a static database consisting of folders and files, would access and manipulation be faster than SQL server type databases, considering this would be used in a CGI script? When working with files and folders, what are the tricks to better performance? ...

How can I detach a process from a CGI so I can store and read files from memory?

Is it possible that I would be able to spawn a detached daemon like process, from a CGI script that stores read text files in memory, then re-access the memory in the next cgi execution, reading the data using a pipe? Would most hosting ISP's, allow detached processes? Are memory pipes fast, and easy to code/work with on a unix/linux sy...