[Solved] Sort mixed text lines (alphanum) in Perl

The Schwartzian Transform as suggested in Toto’s answer is probably the fastest way to sort your lines here. But you said you’re a Perl newbie, and I like to show how the lines can be sorted traditionally. Perl has a sort function that sorts a list simply by alphabet. But you can supply a custom … Read more

[Solved] Want to filter the percentage from my output [closed]

Perldoc is a great resource. Check out perldoc perlretut (tutorial) and perldoc perlre (all the details). Module Regexp::Debugger is also great for visualizing how the matches are happening. Here’s one possible implementation, based on the scant details you provided. #!/usr/bin/env perl use 5.014; use warnings; my $data=”mnttab 0K 0K 0K 54% /etc/mnttab”; my ( $percent … Read more

[Solved] Regular Expression in String [closed]

That’s XML. XML is a bad idea to parse via regular expression. The reason for this is because these XML snippets are semantically identical: <ul type=”disc”> <li class=”MsoNormal” style=”line-height: normal; margin: 0in 0in 10pt; color: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto”> <span style=”mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New … Read more

[Solved] how to include perl script in html

You can’t use SSI to send HTTP headers; by the time the SSI runs, it is too late. You should approach the problem from the opposite direction and have Perl generate the whole page (using PSGI), preferably using a template language (such as Text::Xslate), possibly using a MVC framework (such as Dancer). 2 solved how … Read more

[Solved] separating array elements every 4 characters in array

Please try this: my @array = (“0x0B0x0C0x4A0x000x010x000x000x020”); my @outarray = map { (my $vars = $_) =~ s/\w{4}/$&\,/g; $vars; } @array ; use Data::Dumper; print Dumper @outarray; Thanks to @derobert 4 solved separating array elements every 4 characters in array

[Solved] what does the $F[2]..$F[3] mean? [closed]

Why infinite loop appears to the script? There’s no infinite loop. For the input provided, it creates a hash with 239,517 elements, then dumps the hash. The output starts appearing almost immediately. Could you please tell me what does the $F[2]..$F[3] mean? In list context, if $F[2] and $F[3] are numbers, it returns a sequence … Read more

[Solved] How to create hash with duplicate keys

Perl is telling you exactly what is wrong. You have used the strict pragma, so using the %hash variable without declaring it is a syntax error. While the string %hash does not appear in your code, the string $hash{…} does, on each of the problem lines. This is the syntax to access an element of … Read more

[Solved] How can I read in a variable/value which is a runtime parameter that is inside a constant list of hashes?

As has been explained, your ERROR_SW is a constant, and may not contain run-time variables If you intended $switch_ip and $timeout to also be constant values then, because use constant is evaluated at compile time, you would also have to declare and define these two variables beforehand. Like this use strict; use warnings ‘all’; my … Read more

[Solved] C, Perl, and Python similar loops different results

Well, comparing your methods, it became obvious your final operation for calculating pi was incorrect. Replace pi = (val + x) * (four/(long double)n); with these two lines: val = val * (long double)2.0; pi = (val + x) * ((long double)2.0/(long double)n); Compiling and running gives: 3.14159265241 Which I believe is the output you’re … Read more

[Solved] Edit distance: Ignore start/end [closed]

The code to do this is simple in concept. It’s your idea of what you’d like to ignore that you can add on your own: #!perl use v5.22; use feature qw(signatures); no warnings qw(experimental::signatures); use Text::Levenshtein qw(distance); say edit( “four”, “foor” ); say edit( “four”, “noise fo or blur” ); sub edit ( $start, $target … Read more

[Solved] Perl module, inhereting from DBI , “Can’t call method ‘prepare'” error [duplicate]

Your code includes this line: if (!my $mysqlopen) { &conexion(); } You call your conexion sub with no arguments. However, this sub expects several arguments, including a blessed object, that you don’t provide. You might want to fix that. $database and $hostname also are expected in the arguments. Your call to conexion will always be … Read more