perl

perl + how to use chomp in foreach loop

hi all the following perl script (Showing down) print the following XML file but the XML have problem because the unnecessary "&#10" char after TEST word <ROOT> <FILE Name="TEST1&#10;"/> <FILE Name="TEST2&#10;"/> <FILE Name="TEST&#10;"/>ar </ROOT> I think the "&#10" characters its because the linebreak (read the outp...

Transpose in perl

Hi all, I have started learning perl and like to try out new things. I have some problem in text processing. I have some text of the form, 0 1 2 3 4 5 6 7 8 9 10 6 7 3 6 9 3 1 5 2 4 6 I want to transpose this text. Like, I want to make rows as columns ans columns as rows. Id there a way to do this in perl? Thank you all. ...

Perl way to create sockets quickly (1000+)

I have a Perl server and when it boots up, it connects to 1000+ clients. It takes about 30-45 minutes to setup all the connections with SSL. I'm trying to decrease the start time to something more reasonable. I tried playing with threads to offload the work, but can't get it to work. Creating the socket in one thread and getting it back ...

Get Facebook User ID By Email Address

We have over 10,000 registered users on our site and want to associate each user with a Facebook account with their facebook ID. Our site uses the WWW::Facebook::API CPAN module for all our other Facebook related actions on our site. My question is, is there a method where we can provide a specific user's email address (which they have p...

Perl array manipulation

Is there a single line in perl which does some magic like this. Array = [100,200,300,400,500]; percent = 50% new_Array = [50,100,150,200,250]; That is, I give an array and specify a percent. And it should give me a new array with the given percent of original array values. should take care of odd numbers and give me either ceiling ...

Correct way to instantiate a Moose object from another Moose object?

What is the correct way to create an instance from another Moose object? In practice I've seen this done numerous ways: $obj->meta->name->new() $obj->new() ## which has been deprecated and undeprecated (blessed $obj)->new() -- and, its bastard variant: (ref $obj)->new() $obj->meta->new_object() And, then what if you have traits? Is t...

Embedding evaluations in Perl regex

So i'm writing a quick perl script that cleans up some HTML code and runs it through a html -> pdf program. I want to lose as little information as possible, so I'd like to extend my textareas to fit all the text that is currently in them. This means, in my case, setting the number of rows to a calculated value based on the value of the ...

perl array initialization

Hi, How do I initialize an array to 0. I have tried this. my @arr = (); but it always throws me a warning "Use of uninitialized value" I do not know the size of the array before. I fill it dynamically. I thought the above piece of code was supposed to initialize it to 0. Can anybody tell me how to do this. Thank you. ...

Perl threads slowly consume memory

I am running a Perl server with 10 threads. They never get destroyed until the program exits, but this is something I intend to have as much uptime as possible, so that's why this is an issue for me. The threads handle a simple task many times. When I start the server and all the threads are started, I see that I have 288.30 MB free. Aft...

Perl web scraper, extract content from DIV that only has "style" tag?

I'm stuck on this and have been all day.. I'm still pretty new to parsing / scraping in perl but I thought I had it down until this.. I have been trying this with different perl modules (tokeparser, tokeparser:simple, web parser and some others)... I have the following string (which in reality is actually an entire HTML page, but this is...

Using socks5 proxy with Net::SMTP

I would like to use Net::SMTP with dynamic socks proxy. IO::Socket::Socks is aware of socks but how it should be used with net::smtp? ...

How do I parse this text file using only regular expressions?

Consider a log file which contains r100000|Tom Sawyer|2010-12-01|view.txt I should parse this and print ID:r100000 NAME:Tom Sawyer DATE:2010-12-01 FILENAME:view.txt I should only use regular expressions. ...

Perl equivalent of Ruby's `reject!`?

I need to walk over an array, and conditionally delete elements, in Perl. I know about slice, but am not sure how to use it in a foreach context. In Ruby, there is reject!: foo = [2, 3, 6, 7] foo.reject! { |x| x > 3 } p foo # outputs "[2, 3]" Is there a Perl equivalent? ...

why are function calls in Perl loops so slow?

I was writing a file parser in Perl, so had to loop through file. File consists of fixed length records and I wanted to make a separate function that parses given record and call that function in a loop. However, final result turned to be slow with big files and my guess was that I shouldn't use external function. So I made some dummy te...

Unable to auomate SWF component using Selenium

I am automating test for a website using selenium, but selenium is not able to identify SWF components. Please let me know if there's a way to automate SWF components with Selenium & perl. Here's the test link to check proof of concept: http://demo.swfupload.org/v220/simpledemo/index.php ...

How to push to array with distinct values

@tools = ("hammer", "chisel", "screwdriver", "boltcutter", "tape", "punch", "pliers"); @fretools =("hammer", "chisel", "screwdriver" ,"blade"); push @tools,@fretools if grep @tools,@fretools and i have get tools @tools=("hammer", "chisel", "screwdriver", "boltcutter", "tape", "punch", "pliers", "blade"); is t...

How to make perl thread without copying all variables?

I have one perl program, where using some form of parallelism would really be helpful. However, I have quite a lot of data in variables, that I don't need at all at that part of the program. If I use perl threads, it copies all variables every time I create a new thread. In my case, that hurts a lot. What should I use to make a new th...

perl - text processing - output to csv file

Hi, Is there a way in perl to export data from a file to csv file. What I mean is, Say I have a file as follows.. field1=value1,filed2=value2 field1=value3,filed2=value4 field1=value5,filed2=value6 I want to export this to excel format as follows. field1 field2 value1 value2 value3 value4 value5 value6 anyway of doing this?? ...

What are good Perl Pattern-matching / Regex Modules?

I've been having a need to do a lot of regex / pattern-matching stuff lately and, in looking at different examples / forum posts from my web searches it seems people sometimes mention that perl has good modules to help in simplifying pattern matching / regex tasks, however they neglect to mention which ones are the best for this.. I have...

Perl and NLP, parse Names out of Biographies

I'm pretty new to NLP in general, but getting really good at Perl, and I was wondering what kind of powerful NLP modules are out there. Basically, I have a file with a bunch of paragraphs, and some of them are people's biographies. So, first I need to look for a person's name, and that helps with the rest of the process later. So I was ...