Command line: search and replace in all filenames matched by grep

I'm trying to search and replace a string in all files matched by grep: grep -n 'foo' * will give me output in the form: [filename]:[line number]:[text] For each file returned by grep, I'd like...

Perl, convert numerically-keyed hash to array

If I have a hash in Perl that contains complete and sequential integer mappings (ie, all keys from from 0 to n are mapped to something, no keys outside of this), is there a means of converting...

How can I see if MySQL truncated a field during an Update using Perl DBI

When I run this Update SQL in DBVis, I get an error (Data truncation: Data too long for column 'Description' at row 1). However, in Perl (DBI), this is not giving me an error I am guessing because...

How to call a python script from Perl?

I need to call "/usr/bin/pdf2txt.py" with few arguments from my Perl script. How should i do this ?

XML::LibXML replace element value

I want to replace a "VAL1" value of an element in xml file For some reason it does not work for me: ...

How can I restore my Perl environment and modules to a known state on Mac OS X?

I am an old time Perl hacker but I have basically given up on my Mac because I usually can't install anything with cpan. Something in the dependency list usually fails with meaningless (to me)...

parsing json file using perl

I am trying to parse a json file in perl. I want to extract the key "name" and corresponding value of it. my file looks like this { ...

What is the -t used for in this Perl code

I read in the perldoc that the -t file operator is used to decide if a filehandle is opened to a tty or not. Then i read what a tty was and from what i understand it's an old term for a...

perl print current year in 4 digit format

how do i get the current year in 4 digit this is what i have tried #!/usr/local/bin/perl @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); @days = qw(Sun Mon Tue Wed Thu Fri Sat...

Cannot run shell command through php exec, but can as user on shell?

I'm trying to get exiftool to work on my dedicated server. The issue is that PHP exec seems to run different than when a command is run as a user. Oddly enough, PHP shows up as the same user I log...

How can I build a Perl distribution with DIst::Zilla and use Carton for dependencies?

I have a perl distribution I have built with Dist::Zilla, and so I do not have to contaminate my installed Perl's lib with the dependencies, I have used Carton to manage them. Things work great in...

How can I square a number in Perl?

I have code to print out the first 9 squared numbers: #!/usr/local/bin/perl for($i=1;$i<10 ;$i++ ) { printf $i^2 . "\n"; } but for some reason this just outputs 30167451011. How do I...

Perl/ curl How to get Status Code and Response Body

I am trying to write a simple perl script that calls and API and if the status code is 2xx the do something with the response. While if it is 4xx or 5xx then do something else. The issue I am...

How to install perl module on RHEL?

I need to install perl-Expect, so, I executed: # yum install -y perl-Expect Error: Package: perl-Expect-1.21-14.el7.noarch (epel) Requires: perl(IO::Pty) >= 1.03 Error: Package:...

Resolving circular dependency between ExtUtils::MakeMaker and Test::Harness

I'm trying to compile git 2.5.2 on RHEL6 into my home directory and it requires a perl module ExtUtils::MakeMaker. ExtUtils::MakeMaker isn't installed in the standard locations and installing...

Perl: Invert a Condition

I want to match on fieldA and everything in fieldB as long as it isn't 456: if ($fieldA==123 && $fieldB!==456) What is the syntax I should use for fieldB? Is it !== or != or I've also seen...

How can I safely clean up root's .cpan folder?

I have a development class Linux server which has been used for a great deal of Perl code creation and testing. On this machine is a /root folder, part of the / partition, and in there is a .cpan...

How to find duplicate directories

Let create some testing directory tree: #!/bin/bash top="./testdir" [[ -e "$top" ]] && { echo "$top already exists!" >&2; exit 1; } mkfile() { printf "%s\n" $(basename "$1") > "$1"; } mkdir -p...

How to include conditionally Perl modules and libraries, as well as Global variables from them

I am developing a Perl script. Inside I use various moudules: use Module::One; use Module::Two; ... I also use global variables from these modules: $GLOBAL_1 = 1; $GLOBAL_2 = 1; ... Let's say...

Extract information from HTML using wget and Perl

I'm trying to write a Perl script that works like a tv guide that displays the current show playing for certain channels, for example Fox(7.1 WSVNH) and ABC(10.1 WPLGH). The output I'm trying...

ppm doesn't work after installing ActiveState Perl

I'm trying to install OpenSSL for a mongodb example, but can't install some perl packages I installed ActivePerl 5.28, restarted the computer, added path variable, and ppm still doesn't...

The perl recommend me to install ExtUtils::Manifest when I install ExtUtils::Manifest

The perl recommend me to install ExtUtils::Manifest when I install ExtUtils::Manifest. The os is Win10, and version of perl is strawberry-perl-5.24.4.1-64bit.msi. The detail information I get is...

How to use Shell Parameter Expansion in Perl?

I am trying to implement a Bash parameter expansion technique to replace the existing extension of a file in a Perl script. This is my bash code for replacing the file extension which is working...

How to set a ClientID in Perl module Net::MQTT::Simple (MQTT interface)?

I would like to use the Perl module Net::MQTT::Simple to send MQTT messages to a MQTT server. This is a simple MVP script based on the CPAN documentation of Net::MQTT::Simple: #!/usr/bin perl use...

Using Devel-Cover to get coverage reports

I am new to Perl and I am trying to generate a coverage report for a Perl script I had. I followed the steps mentioned here to install Devel-Cover https://code.activestate.com/ppm/Devel-Cover/ and...

How to concatenate every four lines for the first four lines of a file

I'm not sure the best wording to ask this question, but I'm trying to concatenate the first four lines to the next four lines and so on until the end of the file. My data looks...

Extract a word between brackets and replace it in a sentence

so let's say i have this sentence It's {raining|snowing|cold} outside What I want is to randomly extract a word between the brackets, which i did with awk -vRS="}" -vFS="|" '{print $2}' (still...

Count trailing newlines with POSIX utilities or Perl

I'm looking for ways to count the number of trailing newlines from possibly binary data either: read from standard input or already in a shell variable (then of course the "binary" excludes at...

Regular expression puzzler

I have been doing regular expression for 25+ years but I don't understand why this regex is not a match (using Perl syntax): "unify" =~ /[iny]{3}/ # as in perl -e 'print "Match\n" if "unify" =~...

Difference in Perl regex variable $+{name} and $-{name}

What is the difference between Perl regex variables $+{name} and $-{name} when both are used to refer to the same regex group from Perl statement/expression code?