perl

How can I detect a blank line in Perl?

Hi guys. How to check a line ($_ value) is a blank line in perl? or other good method to check it instead of using $_ I want to code like this if ($_ eq '') # Check current line is a blank line (no any characters) { $x = 0; } Thank you. Updated some code with question solution below my test.txt for ...

How can I check if the next line is blank in Perl?

I just asked a question about how to check if the current line is blank or not in Perl. That works for the current line, but how do I check to see if the next line is blank? Text file to parse:(i need parse the text file and create a new XML file) constant fixup GemEstabCommDelay = <U2 20> vid = 6 name = "ESTABLISHCOMMUNICATIO...

How can I extract multiple email addresses from a single line using a Perl regex?

Hello, I have a text file which was originally a mysql dump of a database table. How do I write a Perl script to extract all the email addresses from this text file? The problem I am having is that I read in the lines of the document one by one then do a regular expression, however in cases where there are more than one email address o...

How can I guess the encoding of a string in Perl?

I have a Unicode string and dont know what its encoding is. When this string is read by a Perl program, is there a default encoding that Perl will use? If so, how can I find out what it is? I am trying to get rid of non-ASCII characters from the input. I found this on some forum that will do it my $line = encode('ascii', normalize('KD'...

How can I filter email addresses that belong in a particular domain using Perl?

How can I scan through a file which contains email addresses that are separated by a new line character and get rid of those that belong to a certain domain, e.g. [email protected]. I want to get rid of all email addresses that are @bad.com ...

How can I match an IP address in Perl?

I have a local DNS script that I've inherited from a past employee that needs to compare some values to see if they match specific MX records and IP addresses. The MX part I have down okay: 120 $doug = doug.local 139 if ($mx_record =~ /$doug/) { 140 print ("Mail on doug.\n"); 141 } 142 else { 143 print (...

How can I find the Firefox window from xwininfo?

Hello all, My Perl isn't very good at all and I am having trouble determining why this awesome perl script keeps returning: Error: No running window found Couldn't find window [Mozilla] in [xwininfo -tree -root] I have setup these variables: my $PROGNAME = $0; $PROGNAME =~ s|.*/||; my $GRAB = 'xwd -silent -nobdrs -id %id | co...

Can I rate a song in iTunes (on a Mac) using Perl?

I've tried searching CPAN. I found Mac::iTunes, but not a way to assign a rating to a particular track. ...

How do I process lines with CRLF, NEL line terminators?

I need to process a file with shift_jis encoding. However the line terminators are in a format that im not familar with. > file record.CSV record.CSV: Non-ISO extended-ASCII text, with CRLF, NEL line terminators Im using the general: open my $CSV_FILE, "<:encoding(shift_jis)", $filename or die "Could not open: $CSV_FILE : $!"; whil...

How can I implement QT (quality threshold) clustering in Perl?

I am having trouble with a QT clustering implementation that I want to implement in Perl. The line beginning with "identify set", the third from the end, is the part I can't figure out. The full paper is available here. ...

How can I create RRD files in Perl?

I have a separate application printing logs in every 10 seconds. I need to create RRD files from the log files. I need some Perl code to read the log files and create the RRD only without the graphs. I have also gone through the available Perl module in CPAN, i.e. RRD::Simple and RRD::Simple::Examples, but I still need help. ...

How can I make an object in my parent class but bless it into my child class in Perl?

I have two classes: a base class, Foo::Base and a derived class, Foo::Base::Sub. I want to have Foo::Base::Sub do some type and data checking on the constructor`s argument--a hash--before blessing it. I've tried overriding Foo::Base->new's constructor, doing the checks and then calling Foo::Base->new (since the code would be exactly th...

Should I disable the buffer to launch a background process in a CGI program?

In my Perl/CGI web application, I sometimes need to run a long process which makes the wait for the next page interminable. So I've been disabling the buffer as below so that the page contents get sent before the long process runs. local $| = 1; print "Content-type: text/html\n\n"; print $output; &background_process(); However it see...

Do SQL::Statement's REGEX and TRIM work with DBD::CSV?

Hello! The functions "REGEX()" and "TRIM()" in this script don't work as I would expect. The REGEX-function returns always true and the TRIM-function returns the "trim_char", not the trimmed string. (When I write the TRIM-function with FROM instead the "," I get an error message.) #!/usr/bin/perl use warnings; use strict; use 5.010; us...

How do I call a perl process that is already running from another script?

Problem: scriptA.cgi is sitting in an infinite loop and handling an open socket to a Flash client. scriptB.cgi is called from the web, does what it needs to do and then needs to inform scriptA to send a message to the client. Is this possible? I'm stuck on how to have scriptB identify the instance of scriptA that is sitting there with t...

How can I reset the vertical scroll position in Perl using Win32::GUI?

I'm outputting something to the textfield I created using Win32::GUI, like this: $Object->AddTextfield( -name => "Birthchart", -left => 75, -top => 90, -width => 250, -height => 250, -vscroll =>1, -multiline => 1, -prompt => "Birthchart", ); {#do ...

Why would waitpid in Perl return wrong exit code?

I get wrong exit code from waitpid and I can't figure out why. Could someone give me some ideas? Here what I do: I start my child process with open2 then I wait for it to finish with waitpid get exit code using $? It always returns with -1 no mater what I return from child process. I check with VS debugger that my program returns an...

How can I test if the DBI driver state is within a transaction?

I've got a couple of methods that should be executed only in the case my DBI driver class is currently into a transaction to ensure data integrity. I'm looking to write something like this: sub m{ my ($self , $dbh ) = @_ ; unless( $dbh->isInTransaction()){ die "Use this only within a transaction\n" ; } etc ... } From the ...

How do I create an instance of value from the attribute's meta object with Moose?

I'm working on a serialization tool using Moose to read and write a file that conforms to a nonstandard format. Right now, I determine how to load the next item based on the default values for the objects in the class, but that has its own drawbacks. Instead, I'd like to be able to use information in the attribute meta-class to generat...

How can I extract HTML img tags wrapped in anchors in Perl?

I am working on parsing HTML obtain all the hrefs that match a particular url (let's call it "target url") and then get the anchor text. I have tried LinkExtractor, TokenParser, Mechanize, TreeBuilder modules. For below HTML: <a href="target_url"> <img src=somepath/nw.gf alt="Open this result in new window"> </a> all of them give ...