How can I choose a random value between 0 and a bigint?

I have a combinatorics problem for which I want to be able to pick an integer at random between 0 and a big integer. Inadequacies of my current approach Now for regular integers I would usually write something like int rand 500; and be done with it.

Test if a string contains one of the words in another

I have a Perl program code that pulls a description string from a hash. I have my variable $ui equal to the variable $uniqueID, but what I want is to return true if $ui contains any words in variable $unqiueID. But =~ isn't working. Is there a smart

Reading a CSV file and writing to a CSV file

use Text::CSV; $csv = Text::CSV->new; open(HIGH, "+>Hardtest.csv") || die "Cannot open ticket $!\n"; #reads the high file while(<HIGH>) { print "Printing High Priority Tickets ...\n"; sleep(1); print <HIGH>;

Delete a line with a pattern unless another pattern is found?

I have a very messy data file, that can look something like this ======== Line 1 dfa====dsfdas== Line 2 df as TOTAL ============ I would like to delete all the lines with "=" only in them, but keep the line if TOTAL is also in the line. My code

How can I get the time to run a Perl program?

How can I get execution time if I stop it? Example I run my perl script and I press terminal shortcut CTRL+C or CTRL+Z to stop it, then post the execution time. This is posible or not?On Linux, you can use the program time to get the execution time.

unable to execute the Perl script, use the command not found?

I have an xml file (client_23.xml) in which I need to add few lines at a particular section basis on what is there in other xml file (abc_lop.xml). Here is my abc_lop.xml file in which you see I have lot of ClientField lines with name, pptype and dat

Perl: RegEx: Storing Variable Lines in the Array

I'm developing a Perl script and one of the script functions is to detect many lines of data between two terminals and store them in an array. I need to store all lines in an array but to be grouped separately as 1st line in $1 and 2nd in $2 and so o

Perl: Extract an element from XML :: Twig

How would I extract a single element from an XML document using XML::Twig? XML Code: <report> <reportheader> <month>February 2015</month> </reportheader> </report> What I've tried XML::Twig->new( twig_handlers =>

how do i edit a text file by perl

I want to make 'find/change' function. open original file. change some words through using s/ / / or tr/ / / but it's not working, i think. open(TXT, ">>text.txt"); my $str = <TXT>; $str =~ s/'a'/'b'/; print TXT $str; Look at this ex

Devel :: Size reported sub size

I was just reading this article from Gabor Szabo and he pointed out that Devel::Size reports that a simple sub {} is reported as requiring 8,516 bytes of space. Is this reported size correct? If so, why does Perl need to allocate so much space for a

Perl Match Substring in a chain ignore spaces

I have a string $str = "xxxxxx Code File(s) Name:Some_thing.c CodeFile(s) Version:27 Design Document:some_other_design.doc Module Design Document Version:43 somexxxxxxxxxx Compiler Version:9.5 Doc Type:Word xxxxxx"; where xxxxx represents any ch

IPN PayPal: Can not Obtain Local Issuer Certificate

I am using curl to verify the PayPal IPN but it throws error: SSL certificate problem: unable to get local issuer certificate. The same code is working on development server and when I moved to client server it is not working. DO I need to purchase s

How can I make the attribution of arguments in Perl?

When calling a perl script with: myPerlScript --myarg 10 --my2Darg 42x87. How do I make the assignments: $myarg = 10; $my2Darg_x = 42; $my2Darg_y = 87; if and only if myarg and my2Darg is valid arguments? I think I need something like this: #!/usr/bi

Why does DateTime add a T separator to the timestamp?

My code: print DateTime->now; Response: 2012-08-17T20:16:37 Why is there a T? Is there an option I have forgotten?The T is just a standard (ISO 8601) way to delimit the time. To use a different format, consider using strftime or format_cldr. For exam

How to treat a char string by char in the XS code

Let's suppose there is a piece of code like this: my $str = 'some text'; my $result = my_subroutine($str); and my_subroutine() should be implemented as Perl XS code. For example it could return the sum of bytes of the (unicode) string. In the XS code

What is $ dummy and split without parameter means in Perl?

I need some help decoding this perl script. $dummy is not initialized with anything throughout anywhere else in the script. What does the following line mean in the script? and why does it mean when the split function doesn't have any parameter? ($du

Perl: Unexpected Behavior with Website Scraping

I'm using WWW::Mechanize and HTML::TokeParser to parse a website for updates. I cannot give any details on the website because it requires a login. The website essentially has a table of data. I'm simply parsing the html till I get to the first row o

Pass the text box entry to the perl script on the server

Sorry in advance for a potentially dumb newbie question, but here goes. I am learning web app programming and I would like to have an input textbox on my webpage where the user enters some text. Then I capture that text and pass to a perl script whic

What types of neat use cases exist for given / when?

Perl 5.10 introduced a proper switch construct with given/when and it seems like a powerful tool. Currently however, perldoc perlsyn lacks some good examples. One case where I found it handy lately was for using it with file test operators: given (-d

How can I print only all three indexes in Perl or Python?

How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array.Python print list[::3] # print it newlist = list[::3] # copy it Perl for ($i = 0; $i < @list;