perl

Is there a way to get the PREMATCH ($`) and POSTMATCH ($') from pcrecpp?

Is there a way to obtain the C++ equivalent of Perl's PREMATCH ($`) and POSTMATCH ($') from pcrecpp? I would be happy with a string, a char *, or pairs indices/startpos+length that point at this. StringPiece seems like it might accomplish part of this, but I'm not certain how to get it. in perl: $_ = "Hello world"; if (/lo\s/) { $...

How can I count paragraphs in text file using Perl?

I need to create Perl code which allows counting paragraphs in text files. I tried this and doesn't work: open(READFILE, "<$filename") or die "could not open file \"$filename\":$!"; $paragraphs = 0; my($c); while($c = getc(READFILE)) { if($C ne"\n") { $paragraphs++; } } close(READFILE); print("Paragraphs: $paragraphs\n"); ...

How do I return a Perl variable to a ksh script?

I have a ksh script that calls a Perl program. The Perl program creates some important data that the ksh script needs to act on. Example: My ksh program: #!/usr/bin/ksh abc.pl > $logFile # perl pgm creates variable $importantData See below. # HOW DO I GET THE .KSH SCRIPT TO SEE $importantData ??? def.ksh $importantData # send impo...

How do I issue an HTTP redirect with Perl's CGI.pm?

Hello, I want to perform an HTTP redirect, but the way I am currently doing it isn't working. When I try redirect it just prints the status code, and the location header: my $q = new CGI; q->redirect(" http://www.google.com "); ...

How can I get colored output with printf and Perl's Term::ANSIColor?

Hello, is there a way to get with printf colored output? #!/usr/bin/perl use warnings; use strict; use Term::ANSIColor; printf "%4.4s\n", colored( '0123456789', 'magenta' ); Output: (only newline) ...

convert perl map with multiple key to c++

I want to convert a code from perl to c++, and my problem is multi key map in perl! example: perl: $address{name}{familyName} = $someAddress; and keys are not unique. I want similar data structure in c++ using map or ...!? also I want to search and obtain values with first key for example I want such %keys{name} in c++ . edited: I ...

Why can't my Perl subroutine see the value for the variable in the foreach loop that called it?

I hope this is something straightforward that I'm doing wrong. I saw something online about "variable suicide" that looked good, but it was for an older version and I'm on 5.10.1. Anyway - a variable that I declared - $RootDirectory - just suddenly loses its value, and I can't figure out why. Here's a script to reproduce the problem....

Why does Perl's DateTime::Astro::Sunrise give me unexpected values?

Using the example code included in the man page for DateTime::Astro::Sunrise, I'm getting back ~14:00 for the sunrise and ~2:00 for the sunset. My machine's time and timezone are set correctly (AFAIK). Am I reading something wrong? 2am and 2pm are just so brutually wrong. use DateTime; use DateTime::Astro::Sunrise; my $dt = DateTime-...

How can my CGI program access non-browseable files?

I was wondering if it was possible to read a text file that was located in a directory called "/home/user/files" I wanted to read it from my cgi-bin which is located in /home/user/cgi-bi/ Below is my code, #!/usr/bin/perl use strict; use CGI; #Virtual Directory #Steffan Harris eval { use constant PASSWORD => 'perl'; use constant U...

Is there a way that I can force mod_perl to re-use buffer memory?

Hi, I have a Perl script running in mod_perl that needs to write a large amount of data to the client, possibly over a long period. The behavior that I observe is that once I print and flush something, the buffer memory is not reclaimed even though I rflush (I know this can't be reclaimed back by the OS). Is that how mod_perl operates...

How can I transfer a hash using client and server in Perl?

I just want to transfer (send or receive) a hash from client to server. Can you tell me which is a preferable way in Perl or can you suggest any CPAN modules? ...

What is the best and useful debug tool in Linux environment for Perl and C++ scripts?

What is the best and useful debug tool in Linux environment for Perl and C++ scripts? In related to that, does anyone know the differences between Eclipse to DDD tools? Thank you, YoDar. ...

In Perl, how can I wait for threads to end in parallel?

I have a Perl script that launches 2 threads,one for each processor. I need it to wait for a thread to end, if one thread ends a new one is spawned. It seems that the join method blocks the rest of the program, therefore the second thread can't end until everything the first thread does is done which sort of defeats its purpose. I tried...

How can I download IMAP mail attachments over SSL and save them locally using Perl?

I need suggestions on how can I download attachments from my IMAP mails which have attachments and current date in subject line i.e. YYYYMMDD format and save the attachments to a local path. I went through the Perl module Mail::IMAPClient and am able to connect to the IMAP mail server, but need help on other tasks. One more thing to no...

How can I handle -r=<pattern> with Perl's Getopt::Long?

I am parsing command line options in Perl using Getopt::Long. I am forced to use prefix - (one dash) for short commands (-s) and -- (double dash) for long commands (e.g., --input=file). My problem is that there is one special option (-r=<pattern>) so it is long option for its requirement for argument, but it has to have one dash (-) pre...

In Perl, how can I get the Cartesian product of multiple sets?

I want to do permutation in Perl. For example I have three arrays: ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"]. How do I get: ["big", "red", "apple"] ["big", "red", "pear"] ..etc.. ["small", "green", "banana"] I understand this is called permutation. But I am not sure how ...

Why does my Perl CGI program fail with "Software error: ..."?

When I try to run my Perl CGI program, the returned web page tells me: Software error: For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error. Here is my code in one of the file: #!/usr/bin/perl use lib "/home/ecoopr/ecoopr.com/CPAN"; use CGI; use CGI::FormBuil...

Why does my Perl regex complain about "Unmatched ) in regex"?

if($title =~ s/(\s|^|,|\/|;|\|)$replace(\s|$|,|\/|;|\|)//ig) $title can be a set of titles ranging from President, MD, COO, CEO,... $replace can be (shareholder), (Owner) or the like. I keep getting this error. I have checked for improperly balanced '(', ')', no dice :( Unmatched ) in regex; marked by <-- HERE in m/(\s|^|,|/|;|\|)Ow...

Is there a Perl implementation of Factor Graphs sum-product scheduling?

Are there good example codes of implementations of factor graph sum-product scheduling? I am new to the concept, and would like to see how it gets implemented. ...

How can I split a string by whitespace unless inside of a single quoted string?

I'm seeking a solution to splitting a string which contains text in the following format: "abcd efgh 'ijklm no pqrs' tuv" which will produce the following results: ['abcd', 'efgh', 'ijklm no pqrs', 'tuv'] In other words, it splits by whitespace unless inside of a single quoted string. I think it could be done with .NET regexps usi...