perl

perl one liner alternative to this bash "chain"?

Hello everyone: I am trying to comprehend Perl following the way describe in the book "Minimal Perl". I've uploaded all source txt files onto my own server : results folder I got the output from using several bash commands in a "chain" like this: cat run*.txt | grep '^Bank[[:space:]]Balance'|cut -d ':' -f2 | grep -E '\$[0-9]+' I kn...

Do I always have to provide Tkx's -command argument an anonymous subroutine?

I find it a bit weird that I have to wrap defined subroutines anonymously when specifying the -command argument for Tkx widgets. An excerpt from a TkDocs tutorial demonstrates this: my $cb = $frm->new_ttk__button ( -text => "Calculate", -command => sub {calculate();} ); sub calculate { $meters = in...

Perl standard input with argument inside Bash

I want to have such pipe in bash #! /usr/bin/bash cut -f1,2 file1.txt | myperl.pl foo | sort -u Now in myperl.pl it has content like this my $argv = $ARG[0] || "foo"; while (<>) { chomp; if ($argv eq "foo") { # do something with $_ } else { # do another } } But why the Perl script can't recognize the parameter passed t...

How can I close a Window using the OS-X ScriptingBridge framework, from Perl?

Problem... Since MacPerl is no longer supported on 64bit perl, I am trying alternative frameworks to control Terminal.app. I am trying the ScriptingBridge, but have run into a problem passing an enumerated string to the closeSaving method using the PerlObjCBridge. I want to call: typedef enum { TerminalSaveOptionsYes = 'yes ' /* ...

perl TemplateToolkit - Can't locate object method "new" via package

Hi, I have inherited a web project that is perl based and I'm attempting to set up a local testing server so changes can be made internally to the project. The server architecture Ubuntu 9.10 php 5.2.10 mysql 5.1.37 perl 5.10.0-24ubuntu4 All the dependent modules and packages are installed such as DateTime.pm, TemplateToolkit.pm but r...

CGI Perl script is printing the HTML (along with 'content-type: text/html') string to the browser rather than rendering it. How to fix?

I have a perl CGI script that needs to send back some HTML print qq^Content-type: text/html\n\n <HTML> <HEAD> <TITLE>some title</TITLE> ... ... ... ... ^: Instead of seeing the rendered HTML in the browser, I see the entire HTML along with the tags and the 'content-type' line in plain text. Below is how things look in the browser - C...

How can I call a Perl package I define in the same file?

I need to define some modules and use them all in the same file. No, I can't change the requirement. I would like to do something like the following: { package FooObj; sub new { ... } sub add_data { ... } } { package BarObj; use FooObj; sub new { ... # BarObj "has a" FooObj my $se...

Creating multiple csv files from data within a csv file.

System OSX or Linux I'm trying to automate my work flow at work, each week I receive an excel file, which I convert to a csv. An example is: ,,L1,,,L2,,,L3,,,L4,,,L5,,,L6,,,L7,,,L8,,,L9,,,L10,,,L11, Title,r/t,needed,actual,Inst,needed,actual,Inst,needed,actual,Inst,needed,actual,Inst,neede d,actual,Inst,needed,actual,Inst,needed,actua...

Perl open file problem

I am having some trouble trying to print from a file. Any ideas? Thanks open(STDOUT,">/home/int420_101a05/shttpd/htdocs/receipt.html"); #Results of a sub-routine &printReceipt; close(STDOUT); open(INF,"/home/int420_101a05/shttpd/htdocs/receipt.html"); $emailBody = <INF>; close(INF); print $emailBody; ERRORS: Filehandle STDOUT reop...

How can I run a Perl script on Mac OS X?

I know this is a real basic and stupid question but how do I run a Perl script on OS X? I honestly can't find the answer anywhere! Presumably I have to run a command in Terminal but what? ...

How can I send an HTML email with Perl?

I am trying to send an HTML email using Perl. open(MAIL,"|/usr/sbin/sendmail -t"); ## Mail Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; ## Mail Body print MAIL "Content-Type: text/html; charset=ISO-8859-1\n\n" . "<html><head></head><body>@emailBody"; cl...

Can't locate in @INC during CPAN dependency install performed not as root.

While trying to do: perl -I'/v1/data/site_perl' -MCPAN -e 'install Log::Dispatch'; I continue to get "Can't locate Params/Validate.pm in @INC." When looking at the output, /v1/data/site_perl is NOT in the @INC displayed, even though I used -I. I am not root so I have changed my CPAN config so that: 'makepl_arg' => q[LIB=/v1/data/si...

What are codepad.org's Perl runner limitations?

Sometimes I see people use http://codepad.org as a way to quickly run/test their Perl snippets (it supports doing that with a wide variety of languages, from C to Scheme to Perl). It's pretty obvious that there must be some limitations as to what code/features can be tested with codepad - does anyone know what those limitations are for...

How I can connect to Oracle from Perl?

We have Oracle Server " Oracle Version: 10.2.0.4.0 - 64bit". I like to connect to this server with Perl from my RHEL machine. I am able to connect via sqlplus successfully. I can use 32-bit or 64-bit Perl. I have few questions. Which files I should download from Oracle.com and where should I install them? What are the environment s...

How can I parse IP addresses and address ranges with Perl?

I have list of IPs: 238.51.208.96/28 238.51.209.180-199 238.51.209.100-109 238.51.213.2-254 ... How can I easily parse them? I need first and last IP from range. For the first line I can use Net::Netmask CPAN module, but what can I do with others lines? ...

How can I de-install a Perl module installed via `cpan`?

I am using Perl running in user space (not installed via root) and installing modules via the command-line cpan. I would like to know if there is a simple way to remove a module without having to do a lot of work deleting individual files. I searched for this question on the internet and found some answers, but the answers I've found se...

Why Read In UTF-16LE File Won't Convert "\r\n" Into "\n" In Windows

I am using Perl to read UTF-16LE files in Windows 7. If I read in an ASCII file with following code then each "\r\n" in file will be converted into a "\n" in memory: open CUR_FILE, "<", $asciiFile; If I read in an UTF-16LE(windows 1200) file with following code, this inconsistency cause problems when I trying to regexp lines with li...

Print array variables when using or not using double quotes.

Hi, When I learning to print array variables, I found the white space inserted when double quoter used. Snippet code as below. Could you please tell me why? #!/usr/bin/perl -w use strict; use warnings; my @str_array = ("Perl","array","tutorial"); my @int_array = (5,7,9,10); print @str_array; print "\n"; # added the double quotes print...

Perl WordPress::XMLRPC categories not being set.

UPDATE (FIGURED OUT): I figured this out on my own, this is not documented anywhere. The array reference passed needs to have each array item be a hash reference using either the a categoryName or categoryId key identifier. Meaning: 'categories' => [ {'categoryName' => 'CatName1'}, {'categoryName' => 'CatName2'}, ], The quest...

Perl: catch error without die

I'm playing around with error handling and got a little problem. I connect with a database using the DBI module. I do my own error handling by using a subroutine that I call upon an error. I can catch my own dies and handle them just fine but when my database connection fails, the DBI module apparently prints out it's own die : DBI co...