Does Perl's IO::Select in Windows work with filehandles?

Does IO::Select in Windows work with filehandles? $pid = open $handle, "-|", "$_command" || die "Cannot run $_command"; my $s = IO::Select->new(); $s->add($handle); $s->add(\*STDIN); while (1) { @ready = $s->can_read(30); if (scalar(@ready) > 0) { } else { } } My script continuously prints something to the screen, with open, the command gets started in the background but can_read always fails on Windows. Any help?

Perl How can I "use lib" the appropriate directory depending on installation location?

I have an object-oriented web-app that is installed in multiple locations on my server. Once for "live", once for "beta", etc. Being object-oriented, it consists of many perl modules. In the main module, I must "use lib" the appropriate directory for all of the custom perl modules for that instance of the app. This is no big deal, I have a BEGIN block that checks the location of the main program and sets the library directory appropriately. However I also have a lot of utility, command line

Which Perl modules can be installed just by copying lib files?

I'm an absolute beginner at Perl, and am trying to use some non-core modules on my shared Linux web host. I have no command line access, only FTP. Host admins will consider installing modules on request, but the ones I want to use are updated frequently (DateTime::TimeZone for example), and I'd prefer to have control over exactly which version I'm using. By experimentation, I've found some modules can be installed by copying files from the module's lib directory to a directory on the host, and

How can I read and parse chunks of data into a Perl hash of arrays?

I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study: Glossina morsitans transcript sequencing project(SRP000741) Sample: Glossina morsitans(SRS002835) Instrument: Illumina Genome Analyzer Total: 1 run, 8.3M spots, 299.9M bases Run #1: SRR016086, 8330172 spots, 299886192 bases 2:SRX004540 Submitter: UT-MGS Study: Anopheles stephensi transcript sequencing project(SRP000747) Sample: Anopheles stephensi(SRS002864) Instrument: Solexa 1G Genome Analyzer Total:

Using perl's Regexp::Grammars, how do I make a capture dependent on $MATCH?

