perl

perl + export param in to perl syntax in shell script

hi I have the following script that replace a param to b param and match only the c parameter in line how to change the perl syntax: if /$c/ in order to export c param to the follwoing perl syntax #!/bin/bash export a='@d&' export b='new text' export c='bla bla' echo $LINE | perl -pe 'next if /^#/; s/(^|\s)\Q$ENV{a}\E(\s|$)/$1$ENV{b}...

Too many DB connection with mod_perl2 moose application

I have a mod_perl2 based web app that requires a connection to a mysql database. I have implemented the SQL connection specifics in a moose role. Simplified, the role looks as follows: package Project::Role::SQLConnection; use Moose::Role; use DBIx::Connector; has 'connection' => (is => 'rw', lazy_build => 1); has 'dbh' => (is => 'r...

how to build sql server 2008 datetime object and insert it using perl DBI

How can i build a sql server 2008 datetime object with perl and insert it using the dbi module to specific table could someone provide example ...

Perl: Value of response code in HTTP::Request

Hi, all! So, I am writing a code to get a document from the internet. The document size is around 200 KB. This is the code: #!/usr/local/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = "SOME URL"; my $req = HTTP::Request->new(GET => $url); my $res = $ua->request($req); if($res->is_success){ print...

Perl, "closure" using Hash

I would like to have a subroutine as a member of a hash which is able to have access to other hash members. For example sub setup { %a = ( txt => "hello world", print_hello => sub { print ${txt}; }) return %a } my %obj = setup(); $obj{print_hello}; Ideally this would output "hello world" EDIT Sorry, I failed to spec...

Match any GET path with Mojolicious::Lite

Hello! I’d like to match any GET request in Mojolicious::Lite. The code looks like this: get '.*' => sub { my $self = shift; $self->render(text => 'Nothing to see here, move along.'); }; This dies with “Modification of non-creatable array value attempted” at MojoX::Routes::Pattern.pm, line 301. I tried other arguments to get,...

Perl Encode - UK characters

This is a part 2 question from This Question. So I'm trying out the :encode functionality but having no luck at all. use Encode; use utf8; # Should print: iso-8859-15 print "Latin-9 Encoding: ".find_encoding("latin9")->name."\n"; my $encUK = encode("iso-8859-15", "UK €"); print "Encoded UK: ".$encUK."\n"; Results: Encoded UK: UK ...

Why did File::Find finish short of completely traversing a large directory?

A directory exists with a total of 2,153,425 items (according to Windows folder Properties). It contains .jpg and .gif image files located within a few subdirectories. The task was to move the images into a different location while querying each file's name to retrieve some relevant info and store it elsewhere. The script that used File...

Perl, foreach order

Does Perl's foreach loop operator require that the list items be presented in order? For example my @a=(1,2,3); foreach my $item (@a) { print $item; } will always print 1 2 3? I suspect so, but I can't find it documented. ...

How do I best do balanced quoting with Perl's Regexp::Grammars?

Using Damian Conway's Regexp::Grammars, I'm trying to match different balanced quoting ('foo', "foo", but not 'foo") mechanisms -- such as parens, quotes, double quotes, and double dollars. This is the code I'm currently using. <token: pair> \'<literal>\'|\"<literal>\"|\$\$<literal>\$\$ <token: literal> [\S]+ This generally ...

Online job-searching is tedious. Help me automate it.

Many job sites have broken searches that don't let you narrow down jobs by experience level. Even when they do, it's usually wrong. This requires you to wade through hundreds of postings that you can't apply for before finding a relevant one, quite tedious. Since I'd rather focus on writing cover letters etc., I want to write a program t...

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 ...

Perl, get all hash values

Let's say in Perl I have a list of hash references, and each is required to contain a certain field, let's say foo. I want to create a list that contains all the mappings of foo. If there is a hash that does not contain foo the process should fail. @hash_list = ( {foo=>1}, {foo=>2} ); my @list = (); foreach my $item (@hash_list) { ...

Usage of ‘if’ versus ‘unless’ for Perl conditionals

What are some guidelines for the best use of if versus unless in Perl code? Are there strong reasons to prefer one or the other in some situations? ...

Perl script to print out cars model and car color

I am tying to create a perl script to printout car models and colors, and the data is below. I want to know if there is anyway to make the car model heading a field so that I can print it any time I want to? the data below is a csv file. the way I want the data to look on a report is below as well *This is how the data looks* Chevy ...

How do you get XML::Pastor to set xsi:type for programmatically generated elements?

I'm learning how to use Perl as an automation test framework tool for a Java web service and running into trouble generating xml requests from the Pastor generated modules. The problem is that when including a type that extends from the required type for an element, the xsi:type is not included in the generated xml string. Say, for exa...

Active Perl Installation on Windows operating system

Hi all. I have installed the Active perl in my windows OS. I have followed below url procedure to install Active Perl Installation after done with that .. I have tried to run "perl -v " in command line . But it says me following error. The system cannot execute the specified prgoram Now What I need to do to solve this i...

How to determinate file in Perl

Hello, I use File::Find -> find(\&f, $directory) for find some file with some content. Relevant part of my delegate looks like: sub f { my $file = $File::Find::name; return unless -f $file; return unless $file =~ /$file_pattern/; etc... but the problem is that, that this code returns every time where $file not exist in curren...

Perl Dbi and stored procedures

How can i retrive the return value of stored procedure by using perl and the dbi against sql server ? could someone provide example. ...

Perl XML::LibXML Parser Error

If I am using the XML::LibXML parser to repeatedly call a line like the following... $tree = $parser->parse_file($WBCall); ...where $WBCall represents a HTTP string to a service that returns data in XML format, then occasionally I receive an error like the following: ":1: parser error : Start tag expected, '<' not found" This occurs ...