perl

What's that best way to move through directories?

Are both of the examples below OK, or is the second one bad style? Case 1: Stay in top directory and use catdir to access subdirectories #!/usr/bin/env perl use warnings; use strict; my $dir = 'my_dir_with_subdir'; my ( $count, $dh ); use File::Spec::Functions; $count = 0; opendir $dh, $dir or die $!; while ( defined( my $file = re...

While and foreach mixed loop issue.

Hi my test.pl as below #!C:\Perl\bin\perl.exe use strict; use warnings; my $numArgs = $#ARGV + 1; print "thanks, you gave me $numArgs command-line arguments.\n"; while (my $line = <DATA> ) { foreach my $argnum (0 .. $#ARGV) { if ($line =~ /$ARGV[$argnum]/) { print $line; } } ...

Select returning 0 on a closed SCTP socket

This is related to the question: SCTP with Multihoming as a Drop In Replacement for TCP I have a simple echo client / concurrent server app that ran perfectly fine using TCP. I could pipe a file to stdin on the client and the client would receive all the data back, call select which would return 1 indicating the socket was readable, t...

How do I use SQL to "Show tables" in a MS Access database?

I based my code on the answer to the question Access get all tables, but am getting the following error: DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'MSysObjects'. (SQL-42000) at direct.pl line 22. [Microsoft][ODBC Microsoft Access Driver] Reco...

Why is Params::Validate callback failing for anonymous function reference?

I am using Params::Validate for validation, but at the callbacks section instead of defining the direct anonymous function, if I try giving the reference to that anonymous function it is directly jumping to the error logging area without printing the message inside the block (in case of passing correct value). use Params::Validate qw(...

Where can I learn advanced (Perl) Gtk2 design?

I've been working with Perl for years and recently started learning how to do GUI via Gtk2. All examples and tutorials I've found illustrate simple one-window type applications. Anything with a second window is limited to a simple text entry or yes/no type dialogue. I want to learn how to build something with that next-step more compl...

Are Rose::DB::Object::Cached memory cached through different processes?

Are RDBOC objects cached through different processes? I'm thining of running it in mod-perl, and it would factor into things, even though it would mostly be used on things that don't change (much). Also, do relationships referencing RDBOCs use the cache when it should intuitively? ...

Ajax prints output from perl script - Problems with IE7

Here is my javascript code: var xmlhttp; var result; function load() { xmlhttp=null; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=state_Change; xml...

Automating Inline::Java Installation on Linux (Centos/Redhat)

I'm maintaining a perl script which runs an automated install of our base server software. One of the new requirements is to install the Inline::Java module. Our usual strategy of installing using Yum seems to fall down as there's no Inline::Java available in yum. I can't find an RPM release for it so can't install as an RPM. The only...

How can I update cookies after having it set on the header in a Perl CGI program?

I have cookies set when the user log in to the application. Yet I need to modify that when the user updates his profile. Can anyone tell me how to update an existing cookies? Thanks in advance.(I'm using perl). ...

How do I copy an array using a reference in Perl?

If I do the following, it works fine: print $ref->{element}->[0]->{data}; I would like to see how many references are in the array so that I can loop through them, but I am having a hard time doing that. Here is the code I have tried, but it doesn't work: my @array = @$ref->{element}; foreach(@array) { print $_->{data}; } I ...

What kind of localization does occur in a "foreach" loop ?

UPD: I updated the question with more details. In this example: my $x = 1; for $x (2..3) { } print $x; # 1 $x is localized to the loop. man perlsyn says that "... If the variable was previously declared with "my", it uses that variable instead of the global one, but it's still localized to the loop." But the variables are not th...

running BLAST (bl2seq) without creating sequence files

I have a script that performs BLAST queries (bl2seq) The script works like this: Get sequence a, sequence b write sequence a to filea write sequence b to fileb run command 'bl2seq -i filea -j fileb -n blastn' get output from STDOUT, parse repeat 20 million times The program bl2seq does not support piping. Is there ...

perl script to connect to mysql server port 3307

Hi, I am trying to connect to a mysql server which is running at port 3307. How do I connect to the server? I do not see any other way to specify port. I am using like this: #!/usr/bin/perl use Mysql; $host = "localhost"; $database = "abc"; $tablename = "def"; $user = "uuu"; $pw = "ppp"; $connect = Mysql->connect($host, $database, $...

How can I download over FTP all the XML files in a directory?

I'm wondering how I would download all _*.xml_ files from a folder I have set up on an FTP server using Net::FTP. I have seen that glob() would be the best way, but I cannot quite wrap my head around the logic. Basically, I need to check if there are XML files in the folder. If not, wait 5 seconds, and check again. Once the files show u...

With Perl, how do I read records from a file with two possible record separators?

Here is what I am trying to do: I want to read a text file into an array of strings. I want the string to terminate when the file reads in a certain character (mainly ; or |). For example, the following text Would you; please hand me| my coat? would be put away like this: $string[0] = 'Would you;'; $string[1] = ' please hand me...

Is there a way to compare two variables in Template Toolkit?

[% IF OrgType.id == Organization.org_type_id %]selected="selected"[% END %] Does not work even when they both evaluate to the same number. [% IF OrgType.id == 3 %]selected="selected"[% END %] (i.e. hard-coding in a number for testing purposes) does work. [% OrgType.id %] and [% Organization.org_type_id %] both print "3" on t...

Can we get the following flexibility in Python as In Perl

Sorry. I am not trying to start any flame. My scripting experience is from Perl, and I am pretty new in Python. I just want to check whether I can have the same degree of flexibility as in Python. In Python : page = form.getvalue("page") str = 'This is string : ' + str(int(page) + 1) In Perl : $str = 'This is string : ' . ($page + ...

Why does my Perl program warn about an uninitialized value?

I've written a Perl script, below which generates a warning and I can't work out why. #!/usr/local/bin/perl -w $status = $ENV{ 'STATUS' }; if ( $status eq "" ) { $status = 0; } else { $status = 1; } It says "Use of uninitialized value in string eq at ./x.pl line 4." Line 4 is the "if ( $status eq "" )" line but the variable...

How can I use vendor-packaged modules from a Perl I compiled myself?

Hello! My OS-Distribution provides the rpm-package "perl-obexftp", which installs the Modul "OBEXFTP". These are the files: /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi/OBEXFTP.pm /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi/auto/OBEXFTP /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi/au...