perl

How can I combine Perl's split command with white space trimming?

Repost from Perlmonks for a coworker: I wrote a perl script to separate long lists of email separated by a semi colon. What I would like to do with the code is combine the split with the trimming of white space so I don't need two arrays. Is there away to trim while loading the first array. Output is a sorted list of names. Thanks. #!/...

Why doesn't my Perl grep return the first match?

The following snippet searches for the index of the first occurrence of a value in an array. However, when the parentheses around $index are removed, it does not function correctly. What am I doing wrong? my ($index) = grep { $array[$_] eq $search_for } 0..$#array; ...

Cross platform file compression

We need a cross platform solution for compressing files. Our server runs on Windows XP/Vista/7 and 3 Unix distros, SunOS, HPUX, and AIX. Our server creates files that needed to be zipped before being set back to the client. Our initial thought was to compress the files with jar, as most of the servers have java installed, but apparent...

Why do I get "uninitialized value" warnings when I use Date::Manip's sortByLength?

How might this block of code in Date/Manip.pm from the Date::Manip module: #*Get rid of a problem with old versions of perl no strict "vars"; # This sorts from longest to shortest element sub sortByLength { return (length $b <=> length $a); } use strict "vars"; I get this warning: Use of uninitialized value in length at /perl/lib...

How can I add an attribute to a child element using Perl's XML::Twig?

I have an XML string like this: <DATA> <CHILD_DATA ATVAL="value1"/> <CHILD_DATA /> </DATA> The final output I want is: <DATA> <CHILD_DATA ATVAL="value1"/> <CHILD_DATA ATVAL="value2"/> </DATA> My twig $t is at <DATA>. Now I want to add an attribute to the second <CHILD_DATA />. The attribute is ATVAL="value2". I tried th...

How can I translate these sed and perl one-liners to informatica?

Duplicate: http://stackoverflow.com/questions/1259545/let-me-know-alternate-command-in-dos-for-following-sed-and-perl-commands-closed the following commands have unique implementation in unix box. Need to implement in informatica(etl tool). If not any windows solution for the same sed 's/^#//g' < kam_account_calls.txt > kam_account_...

Is it possible to create an attribute that can only be set in the constructor in Moose?

Is it possible to create an attribute that can only be set in the constructor in Moose? I’d like to do something like this: my $foo = new Foo(file => 'foo.txt'); my $bar = new Foo(string => $str); $foo->file('baz.txt'); # dies I know I can create an attribute that can not be set in constructor, but the complementary case seems to be m...

How can I have a Perl/Tk progress bar showing that an external process is running?

I am creating a Perl/TK GUI code that will call a seperate exe inside. The progress bar widget will be the only indication that execution is happening inside it but problem is, as you run the code, the progress bar freezes because it has to finish first the execution of the seperate exe and after it's done, activity on the progress can b...

Why is it bad to put a space before a semicolon?

The perlstyle pod states No space before the semicolon and I can see no reason for that. I know that in english there should not be any space before characters made of 2 parts ( like '?',';','!' ), but I don't see why this should be a rule when writing Perl code. I confess I personally use spaces before semicolons. My reason is t...

How can I walk a YAML tree with Perl's YAML::Tiny?

I have a YAML document like this: --- version: 1 rootdirectory: - subdirectory: - file1 - file2 - subdirectory2 that I am loading into a YAML::Tiny object like this: $configuration = YAML::Tiny->read($configuration_file) I see from invoking the script with the Perl debugger that what I end up with is a set of nested has...

How can I safely pass a filename with spaces to an external command in Perl?

I have a Perl script that processes a bunch of file names, and uses those file names inside backticks. But the file names contain spaces, apostrophes and other funky characters. I want to be able to escape them properly (i.e. not using a random regex off the top of my head). Is there a CPAN module that correctly escapes strings for use ...

Why do I get "Can't use string as a HASH ref" error when I try to access a hash element?

How do I fix this error? foreach (values %{$args{car_models}}) { push(@not_sorted_models, UnixDate($_->{'year'},"%o")); } Error: Can't use string ("1249998666") as a HASH ref while "strict refs" in use at /.../BMW.pm line 222. ...

Does DBIx::Class have transparent caching?

In the C#/.Net world, there are ORMs such as NHibernate or ActiveRecord that includes transparent caching: database updates are transparently replicated to the cache, objects are retrieved directly from the cache when available, etc (often with memcached). It doesn't look like transparent caching is available in Perl with DBIx::Class. D...

Perl script that has command line arguments with spaces

I'm feel like I'm missing something pretty obvious here, but I can't seem to figure out what's going on. I have a perl script that I'm calling from C code. The script + arguments is something like this: my_script "/some/file/path" "arg" "arg with spaces" "arg" "/some/other/file" When I run it in Windows, Perl correctly identifies it...

Why do I get “uninitialized value” warnings when I use Date::Manip’s UnixDate in a sort block?

Related/possible duplicate: http://stackoverflow.com/questions/1263943/why-do-i-get-uninitialized-value-warnings-when-i-use-datemanips-sortbylength This block of code: my @sorted_models = sort { UnixDate($a->{'year'}, "%o") <=> UnixDate($b->{'year'}, "%o") } values %{$args{car_models}}; kept generating the following err...

What's the best technique for handling US Dollar calculations in Perl?

What's the best technique for handling US Dollar calculations in Perl? Especially: the following needs to work: $balance = 10; $payment = $balance / 3; # Each payment should be 3.33. How best to round amount? $balance -= $payment * 3; # assert: $balance == .01 ...

Where do I get the MQ DLLs I need for Perl's MQClient::* and MQSeries:: modules?

I need to rejig some VERY old Windows code that uses Perl to talk to MQ. Specifically, I need to be able to install Perl's MQClient::MQSeries, MQSeries::QueueManager, MQSeries::Queue and MQSeries::Message modules. When I fire up Strawberry Perl, go into CPAN and try to install them, I can see that there's several MQ client DLLs that ar...

Scalable Regex for English Numerals

I'm trying to create a regex to recognize English numerals, such as one, nineteen, twenty, one hundred and twenty two, et cetera, all the way to the millions. I want to reuse some parts of the regular expression, so the regex is being constructed by parts, like so: // replace <TAG> with the content of the variable ONE_DIGIT = (?:one|two...

How can I generate call graphs for Perl modules and scripts?

Hi All, I have a bunch of Perl scripts and Perl modules given to me by someone. I have a driver program that tests all these scripts and modules. I want to generate a call graph and see the flow. Is there something available for Perl for doing this? I'd like something like pycallgraph (for python). I am running all this in AIX. Thank...

How can I create a hash of hashes in Perl?

Hi everyone, I am new to Perl. I need to define a data structure in Perl that looks like this: city 1 -> street 1 - [ name , no of house , senior people ] street 2 - [ name , no of house , senior people ] city 2 -> street 1 - [ name , no of house , senior people ] street 2 - [ name , no of house , senior p...