2018-10-22         Salome

Perl add value 1 to value 2 value 2 to value 3 etc to end of file

I have a Perl question which should be fairly easy but can’t quite seem to get it correct I have a file that contains 2 columns of numbers, what I need to is to take the second column and add the first value in this column to the second, the second to the third the third to the fourth etc. I don’t know how many numbers will be in column 2 so I need to do this until the end of the file, I also want to be able to use these values further on in my program. I will give a dummy example below along with the code I have tried so far.Example file tab delimited file data.txt 1 29...

 perl                     2 answers                     13 view
 2018-10-22         Virgil

Making Catalyst calls from the model?

I'm using Catalyst with Catalyst::Plugin::Authentication andCatalyst::Plugin::Authorization::Roles and am wondering if there is a betterapproach to adding an attribute to a model that I'm not seeing.Each user is permitted to access one or more companies, but there isalways one primary (current) company at a time. The permitted list isstored in the database, and database access is primarily through DBIC.My first inclination is to say that it's the user that has a currentcompany, and thus put it as part of the user model: give the userpackage a "sub company { … }" to get/set ...

 perl                     1 answers                     61 view
 2018-10-22         Nathaniel

How can I access Closure JavaScript minifier using Perl's LWP::UserAgent?

I'm trying to get Code Closure to work, but unfortunately, there's always an error thrown.Here's the code:use LWP::UserAgent;use HTTP::Request::Common;use HTTP::Response;my $name = 'test.js';my $agent = new LWP::UserAgent();$agent->agent("curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/ libidn/1.18");$res = $agent->request(POST 'http://closure-compiler.appspot.com/compile', content_type => 'multipart/form-data', content => [ output_info => 'compiled_code', compila...

 perl                     2 answers                     16 view
 2018-10-22         Crystal

Is there a perl module that can start a process and return the three main I/O handles to that process?

In perl, I often need to run a child process, send some input to it, and then read its output. There are a number of modules to do this, but they all seem to require you to pass in pre-existing variables, which are then modified by the function to contain filehandles. Here is an example from the Synopsis of IPC::Open3:my ($wtr, $rdr, $err);use Symbol 'gensym'; $err = gensym;$pid = open3($wtr, $rdr, $err, 'some cmd and args', 'optarg', ...);This pattern gets kind of annoying when I have to do it over and over, especially because it involves a bunch of position...

 perl                     1 answers                     68 view
 2018-10-22         Susan

How can I process a binary file of fixed length records with no line breaks in between?