I've got a token like such: <delim2=((?{ $MATCH{delim} }))> and what I want to happen is for delim2 to capture and be set to the value of delim. When I run this, delim2 is set, but the capture is never done. I think this is an error in my reasoning: I'm trying to chain this form: <ALIAS= ( PATTERN )> Match pattern, save match in $MATCH{ALIAS} and this form: (?{ MATCH{delim} }) into something like this <ALIAS= ( (?{MATCH{delim}) )> Matches the value of $MATCH{deli

Perl escape HTML by default in Template Toolkit

Can I somehow configure Template Toolkit so that: [% foo %] does what you would now need to say: [% foo | html %] that is, escape HTML in foo? And do something else, like: [% foo | noHtml %] if I don't want to escape?

how to embed perl script in c program?

Actually I've got an idea but to do that I need your help.Tell me is there any way to create a library in perl script ? I mean what is the command to create a library in perl ?and how can i include that library in my c program and run it ? I read somewhere that you can embedd your perl script in your c program but how can I make it?I want to create a special library on strings using perl script and use it in my c program.Help me guys.Thank you.

push an array of references to any number of hashes [ perl ]

suppose i have an array: @array = { 'A' => "", 'B' => 0, 'C' => 0, 'D' => 0, }; i can add an element by: $count = 0; $array[$count]->{A} = "abcd"; $array[$count]->{B} = 789; $array[$count]->{C} = 456; $array[$count]->{D} = 123; and another element, $count++; $array[$count]->{A} = "efgh"; $array[$count]->{B} = 111; $array[$count]->{C} = 222; $array[$count]->{D} = 333; how can i add elements to @array using push?

Perl system call mplayer, transition between videos varies

I'm only few weeks into perl, and I am trying to run the codes below: sub runVideo { system('mplayer -fs video1.mpeg2 video2.mpeg2'); return; } runVideo(); system('some other processes in background&'); runVideo(); Basically I run video1 and video2 for two times, first time which is just the videos, second time with some application running at the background, doesn't matter what apps are running, since I'm running the videos in fullscreen mode. Problem: On the first run, the tr

How can I use Perl's File::Find inside a Moose Object?

I'm building a Perl application that relies on Moose. One task the Moose object needs to accomplish is to use File::Find to populate an attribute with a list of files. I'm having some trouble figuring out how to use find's \&wanted code reference in a way that will let me maintain access to a $self version of the Moose object. So far, I have this: #!/usr/bin/perl package MyMoose; use Modern::Perl; use Moose; use File::Find; use FindBin qw($Bin); ### Attribute to hold the file list has "

perl code blocks

I have a question regarding code blocks in perl. Given the following code: my @newArr = sort { $a <=> $b } @oldArr; uses a code block as an argument. I could rewrite it as: sub sortFunc { return $a <=> $b; } my @newArr = sort sortFunc @oldArr; I am trying to figure out how this mechanism works. Currently I need to implement a sort of complex sort function that would look messy in a code block, However it depends on some local variables. For example:

How to select siblings (xpath syntax) with Perl's XML::Twig?

I need to select the next node via next_sibling or first_elt. But I want to filter by node name (containing the string "TON") first_elt ('HILTON[@method]' or 'SHERATON[@method]'); or next_sibling ('HILTON[@method]' or 'SHERATON[@method]'); or next_sibling ('TON[@method]'); Example I tried (not working): #!/usr/bin/perl -w use warnings; use XML::Twig; $t-> parsefile ('file.xml'); my $Y0=$t->first_elt('HILTON[@method]' or 'SHERATON[@method]'); it will just process for 'HILTON[@

Preparing a Perl file to run with Ubuntu and tabix

I don't know about Ubunto or Perl but still need to install and run a program on it. This is what I am looking at: On the installation section it says this: To build the vcftools executable, type "make" in the vcftools folder. The Perl scripts require that VCF files are compressed by bgzip and indexed by tabix (both tools are part of the tabix package, available for download here). Both tools must be in directories that are listed in the

how to get the data from tag in perl

I want to extract the data from SUB tag line by line and store the data in hash.. I did this but im not getting the result ==file== <SUB> name1="abc" value1="24" value2="24" </SUB> <SUB> name="abc2" </SUB> <SUB> name3="ag" value3="27" </SUB> <SUB> name4="ljh" value4="90" </SUB> ===code=== use strict; use warnings; open my $fh, '<', 'data_file.txt' or die $!; while (<$fh>) { while(m{<SUB>(.*?)<\/SUB>}g

Declare and populate a hash table in one step in Perl

Currently when I want to build a look-up table I use: my $has_field = {}; map { $has_field->{$_} = 1 } @fields; Is there a way I can do inline initialization in a single step? (i.e. populate it at the same time I'm declaring it?)

Perl How can I print the elements of an array repeated twice each side-by-side?

Please, I have the following line of code to write the header of a file, but I'd like to print each element of the array @order twice side-by-side. For example: $1 $1 $2 $2 $3 $3... in a way that I would have each pair of columns of my output file with the same name. print(join("\t", "Case_ID", "State", "Ind", "DoB", @order) . "\n"); Can I do something simple or I have to loop over the array to repeat the elements before I print? Thanks!

Installing perl dependency automatically in perl

I'm very new to perl. I wish I could install some package from perl, I did so like this : perl -MCPAN -e 'install VM::EC2' Its getting failed due to dependency I guess, it shows : Result: FAIL Failed 8/8 test programs. 9/9 subtests failed. LDS/VM-EC2-1.20.tar.gz one dependency not OK (XML::Simple); additionally test harness failed ./Build test -- NOT OK //hint// to see the cpan-testers results for installing this module, try: reports LDS/VM-EC2-1.20.tar.gz Running Build install make

Compare time with Perl

I want to check if current time is small , equal or great of 20:00 ( for example). How i can do it with Perl? Thanks.

Printing reverse complement of DNA in single-line Perl

I want to write a quick single-line perl script to produce the reverse complement of a sequence of DNA. The following isn't working for me, however: $ cat sample.dna.sequence.txt | perl -ne '{while (<>) {$seq = $_; $seq =~ tr /atcgATCG/tagcTAGC/; $revComp = reverse($seq); print $revComp;}}' Any suggestions? I'm aware that tr -d "\n " < input.txt | tr "[ATGCatgcNn]" "[TACGtacgNn]" | rev works in bash, but I want to do it with perl for the practice.

Perl file processing on SHIFT_JIS encoded Japanese files

I have a set of SHIFT_JIS (Japanese) encoded csv file from Windows, which I am trying to process on a Linux server running Perl v5.10.1 using regular expressions to make string replacements. Here is my requirement: I want the Perl script’s regular expressions being human readable (at least to a Japanese person) Ie. like this: s/北/0/g; Instead of it littered with some hex codes s/\x{4eba}/0/g; Right now, I am editing the Perl script in Notepad++ on Windows, and pasting in the string I need to

Way to Get 3 types of input of similar kind in Perl

I am a novice in Perl, so I would like some help. I am writing a program, where the user can give me up to 3 different types of input and I need to extract specific data. The user can give me any one of the three: ASP_72_2 D72_2 72_2 (ASP = residue name, D = residue code for ASP, 72 = residue number, 2 = transmembrane number) Is there a clever way to store the data in one line? My idea (pseudo code) would be to check substring of each input like the following. if ((substr($input, 0,3)) eq 'A

perl Text::CSV_XS removes all escape_chars

I had moved from Text::CSV to the XS version because of a problem of newline inside data Text::CSV parsing when data contains newline Text::CSV_XS removes all the escape chars in the data ( I am using linux with perl 5.8.8 ) This is the sample code (below) I expect that the attribute on the 3 row should be \N after escaping 1 \ but Text::CSV_XS removes both the \ use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new({ binary => 1, eol => "\n", quote_c

Perl Win32:OLE unable to return a list of string

I created a Win32:OLE object in perl: $myObject = Win32::OLE->new("myObject"); One of the APIs in my object returns a list of another object: public Ilist<obj2> GetMyList() It also displays the object content on cmd window and log them on disk as a txt file using the list. All the display and logging were carried out well in perl code using: my $myObjList = $myObject->GetMyList(); but $myObjList returns undef. I tried to return a list of string and the perl variable that sh

Reading line by line in perl

Suppose I have a text file with the following format @ATDGGSGDTSG NTCCCCC + @nddhdhnadn @ATDGGSGDTSG NTCCCCC + nddhdhnadn Now its a repeating pattern of "4" lines and I every time want to print only the 2nd line i.e. the line after the line starting with "@" i.e 2nd line..6th line..etc. How can I do it?

Perl LIne-by-line file-io not working as expected in Windows

I'm using Perl 5.16.1 from Strawberry in a Windows environment. I have a Perl script reading very large text files. The smallest text file is 30M. When reading files that do not have a line feed at the end of the very last line I get very peculiar results. It may not happen all the time but when it does It's as though it is reading cached data from the I/O system for another file that I previously opened with the Perl script. If I manually edit the file and add a line feed it's fine. I added a l

command line arguments in perl with keywords

I am new to Perl and currently I am passing the command line arguments to a perl script and retrieving it via ARGS[0]. perl <> windows IE. I would like to give keywords to the values mentioned above. perl <> -os windows -browser IE -instance 2. There might be times where instance might or might not be present. How do I go about handling this in my perl script.

How to use in perl script?

I've followed following link for the issues i faced. Really I don't know how to use. Please guide me in proper way. Issue : Can't locate XML/ in @INC (@INC contains: /perl/site/lib C:/Dwimpe rl/perl/site/lib C:/Dwimperl/perl/vendor/lib C:/Dwimperl/perl/lib .) at C:/Dwimp erl/perl/site/lib/ line 103. BEGIN failed--compilation aborted at C:/Dwimperl/perl/site/lib/ line 103 . Compilation failed

Installing perl DBD:Pg on Mac

I run: perl -MCPAN -e 'install Bundle::DBD::Pg' it asks: Path to pg_config? I say: /Library/PostgreSQL/9.3/bin/pg_config it runs... and the last lines are: Test Summary Report ------------------- t/02attribs.t (Wstat: 256 Tests: 249 Failed: 1) Failed test: 23 Non-zero exit status: 1 Files=15, Tests=1691, 29 wallclock secs ( 0.23 usr 0.05 sys + 5.29 cusr 1.65 csys = 7.22 CPU) Result: FAIL Failed 1/15 test programs. 1/1691 subtests failed. make: *** [test_dynamic] Error 255

How can I tell if a Perl module is actually used in my program?

I have been on a "cleaning spree" lately at work, doing a lot of touch-up stuff that should have been done awhile ago. One thing I have been doing is deleted modules that were imported into files and never used, or they were used at one point but not anymore. To do this I have just been deleting an import and running the program's test file. Which gets really, really tedious. Is there any programmatic way of doing this? Short of me writing a program myself to do it.

Sending output to STDOUT in perl while executing a command

I am writing a perl code to upload code from a repro to a directory(jsvn update . a shell comand in my case) . I wanted that while the check in is going on, the result should display in stdout ('jsvn update .' does show that but i have to keep on looking at the monitor in case of any error and incase of error i have to give a clean up and start the process again.) I wrote a program for that, but it doesnot displays output to screen. The cursor keeps blinking and i know the process is going on ba

Using hash values as categories in Perl

I'm reading two tab separated files into two hashes, files looks like this: apple fruit pear fruit carrot vegetable potato vegetable peach fruit and apple 23 pear 34 carrot 12 potato 45 peach 12 I want to pick up only vegetable and get their numbers. Is there any smarter way than through the for cycle to do this? And if I want to create two new hashes %fruits and %vegetable, do I really have to do it like: foreach (keys %kinds_hash) { if ($kinds_hash{$_} =~ "vegetable") { $vege

Perl Check if key exists in hash using value from another hash as hash name

I'm getting a variable $breed back in a callback and I'm checking if I've seen it before, and if I haven't, storing it in %hash by doing the following: if (exists $hash{$breed}) { #exists } else { #add it $hash{$breed}; } Now, since I would like to keep track of these unique $breeds in separate hashes, I made another hash to keep new hash names %hashnames =(cats => 'cathash', dogs => 'doghash'); my %cathash = (); my %doghash = (); Since I'm getting

Bundling up a perl script with its dependencies?

I have a perl script that I've put together to do some monitoring and graphing. It works nicely on my dev system, where I have carte-blanch to install my own modules from CPAN. What I'm looking at doing is bundling it up to deploy onto another system. But here's the catch - this other system is 'standalone' and has no network connection. (And I have change control paperwork to fill in, indicating what I'm installing). As a result, I'd really like a nice easy way to figure out: - What module

Perl Mounting PSGI app by regex - different paths -> one app

Looking for a way, how to run the same PSGI $app for multiple requests what aren't defined by the mount prefix. How to mount in such screnario? E.g. let say i have in my app.psgi use Plack::Builder; my $defaultapp = sub { ... }; my $someapp = sub { ... }; my $otherapp = sub { ... }; builder { mount '/some' => $someapp; # ok #and here need something like: mount "_regex_here" => $otherapp; #??? mount '/' => $defaultapp; #OK - last mount is the "default" } E.g.

Perl How to copy zipped file data to one txt file

Now i need to copy data inside the zip files to one .txt file i.e all R1 folder file data should copy and save in one R1.txt file similarly R2 folder file data should save in one single R2.txt file. is it possible to copy data from zipped files?? #!/usr/bin/perl use File::Copy; use strict; use warnings; print"Enter Folder name \n"; print"File name: "; chomp(my $Filename=<>); mkdir "R1"; mkdir "R2"; opendir(DIR,"$Filename") or die "cannot open directory"; foreach my $name (readdir(DI

Perl AnyEvent::RabbitMQ issues with closed channels

I'm writing a master program for publishing message into a message queue (RabbitMQ). The program is written in Perl 5 and is using AnyEvent::RabbitMQ for the communication to RabbitMQ. The following minimal example (for the issue I ran into) will fail on a second command send via the same channel with the error "Channel closed". use strictures 2; use AnyEvent::RabbitMQ; main(); ############################################################################ sub main { _log( debug => 'main'

Perl Cumulative Density Function of a normal distribution calculation without installing a Math module

I would like to calculate the Cumulative Density Function of a normal distribution in Perl. I am using the Math::Gauss module from CPAN which calculates a CDF without any problem. #!/usr/bin/perl use strict; use warnings; use Math::Gauss ':all'; my $x = 0.1; my $mean = 0; my $std = 0.1; my $output = cdf($x, $mean, $std); print $output; However, I got a module installation problem when I ran the code in a different server as below: Can't locate Math/ in @INC (@INC cont

Trouble passing an IO::File handle to a Perl class

If I pass it as an argument I get the error: 'Can't locate object method "getline" via package "Bad" at line 27.' But if I insert it in the module it works. This is the boiled down code. uses the module Set $CAUSE_ERROR to see the problem. #!/usr/bin/env perl # This is use strict; use warnings; use IO::File; use Bad; # use the bad module "" &Main(); sub Main { my $filename = ""; warn "About to parse '$filename'\n"; my $MyWord = Ba

Perl Passing Parameteres to Interactive script programatically

We have an interactive script(Script 1) which asks for an IP Address and continues it's execution process. Script 1 is called from script2. As we know the IP address we want to pass IP Automatically to script so that manual intervention is not required I looked into Expect Module. But i cannot install that module in PRODUCTION server. Can someone suggest a way to overcome this issue.

Perl DBI connect('database=;host=;','',...) failed

I have an Open-source Ticket Request System (OTRS) docker container that works perfectly when I define Database, DatabaseHost, DatabasePw, and DatabaseUser in the file # The database host $Self->{DatabaseHost} = mysqldb; # The database name $Self->{Database} = otrs; # The database user $Self->{DatabaseUser} = otrs; # The password of database user. You also can use bin/ Maint::Database::PasswordCrypt # for crypted passwords $

Perl DBIx::Class error "Can't find source for XXX"

When I try to dump database with Fixtures: dbic-migration --schema_class App::Schema --database PostgreSQL -Ilib dump_all_sets I got error: DBIx::Class::Schema::source(): Can't find source for Schet at /home/xxx/lib/perl5/x86_64-linux/Moose/Meta/Method/ line 110 In main application I have no problem to write: $schema->resultset('Schet') How to fix this error and dump data into fixtures?

Perl Ternary Operator with Undef

I am having issues with getting a ternary operator to work using undef. My original code that works: my $qr = [ {IP=>'x.x.x.51',Testnet=>'bos-portal-legacy',Owner=>'Amund', Email => 'bosemail'}, {IP=>'x.x.x.52',Testnet=>'bos-portal-2',Owner=>'Amund', Email => 'boemail2'}, {IP=>'x.x.x.53',Testnet=>'bos-portal-legacy',Owner=>'Amund', Email => 'bosemail'}, {IP=>'x.x.x.54',Testnet=>'sqa',Owner=>'Richard', Email => 'sqaemail'}, {IP

Need help on Checking the Signature of the Request from Amazon Alexa using Perl

I am currently building a web service that should handle Alexa voice intents. The HTTP request I get from Alexa must be verified by checking a signature, as described in the documentation. I am writing this code in Perl. Amazon provides me with a SignatureCertChainUrl (which contains the certificate) and a signature, such as the following: signature: KUm7g9saS4la2pwCPJHuk0ZOtNAPKnqE8qprp58rz1x9Em1DDp2mNdL56iiC7weGw3hzaN6lCmqjWL3zxtAC7HXmbDPdpYE5ZQJzVDCorAvAgb0VQTVMiRi2xcoNm+6KcQZe2/aFJgAxaDaJ

Perl printing set from another set

I have this script which pretty much just prints a data set from vertical to horizontal. I was it to skip over some names where are not part of the set that I want. Howerver I want to print out just select Initials, while retaining the orders. #!/usr/bin/perl use strict; use warnings; use Data::Dumper ; my $filename = shift @ARGV ; open(my $fh, '<', $filename) or die "Could not open file $filename $!"; while (<$fh>) { next if /^$/; chomp $_ ; print $_ ; }

Timeout the perl command

I am working on a old Solaris node which does not have coreutils(timeout) tool installed. I am trying to print output of three bash commands separated by "-" x 80 chars. One of the command is having bad rep of taking very long time and I need to timeout that command and print the remaining output. I am trying to use alarm shift but this does not help. I need to keep the command as a one liner as I need to use this command in ansible's shell module. Can someone please help. If I run the

Access xenapi over https with a self-signed cert with perl

I am trying to access xenapi with the following perl script. The "http" version seem to work, but the "https" version doesn't. The code: #!/usr/bin/perl use 5.20.0; use RPC::XML::Client; use Data::Dumper; use IO::Socket::SSL qw( SSL_VERIFY_NONE ); $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; $ENV{HTTPS_DEBUG} = 1; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; use Xen::API; my $user='Gordon'; my $passwd='Freeman'; my $xen = RPC::XML::Client->new("https://xen1.

  1    2   3   4   5   6  ... 下一页 最后一页 共 179 页