perl

In Perl, is there a built in way to compare two arrays for equality?

I have two arrays of strings that I would like to compare for equality: my @array1 = ("part1", "part2", "part3", "part4"); my @array2 = ("part1", "PART2", "part3", "part4"); Is there a built-in way to compare arrays like there is for scalars? I tried: if (@array1 == @array2) {...} but it just evaluated each array in scalar context,...

How can I select a random name from a list and store it in a variable?

Hello, I'm already developing that project to my family, but now i'm needing to link a Name to another aleatory(remember that the first name i have it) and store only the second name in a variable, remember that this list is a file(*.txt) with some names, but how i can do this? Thanks. ...

Configuring form_path in Catalyst::Controller::Formbuilder

Using the Catalyst::Controller::FormBuilder module to handle forms in a Catalyst application. The documentation says you can set the form_path like this: form_path => File::Spec->catfile( $c->config->{home}, 'root', 'forms' ), But the call to config() in my application is at the top level of the base module. Therefore, $c is undefined...

How do I split up a line and rearrange its elements?

I have some data on a single line like below abc edf xyz rfg yeg udh I want to present the data as below abc xyz yeg edf rfg udh so that alternate fields are printed with newline separated. Are there any one liners for this? ...

How can I replace a column of one file with a column of another using Perl?

Suppose File 1 has two columns and looks something like: fuzz n. flowering shrub of the rhododendron family dyspeptic adj. bright blue, as of the sky dysplexi adj. of Byzantium or the E Roman Empire eyrie adj. of the Czech Republic or Bohemia azalea adj. suffering from dyslexia Czech adj. suff...

How can I replace all hotmail.com addresses in a file with another email address, using Perl?

Hello all, I have multiple email id's in some config files in a directory; I'm running my scripts on a Solaris machine. I want to perform the following: Find all the email_id's in the config files in a directory: eg: [email protected] ; [email protected] ; [email protected] ; [email protected] Replace all existing id's with: wxyz@hotmail....

How can I convert an input file to UTF-8 encoding in Perl?

I already know how to convert the non-utf8-encoded content of a file line by line to UTF-8 encode, using something like the following code: # outfile.txt is in GB-2312 encode open my $filter,"<",'c:/outfile.txt'; while(<$filter>){ #convert each line of outfile.txt to UTF-8 encoding $_ = Encode::decode("gb2312", $_); ...} ...

Parsing XML - right scripting languages / packages for the job?

I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions. Thanks! UPDATE: I ended up going with XML::Simple which did a nice job, but I have one piece of advice if you ...

Modifying an XML File using Perl

I have an XML file, with some format. I want the data to be modified in some way I want. I feel XML::Twig is the way to do it. I want to know if there is any other better alternative? ...

How can I extract the first paragraph of a PDF document using Perl's CAM::PDF?

How can I extract the first paragraph of a PDF document using Perl's CAM::PDF? ...

What is the best way to insert <wbr /> tag in HTML from backend

We deal with alot of UGC (1m+/mo) and sometimes our users will input large strings with no spaces which causes web browsers to display content in a strange manner, breaking UI here and there. I am trying to find a way to intelligently and quickly process text up to 50k and insert tags where appropriate. I have already built this, but ...

How do I change this to "idiomatic" Perl?

I am beginning to delve deeper into Perl, but am having trouble writing "Perl-ly" code instead of writing C in Perl. How can I change the following code to use more Perl idioms, and how should I go about learning the idioms? Just an explanation of what it is doing: This routine is part of a module that aligns DNA or amino acid sequences...

Using Perl with compiled C library?

I would like to try and use Perl, but need to communicate with another application I wrote. I have an interface library that I wrote in C++, and it contains the socket communications and interface protocol to set/get parameters in my application. I would like to use Perl with Apache to serve up web pages for configuring my application....

How can I parse XML using Perl?

I have a file which has <Doc> <Text> .... </Text> </Doc> <Doc> <Text> </Text> </Doc> How do I extract only the <text> elements, process them and then extract the next text element efficiently? I do not know how many I have in a file? ...

Why does my Perl script complain about "Global symbol "$random_name" requires explicit package name"?

Hello, I'm learning Perl and at the same time I'm creating a program to my family events, but when I'm trying to use a array with a randomization process I'm getting some errors, as you could see: [ubuntu@eeepc:~/Desktop/mail] ./get.pl -h pop.vix.terra.com.br -u nathanpc -p (:D) Global symbol "$random_name" requires explicit package n...

How can I merge the overlapping elements using Perl?

I've already learnt how to remove duplicates in Perl using the following code: my %seen = (); my @unique = grep { ! $seen{ $_}++ } @array; But what about if I want to merge the overlapping parts? Is there a simple way like the above code to directly do the job? For example a bit of the input file looks something like this: Anais Ni...

How do I interpolate a Perl hash element in a string?

How do I print a hash from within a string, as in print "\n[*] Query : $select { query }"; versus print "\n[*] Query : " . $select { query }; ...

What's the history of the + in front of a hashref that disambiguates from a code block?

I would like to read a little more about the + that is usually put in front of a hashref that helps to disambiguate from a code block. When was it first introduced? Who first introduced it (recommended it)? How did people go around the issue before this was introduced? Any trivia or notes that comes to mind while using this syntax? ...

Creating a sort of "composable" parser for log files

Hi! I've started a little pet project to parse log files for Team Fortress 2. The log files have an event on each line, such as the following: L 10/23/2009 - 21:03:43: "Mmm... Cycles!<67><STEAM_0:1:4779289><Red>" killed "monkey<77><STEAM_0:0:20001959><Blue>" with "sniperrifle" (customkill "headshot") (attacker_position "1848 813 94") (...

How can I print the syntax tree of all functions in a Perl program?

Hi, perl -MO=Concise,-exec myprog.pl should do it but it only prints the syntax of the lines that are outside any procedures, and the main package itself. It does not print the syntax tree of packages and functions used in myprog and imported. Could someone tell me how to tell "B::Concise" to print all functions in myprog.pl. ...