I have a text file that's composed of fixed length records but all in one line with no line breaks in between. What's the best way to process it in Perl? Thanks! First, let's open the file, and make sure it's in bin mode:open my $fh, '<', 'file.name' or die "Cannot open file.name: $!";binmode $fh;Now, set input record separator to reference to length of your records (let's assume 120 bytes per record):local $/ = \120;Now, let's read the records:while (my $record = <$fh>) {And now if you want to get data out of it, you have to write some unpack thing: my @eleme...

 perl                     3 answers                     22 view
 2018-10-22         Lennon

How can I format a timestamp in Perl?

I would like to get this timestamps formatting:01/13/2010 20:42:03 - -Where it's always 2 digits for the number except for the year, where it's 4 digits. And it's based on a 24-hour clock.How can I do this in Perl? I prefer native functions. POSIX provides strftime:$ perl -MPOSIX -we 'print POSIX::strftime("%m/%d/%Y %H:%M:%S\n", localtime)'01/27/2010 14:02:34You might be tempted to write something like:my ($sec, $min, $hr, $day, $mon, $year) = localtime;printf("%02d/%02d/%04d %02d:%02d:%02d\n", $day, $mon + 1, 1900 + $year, $hr, $min, $sec);as a means of avoiding ...

 perl                     3 answers                     58 view
 2018-10-22         Yale

How can I convert yyyy-mm-dd hh:mm:ss into UTC in Perl?

convert datetime format yyyy-mm-dd hh:mm:ss (Might be a string) into UTC,Looking into DateTime but I don't see how to parse the string?UPDATE:Is this working correctly?require 5.002;use strict;use warnings;use DateTime::Format::DateManip;my $string = '2010-02-28 00:00:00';my @dates = ( $string);for my $date ( @dates ) { my $dt = DateTime::Format::DateManip->parse_datetime( $date ); die "Cannot parse date $date, Please use a valid date in this format 'yyyy-mm-dd mm:hh:ss'" unless defined $dt; print $dt."\n"; $dt->set_time_zone( 'UTC' ); print $dt."Z\...

 perl                     3 answers                     63 view
 2018-10-22         Melissa

How come MooseX::Storage doesn't seem to follow attribute traits for some objects?

I have put together a little test case to demonstrate my problem:package P1;use Moose;use MooseX::Storage;with Storage;has 'blah' => ( is => 'rw',);package P2;use Moose;use MooseX::Storage;with Storage;has 'lol' => ( is => 'rw', traits => ['DoNotSerialize']);package P3;use Moose;extends 'P2';has 'magic' => ( is => 'rw',);package Test;my $obj = P3->new( magic => 'This ok!', lol => sub { 'weee' });my $stored = P1->new(blah => $obj);use Data::Dumper; print Dumper ($stored->pack);I would expect this to print the object,...

 perl                     2 answers                     102 view
 2018-10-22         Rose

Why doesn't my Perl CGI program work on Windows?

I have written following in index.pl which is the C:\xampp\htdocs\perl folder:#!/usr/bin/perlprint "<html>";print "<h2>PERL IT!</h2>";print "this is some text that should get displyed in browser";print "</html>";When I browse to http://localhost:88/perl/ the above HTML doesn't get displayed (I have tried in IE FF and chrome).What would be the reason?I have xampp and apache2.2 installed on this Windows XP system. Maybe it's because you didn't put your text between <body> tags. Also you have to specify the content type as text/html.Try this:p...

 perl                     3 answers                     38 view
 2018-10-22         Rita

How do I create a directory and parent directories in one Perl command?

In Perl, how can I create a subdirectory and, at the same time, create parent directories if they do not exist? Like UNIX's mkdir -p command? use File::Path qw(make_path);make_path("path/to/sub/directory");The deprecated mkpath and preferred make_path stemmed from a discussion in Perl 5 Porters thread that's archived here.In a nutshell, Perl 5.10 testing turned up awkwardness in the argument parsing of the makepath() interface. So it was replaced with a simpler version that took a hash as the final argument to set options for the function. [XXX]Use mkpath from the F...

 perl                     5 answers                     31 view
 2018-10-22         Jeffrey

How can I list all of the files in a directory with Perl?

This question already has an answer here: How do I read in the contents of a directory in Perl? 8 answers If you want to get content of given directory, and only it (i.e. no subdirectories), the best way is to use opendir/readdir/closedir:opendir my $dir, "/some/path" or die "Cannot open directory: $!";my @files = readdir $dir;closedir $dir;You can also use:my @files = glob( $dir . '/*' );But in my opinion it is not as good - mostly because glob is quite complex thing (can filter result...

 perl                     6 answers                     33 view
 2018-10-22         Jonas

Find file names with certain extensions

I want to search a directory for file names with any of the following extensions: .srt, .sub, .txt, .ass, .ssa.I would appreciate any input. The simplest way is to use glob:chdir $directory;my @files = glob '*.srt *.sub *.txt *.ass *.ssa';Another way is to use readdir, but then you have to filter the files yourself, e.g. by using grep:open my $dir_handle, $directory or die $!;my @files = grep /\.(?:srt|sub|txt|ass|ssa)\z/, readdir $dir_handle; [XXX]And if you need to search through an entire directory tree, use File::Find. [XXX]

 perl                     2 answers                     47 view
 2018-10-22         Donna

What's the best way to turn CPAN modules into Debian packages?

Whenever I work on a system of any flavor that has a particular way of handling package management, I try to stick with that standard for managing my Perl modules. "When in Rome, etc."For example, on a Win32 system using ActivePerl, I use PPM for everything and use the great PPM::Make. On a RedHat system I prefer to use RPMs.Now I am working on a Debian system, and find myself in need of a way to turn an arbitrary CPAN or CPAN style distribution into a deb. Google shows options like dh-make-perl, CPANPLUS::Dist::Deb and CPAN::Packager::Builder::Deb.Does anyone with exper...

 perl                     5 answers                     46 view
 2018-10-22         Karen

How do I install Image::Magick on Debian etch?

I've been trying to install Image::Magick on Debian etch for a while without great success.I've got graphicsmagick-libmagick-dev-compat installed, but can't find the .deb for Perl's Image::Magick. And cpan -i Image::Magick gives me all sorts of compilation errors.Does anyone know the good combination of software so I can finally write use Image::Magick? I've got the answer: The package to install is perlmagick.I hope it doesn't help just me :) [XXX]Have you tried libgraphics-magick-perl?EDIT:Are you sure you need the real deal?perlmagick contains its own version of Im...

 perl                     2 answers                     47 view
 2018-10-22         Julian

the first IP of the next block with Net::IP

i am trying to use Net::IP module from cpanmy $block = new Net::IP('');$block->ip() # get the first ip on the block$block->last_ip() #get the last ip on the blockhow can i increment the last ip , as i want to know the first ip on the next blocki tried something like :++$block->last_ip()but this is not working any idea? You can't increment the last ip as mentioned in Net::IP document. The ++ operator returns undef when the last address of the range is reached.The most simple way is to convert the last ip into integer, increment, then create a bran...

 perl                     1 answers                     33 view
 2018-10-22         Ida

Creating a software router

I want to build a software router.I have written the code to open a socket, receive the data, and print its received data. The GUI is going to be written using TkBelow is a simple version of the code, it does basically what i want to do, with the exception of not forking the new_port subroutine. Every time i click the submit button the Tk window is stuck. If someone can please assist with adding a fork to the new_port subroutine so it spawns a new child process. The idea is i can fill in a new port in the form and hit sumbit. The window closes, I then press new again put...

 perl                     1 answers                     53 view

Page 1 of 362  |  Show More Pages:  Top Prev Next Last