perl

How do you store a result to a variable and check the result in a conditional?

I know it's possible but I'm drawing a blank on the syntax. How do you do something similar to the following as a conditional. 5.8, so no switch option: while ( calculate_result() != 1 ) { my $result = calculate_result(); print "Result is $result\n"; } And just something similar to: while ( my $result = calculate_result() != ...

How do I use connect to DB2 with DBI and mod_perl?

I'm having issues with getting DBI's IBM DB2 driver to work with mod_perl. My test script is: #!/usr/bin/perl use strict; use CGI; use Data::Dumper; use DBI; { my $q; my $dsn; my $username; my $password; my $sth; my $dbc; my $row; $q = CGI->new; print $q->header; print $q->start_html(); $d...

Why can't Perl's WWW::Mechanize find the form by field names?

#!/usr/bin/perl use WWW::Mechanize; use Compress::Zlib; my $mech = WWW::Mechanize->new(); my $username = ""; #fill in username here my $keyword = ""; #fill in password here my $mobile = $ARGV[0]; my $text = $ARGV[1]; $deb = 1; print length($text)."\n" if($deb); $text = $text."\n\n\n\n\n" if(length($text) < 135); $mech->get("http...

How do I use Spreadsheet::WriteExcel to create a chart from numeric log data?

I used csv2xls.pl to convert a text log into .xls format, and then I create a chart as in the following: my $chart3 = $workbook->add_chart( type => 'line' , embedded => 1); # Configure the series. $chart3->add_series( categories => '=Sheet1!$B$2:$B$64', values => '=Sheet1!$C$2:$C$64', name => 'Test data series 1',...

User input in perl - Issue with running script in KomodoEdit

i wrote this tiny code on gedit and ran it :- #/usr/bin/perl print "Enter the radius of circle: \n"; $radius = <>; chomp $radius; print "radius is: $radius\n"; $circumference = (2*3.141592654) * $radius; print "Circumference of circle with radius : $radius = $circumference\n"; Runs fine using command line.Ran the same code on Komodo ...

Does XML::LibXML::Reader read HTML?

I didn't find anything about parsing HTML in the XML::LibXML::Reader documentation. And I tried to parse a HTML-site and it didn't work. Is my conclusion, that XML::LibXML::Reader doesn't work with HTML right? ...

How do I include a frameset under CGI.pm?

I want to have a cgi-script that does two things. Take the input from a form. Generate results base on the input values on a frame. I also want the frame to exist only after the result is generated/printed. Below is the simplified code of what I want to do. But somehow it doesn't work. What's the right way to do it? #!/usr/loca...

Why does perl crash with "*** glibc detected *** perl: munmap_chunk(): invalid pointer"?

#!/usr/bin/env perl use warnings; use strict; use 5.012; use XML::LibXML::Reader; my $reader = XML::LibXML::Reader->new( location => 'http://www.heise.de/' ) or die $!; while ( $reader->read ) { say $reader->name; } At the end of the output from this script I get this error-messages: * glibc detected * perl: munmap_chunk(): ...

How can I get UTC equivalents of Today_and_Now() and Today() in Perl?

How can I get UTC equivalents of Today_and_Now() and Today() call results? Can I convert them back to local time? ...

How can I take a screenshot of website with Perl?

Possible Duplicate: How can I take screenshots with Perl? How can I take a screenshot from a site (in batch mode) using Perl? I.e. solution should produce image file (say .png) given an URL. It would be nice, if no X Window system will be required for solution to work. ...

How is this Perl code selecting two different elements from an array?

I have inherited some code from a guy whose favorite past time was to shorten every line to its absolute minimum (and sometimes only to make it look cool). His code is hard to understand but I managed to understand (and rewrite) most of it. Now I have stumbled on a piece of code which, no matter how hard I try, I cannot understand. my ...

How do I get a slice from an array reference?

Let us say that we have following array: my @arr=('Jan','Feb','Mar','Apr'); my @arr2=@arr[0..2]; How can we do the same thing if we have array reference like below: my $arr_ref=['Jan','Feb','Mar','Apr']; my $arr_ref2; # How can we do something similar to @arr[0..2]; using $arr_ref ? ...

How can I extract a string between matching braces in Perl?

My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points {}}}} {ABC|*|XYZ:mno:pqr {GHI 0 34 0} {{Points {}}}} { ABC|*|XYZ:abc:pqr {GHI 0 68 0} ...

How to replace unicode characters by ascii characters in Python (perl script given)?

I am trying to learn python and couldn't figure out how to translate the following perl script to python: #!/usr/bin/perl -w use open qw(:std :utf8); while(<>) { s/\x{00E4}/ae/; s/\x{00F6}/oe/; s/\x{00FC}/ue/; print; } The script just changes unicode umlauts to alternative ascii output. (So the complete ...

Injecting relationships in DBIx::Class

I have a handful of DBIx::Class::Core objects that model various database tables. For some of those models (those that have a 'queue' column), I have another class inject subs (basically, to 'move' the model object along it's queue states). I'd like to also have that class inject has_many relationships ala class($name)->has_many('queu...

How can I quickly sum all numbers in a file?

I have a file which contains several thousand numbers, each on it's own line: 34 42 11 6 2 99 ... I'm looking to write a script which will print the sum of all numbers in the file. I've got a solution, but it's not very efficient. (It takes several minutes to run.) I'm looking for a more efficient solution. Any suggestions? ...

How did Perl gain a reputation for being a write-only language?

How did Perl gain a reputation (deserved, undeserved, or used to be deserved, no longer so) of being a "write only language"? Was it The syntax of the language Specific features that were available in the language Specific features not being available in the language (or at least old versions of it) The kind of tasks Perl was being us...

What is a good Perl CGI tutorial?

I am going to learn Perl CGI. Please suggest a good URL or book for a CGI tutorial. ...

How can I use Perl to scrape a website that reveals its content with JavaScript?

I need to write a Perl script to scrape a website. The website can only be scraped with JavaScript, and the user is on Windows. I got some way with Win32::IE::Mechanize on my work machine, which has IE6, but then I moved to my netbook which has IE8, and can't even get as far as fetching a simple page. Is Win32::IE::Mechanize up to d...

Is it possible to write a shell script which is faster to the same script in Perl?

I wrote multiple scripts in Perl and shell and I have compared the real execution time. In all the cases, the Perl script was more than 10 times faster than the shell script. So I wondered if it possible to write a shell script which is faster to the same script in Perl? And why is Perl faster than shell although I use the system functi...