perl

Removing Parts of String That Contain Digit With Sed/Perl (one-liner)

I have a data that looks like this: AB208804_1 446 576 AB208804_1orf 0 AB208804_20 446 576 AB208804_20orf 0 I want to convert them into this: AB208804 446 576 AB208804orf 0 AB208804 446 576 AB208804orf 0 just by removing _\digit part in column 1 and 4. Why this line doesn't work: sed 's/_\d+//g' What's the correct way to do it...

Perl - Insert lines after a match is found in a file

Hello All: I have a file with the following syntax in some_1.xyz module some_1 { INPUT PINS OUTPUT PINS } and I want to insert APPLY DELAYS xx and APPLY LOADS ld after line module some_1 { The following code works fine for just one file i.e., if I replace some_1.xyz to *.xyz then the script doesn't work. I tried introducing sleep(xx...

Regular expression match first found value

I have a program-generated HTML file, and this tag is repeating: <table cellspacing="0" cellpadding="0" border="0" id="pt1:pt_region0:0:resId1:5:pgl3"> <table cellspacing="0" cellpadding="0" border="0" id="pt1:pt_region0:0:resId1:4:pgl3"> <table cellspacing="0" cellpadding="0" border="0" id="pt1:pt_region0:0:resId1:3:pgl3"> How do I g...

Multi-platform chomp working on unix, windows and mac text files

Looking for a way to chomp newline characters irrespective of the platform the files were created on. The problem as specified by perlport#newlines is that newlines are encoded differently on each platform: \012 unix \015\012 windows \015 mac However, chomp is platform specific and will only remove the character for the platform it'...

Using Win32::API to accessing the methods of a DLL in Perl

I have in my possession a Microsoft Powershell script which examines all the files in a folded ending in .wtv (Windows Media Center recorded TV programmes), extracts some metadata (using a DLL called "Toub.MediaCenter.Dvrms.dll") and then writes it to stdout: [void][System.Reflection.Assembly]::LoadFile("C:\Toub.MediaCenter.Dvrms.dll") ...

How else can I replace multiple lines through the terminal in a Rails app?

Is there an alternative way to do the following one-liner replacement of text across all files in a Rails app? perl -pi -e 's/replaceme/thereplacement/g' $(find . -type f) Perl complains that there are too many files if I include the RAILS_ROOT, but it works for subdirectories. ...

How to avoid the system command execution sucessful message ?

I am executing the following Perl command: system ("cvs ci a.txt"); and it is displaying the CVS message. How to avoid this? ...

perl process queue

I have a Perl script which forks a number of sub-processes. I'd like to have some kind of functionality like xargs --max-procs=4 --max-args=1 or make -j 4, where Perl will keep a given number of processes running until it runs out of work. It's easy to say fork four process and wait for them all to complete, and then fork another fou...

parsing assembly code in perl.

0000000000033a1b subq $0x28,%rsp I am having trouble extracting 0x28 from the above line. I am able to extract subq from a big list of assembly code but i only want 0x28 since this gives me the stack size. I was thinking of using substr() function buy there are variations to it, another one could look like this: 0000000000...

Dynamic image gallery generation using PHP and jQuery

I've got an idea in my head, something I want to create, but am not sure about the best approach. I'd like to pitch the idea and get some opinions on a smart way to go about this before I dive headfirst in the wrong direction! I've got a photography website that displays multiple portfolios for a few different photographers. It's got th...

Perl, make script timeout after x number of seconds?

I have been searching on this but it is surprisingly hard to come by a straight answer to this (as php has a lot more info on this topic it seems).. I need to make my perl script die after a specified number of seconds because, as it is now, they are running too long and clogging up my system, how can I make it so the entire script just ...

perl - help passing/looping in arguments from file or within a separate perl data structure

I have a while loop that reads in a single file: my %MyItems = (); while (my $line = <>) { chomp $line; if ($line =~ m/(.* $mon $day) \d{2}:\d{2}:\d{2} $year: ([^:]+):backup:/) { my $BckupDate="$1 $year"; my $BckupSet =$2; $MyItems{$BckupSet}->{'MyLogdate'} = $...

What is the best library for reliably dealing with attachments from email?

I have an application and need to write a program that is able to figure out attachments from all kinds of email senders (and MUAs) reliably. PHP doesn't seem to have a great MIME parser so I was hoping some other languages might. I've seen the PHP Mail Mime Parser but it's not robust at all and I know (and have confirmed) it doesn't w...

Perl - Subroutine redefined

I have asked this question before or searched and seen others ask - why am I getting the warning "Subroutine mySub redefined at ../lib/Common.pm line x"? and you always get the answer you declared the sub twice in the same code. I created this test package: ENTIRE FILE --------------- package Common; use strict; sub thisSubroutineIs...

help printing out hash keys to needed format

I need help printing out data from a hash/hash ref to STDOUT or file with data in a specific order if possible. I have a perl routine that uses hash references like so: #!/usr/local/bin/perl use strict; use warnings; use File::Basename; use Data::Dumper; my %MyItems; my $ARGV ="/var/logdir/server1.log"; my $mon = 'Aug'; my $day = '0...

Perl Term::Screen Enable insert character / delete character

The Perl module Term::Screen has a method for inserting a character and deleting a character. Both of these methods have an accompanying method to check if the interface allows for such actions [ic_exists() and dc_exists()]. I'm running this script through a ssh session and the ic_exists and dc_exists are returning 0, not available. W...

What, if any, are the disadvantages of SQL::Interp over SQL::Abstract?

I'm currently looking at some light-weight SQL abstraction modules. My workflow is such that i usually write SELECT queries manually, and INSERT/UPDATE queries via subs which take hashes. Both of these modules seem perfect for my needs and i have a hard time deciding. SQL::Interp claims SQL::Abstract cannot provide full expressivity in ...

How do I do this search and order_by on a DBIx::Class::ResultSet

Problem definition. I have multiple clients with multiple users. Each client needs to be able to associate custom data with a user, search, and order by. Database Solution: A table Customfields which defines the customfields table. It has an id and name. It has a has_many relationship with a Userfields table (aka "attributes"). The...

Perl Hashes and array

Hi, I have an array with 28 elements. I copied array contents into a hash. If i try to print the hash it is not showing all keys and values. Code is given below, @new; %hash = @new; foreach $food (keys %hash) { $color = $hash{$food}; print "$food is $color.\n"; } Output is :: attribute is Mandatory. min is 0X00. value is 778....

Using Different Outbound IPs in Perl

We have a few different websites running on the same server that all access 1 particular web service with each having their own unique API key. Unfortunately the web service has a daily limit based on IP address (not API key) so while each of our sites is way under their daily limit, combined they are over the IP limit. When accessed via...