Re: Distinguish module loading error: Compilation fail vs. not existing

2017-11-17 Thread Simon Reinhardt
=~ /Can't locate (.*) in \@INC/) { >         say "module $1 not found"; >     } else { >         say "unknown error: $@" > }; > > This isn't 100% safe, but it covers the most common issue.  You can read > more at https://metacpan.org/pod/Try::Tiny#BACK

Distinguish module loading error: Compilation fail vs. not existing

2017-11-17 Thread Simon Reinhardt
Hi list, I need to check the cause of a module loading error. Currently I'm parsing the text of the thrown exception (see below). This seems to work, but is there a more idiomatic way? Best, Simon #!/usr/bin/env perl use 5.020; use warnings; use strict; use Module::Load; my $module= 'AB::CD';

Re: Image::Magick: Unicode annotations

2016-07-10 Thread Simon Reinhardt
Hi Omega, Am 10.07.2016 um 18:58 schrieb Omega -1911: > Are you certain the font you are using is supported? You are right: Using the Annotate method with "font => 'DejaVu-Sans'" made it work. Looks like their default font doesn't have proper unicode support :/ Thanks for the pointer, Simon

Image::Magick: Unicode annotations

2016-07-10 Thread Simon Reinhardt
Hi, I'm trying to place Unicode annotations on a JPEG file: #!/usr/bin/env perl use 5.010; use warnings; use strict; use Image::Magick; use utf8; my $image = Image::Magick->new(); $image->Read('file.jpg'); $image->Annotate(text => 'α', pointsize=>'60', geometry=>'+100+100'); $image->Write("/

Re: convert linear array to nested structure

2015-08-07 Thread Simon Reinhardt
Am 04.08.2015 um 23:06 schrieb Brandon McCaig: > Generally I meant that your solution was short and simple enough that > it probably wasn't worth the extra effort of trying to improve it > [unless the code was going to be maintained for a long time]. This is > what I came up with in a few minutes.

Re: convert linear array to nested structure

2015-08-01 Thread Simon Reinhardt
Am 30.07.2015 um 20:42 schrieb Brandon McCaig: > I'll give you my 2 cents for whatever that's worth. >:) Thanks for your many comments. The updated full project code is below. Feedback is appreciated. (you also find this at github.com/simon0x5b/bookmark-djvu) > I can't help thinking that the e

Re: Best way to translate parts of strings

2015-07-24 Thread Simon Reinhardt
Hi Gary, > Unfortunately some strings have a 'S' instead of a 5 or a 'B' instead of a 8 > > The fields are of the format > > Registration XX99XXX > Stock no XX9 > VIN XX9 > > I've been experimenting with translate to convert the letters to the correc

Re: convert linear array to nested structure

2015-07-24 Thread Simon Reinhardt
Am 21.07.2015 um 22:35 schrieb Jim Gibson: > That is an unique data structure and transformation requirement (as most are), so you are not likely to find an existing set of code to do exactly what you want. However, the transformation should not be too difficult, so you should try to code up somet

convert linear array to nested structure

2015-07-21 Thread Simon Reinhardt
Hi Team, is there a ready solution to convert an linear array of hashrefs like this [ {level => 0, value => "string1"}, {level => 1, value => "string2"}, {level => 2, value => "string3"}, {level => 2, value => "string4"} ] into the nested data structure [ {value => "string1", kids => [

Re: Regular Expression Help.

2015-03-25 Thread Simon Reinhardt
Hi Frank, when first learning regexps I read the section "In the World of Regular Expressions" in the Lama-Book [1]. If you find this introduction to slow, you might also take a look at chromatic's Modern Perl, which is available for free [2]. Regards, Simon Am 25

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Simon Reinhardt
Am 24.03.2015 um 14:03 schrieb Shlomi Fish: > This can be more idiomatically written as: > > $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] I agree, a sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] } is certainly more readable than the C-style sort {

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Simon Reinhardt
Hi Anirban, first we have to be clear how you want to sort the lines. Does 10-1 sort before 1-11 ? Do you want numeric (use <=>) or alphabetic (use cmp) order? > while (my $line = <$RFH>) { > chomp($line); > if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { > $sequence_no = "