perl

Advice on how to write robust data transfer processes?

I have a daily process that relies on flat files delivered to a "drop box" directory on file system, this kicks off a load of this comma-delimited (from external company's excel etc) data into a database, a piecemeal Perl/Bash application, this database is used by multiple applications as well as edited directly with some GUI tools. Some...

Grepping Key-Value Pairs from Brackets in Perl

What if I have a string that consists of tuples in brackets and I would like to get the maximum value out of the tuple in Perl? Example: Input: [everyday,32][hoho,16][toodledum,128][echigo,4] Output: 128 ...

Is it okay to use modules from within subroutines?

Recently I start playing with OO Perl and I've been creating quite a bunch of new objects for a new project that I'm working on. As I'm unfamilliar with any best practice regarding OO Perl and we're kind in a tight rush to get it done :P I'm putting a lot of this kind of code into each of my function: sub funcx{ use ObjectX; # i do...

Why is the list my Perl map returns just 1's?

The code I wrote is as below : #!/usr/bin/perl my @input = ( "a.txt" , "b.txt" , "c.txt" ) ; my @output = map { $_ =~ s/\..*$// } @input ; print @output ; My intention is to let the file name without the extension stored in the array @output. but instead it stores the value returned by s/// rather than the changed file name in @ou...

How do I extract the SMTP envelope and header with Perl?

What is SMTP Envelope and SMTP header and what is the relationship between those? How do I extract them with Perl? ...

What's wrong with my merge sort implementation in Perl?

I'm trying to write a merge sorting algorithm in Perl and I've attempted to copy the pseudo code from Wikipedia. So this is what I have: sub sort_by_date { my $self = shift; my $collection = shift; print STDERR "\$collection = "; print STDERR Dumper $collection; if ( @$collection <= 1 ) { return $c...

Do MooseX::AttributeHelpers and MooseX::FollowPBP interact correctly?

The following code defines two classes (DeckA and DeckB) that differ only in whether they use the features that come with MooseX::AttributeHelpers. The getters generated by Moose for DeckB are not what I expected. Is this a bug or am I misunderstanding how MooseX::AttributeHelpers and MooseX::FollowPBP ought to interact? My workaround f...

How can I make the list of letters from A to Z and iterate through them in the shell?

Say I want to iterate from letter A to letter Z in csh shell. How do I succinctly do that? In bash I would do something like for i in 'A B C ...Z'; do echo $i; done The point is I don't want to write A through Z, I want something like [A-Z] Can you suggest a one line suggestion in AWK or Perl? ...

Ignore lines with same next fields as previous

I have a file contents of which looks like this 123,1,ABC,DEF 123,1,ABC 345,4,TZY 456,3,XYZ 333,4,TTT,YYY 333,4,TTT I want to ignore lines with the previous and next contents the same i.e lines containing 123 and 333 Output needs to be 345,4,TZY 456,3,XYZ Any ideas on how to go about this ...

Is there any guarantee that results of globbing will be sorted in Perl?

Is there any guarantee that the array of filenames returned from a glob (e.g. <*>) will be sorted? I can't find that sorting is mentioned one way or the other in the documentation, but it seems to be the case in every directory I've tried it on. I'm talking about using this syntax: @files = <*>; If I need the files to be sorted, wou...

How can I find copy/paste (duplicate, clone) code in Perl?

I've searched the Internet for a while now and I have not been able to find any free (or cheap) tools/utilities/modules that can analyze a set of Perl files (modules or scripts) and flag duplicate or cloned or copy/pasted code. I'm better now, but I used to copy and paste sections of code all over the place. I'd like to clean it up and...

Can aptitude for learning Programming paradigms be influenced by culture or native language's grammar?

It is well known that different people have different aptitudes regarding various programming paradigms (e.g. some people have trouble learning non-procedural, especially functional languages. Some people have trouble understanding pointers - see Joel Spolsky's blog for musings on that. Some people have trouble grasping recursion). I wa...

How do I load a file relative to a module path?

Hello SO, I don't know how to do one thing in Perl and I feel I am doing something fundamentally wrong. I am doing a larger project, so I split the task into different modules. I put the modules into the project directory, in the "modules/" subdirectory, and added this directory to PERL5LIB and PERLLIB. All of these modules use some ...

How do I add RIFF header to MP3 files programatically?

More information about what I want to do here; http://www.studiodust.com/riffmp3.html I want a way so that my control panel (made with Perl and Webmin) can do this automatically. Right now I have to rely on system calls and have a binary for Linux. Is there a library that does it for Perl or some other language? What's the best way of ...

How can I create a binary file in Perl?

For example, I want to create a file called sample.bin and put a number, like 255, so that 255 is saved in the file as little-endian, FF 00. Or 3826 to F2 0E. I tried using binmode, as the perldoc said. ...

How can I print only every third index in Perl or Python?

How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array. ...

How can I update values on the screen without clearing it in Perl?

Hi, I want to display a set of values on screen and update that value every 5 seconds. I don't want to clear the screen. eg: hours: 1 mins : 30 sec: 45 here, values should change accordingly. How should i do that in Perl? Regards, Anandan ...

How do I get mod_perl to recognize changes to my application?

I'm running an apache2 / mod_perl2 combo on our development server. When I'm developing, my changes are instantly reflected in the webpage I'm working on. I assumed mod_perl was being clever and was reloading files when they were changed. But now another developer is working on a different part of the system and their changes are not p...

Why does Digest::SHA come up with different hashes than those shown in RFC 4868?

I'm trying to write some Perl to inter operate with hash functions in other languages, namely Java at this point. We have found what is presumably a correct source, RFC 4868 which includes some test keys & strings along with their hashed values. I'm using the following snippet, and can't get Perl to come up with the same result. I can ...

How do I rerun a subroutine without restarting the script in Perl's debugger?

Suppose I have a situation where I'm trying to experiment with some Perl code. perl -d foo.pl Foo.pl chugs it's merry way around (it's a big script), and I decide I want to rerun a particular subroutine and single step through it, but without restarting the process. How would I do that? ...