recentpopularlog in

kme : perl   441

« earlier  
How do I retrieve the terminal width in Perl? - Stack Overflow
<code class="language-perl">use Term::ReadKey;
($wchar, $hchar, $wpixels, $hpixels) = Term::ReadKey::GetTerminalSize();</code>

<code class="language-perl">my $width = `tput cols`;</code>
perl  terminal  tui  shellscripting  solution 
5 weeks ago by kme
uninames - show selected Unicode character descriptions -
Doesn't do what 'uninames' from 'uniutils' does (print names of Unicode characters from stdin), but might still be handy.
unix  linux  perl  unicode  reference 
8 weeks ago by kme
How do I stop sed from adding extra newline characters - Unix & Linux Stack Exchange
GNU sed, if it's available, will not print an extraneous newline if you do 'sed -n "s/patt/repl/p"' (source:
If you do need that file not to end in a newline character, then you could use perl or other tools that can cope with non-text data.
<code class="language-bash">perl -pe 's|<LIST_G_STATEMENT>|$&\n|g'</code>
perl  sed  newlines  textprocessing  unix  annoyance  solution 
10 weeks ago by kme
#29763 (*_select framework does not apply to Perl: fix provided) – MacPorts
Status as of 06 December 2019:
You're not missing anything. It doesn't work yet. That's why this ticket is still open.
macports  perl  portselect  annoyance  needshelp 
11 weeks ago by kme
#53221 (perl_select not updated for Darwin 16) – MacPorts
My recollection is that perl_select has never been fully implemented and should not be used.

See also
macports  perl  portselect  annoyance  needshelp 
11 weeks ago by kme
vuetify - love & hate
"Backward compatibility is a property of a system, product, or technology that allows for interoperability with an older legacy system, or with input designed for such a system"
Perl values backward compatibility a lot.
We expect a sane script or application that was written 10 year ago to just run on a current system.
vuetify .. not so much
webdesign  webdevel  vue  vuejs  materialdesign  perl  slides 
november 2019 by kme
Ways to Flatten A Perl Array in Scalar Context - Stack Overflow
I had this weird problem with 'getsnpcoords' that was compressing a list within a double-quoted string /without/ the intermediate spaces, like some other package had unset '$"' and not reset it to the default, and what I ended up doing was an explicit 'join'.

When an array or an array slice is interpolated into a double-quoted string or a similar context such as /.../ , its elements are separated by this value. Default is a space. For example, this:
<code class="language-bash">print "The array is: @array\n";</code>
is equivalent to this:
<code class="language-perl">print "The array is: " . join($", @array) . "\n";</code>
Mnemonic: works in double-quoted context.
perl  syntax  lists  til 
november 2019 by kme
How can I conditionally use a module in Perl? - Stack Overflow
String eval is I think what I had to do to make a conditional 'use' statement for Text::MultiMarkdown, falling back to Text::Markdown.
perl  eval  exceptionhandling  sortof  solution 
november 2019 by kme
perl - Escape angle brackets using Pod::Markdown - Stack Overflow
I sort of had this problem, but my formatter was actually Pod::Usage, and it turns out POD has its own escapes for this "E<lt>" and "E<gt>".
perl  pod  funnycharacters  escapecharacter  sortof  solution 
november 2019 by kme
rt/ at stable · bestpractical/rt
Has an interactive shell, built-in help, and a dispatcher for command line options.
perl  commandline  tui  samplecode  inspiration 
october 2019 by kme
Longest Common Prefix in perl - René Seindal - Living in Venice
<code class="language-perl">\
use strict;
use warnings;
sub longest_common_prefix {
my $prefix = shift;
for (@_) {
chop $prefix while (! /^$prefix/);
return $prefix;
print longest_common_prefix(@ARGV), "
perl  string  substring  prefix  matching  samplecode  solution 
october 2019 by kme
UTF8, MySQL, Perl and PHP (Phil Gyford: Writing)
Only these two together seemed to work for me (CentOS 7, using vendor-supplied perl-DBD-MySQL-4.023-6.el7.x86_64):

<code class="language-perl">$dbh->{'mysql_enable_utf8'} = 1;
$dbh->do('SET NAMES utf8');</code>

The error message I would get otherwise was
SQL execution failed: COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1' (1253)

Even if the table, server, column, collation were all 'utf8'. The *client* was the missing part, and 'SET NAMES utf8' fixes that, seemingly.
perl  dbd  dbi  database  errormessage  devel  solution 
august 2019 by kme
DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI) -
Additionally, turning on this flag tells MySQL that incoming data should be treated as UTF-8. This will only take effect if used as part of the call to connect(). If you turn the flag on after connecting, you will need to issue the command SET NAMES utf8 to get the same effect.

This did *not* work as advertised, and I ended up setting it *after* the connect, along with 'SET NAMES', which actually *did* seem to fix the error messages I was getting about "COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1'":

<code class="language-perl"># source
# see also:
$dbh->{mysql_enable_utf8} = 1;
# $dbh->do('SET NAMES utf8');</code>
perl  dbi  dbd  mysql  dba  devel  reference  errormessage  workaround  solution 
august 2019 by kme
perl - Why CONCAT() does not default to default charset in MySQL? - Stack Overflow
This did NOT work (for me):
It probably is DBD::mysql issue/peculiarity. Try enabling utf8 in database handle as described in POD for DBD::mysql (mysql_enable_utf8 part).
perl  dbi  mysql  dba  database  query  collation  errormessage  maybesolution 
august 2019 by kme
Re: We plan to transition from RT to GitHub -

Here’s a proposal: if you’re going to complain GitHub and needing a login
and anonymity and open source purity and yadayadayada, how about you also
tell us how many bugs you’ve reported or fixes you’ve submitted to core or
CPAN. This is a positive move to a modern setup that can’t but help attract
new blood. We’re only a handful of messages in and we’re already throwing
up purist road blocks. Sawyer, this is a fantastic idea and if you need any
help, just throw some bits my way.
perl  github  purists  keepinitreal 
august 2019 by kme
The Perl Conference - YouTube |
The official YouTube page of The Perl Conference, hosted by The Perl Foundation.
perl  conference  talk  video 
july 2019 by kme
perlfaq4 - Data Manipulation - |
How do I determine whether a scalar is a number/whole/integer/float?

Assuming that you don't care about IEEE notations like "NaN" or "Infinity", you probably just want to use a regular expression (see also perlretut and perlre):
<code class="language-perl">
use 5.010;

if ( /\D/ )
{ say "\thas nondigits"; }
if ( /^\d+\z/ )
{ say "\tis a whole number"; }
if ( /^-?\d+\z/ )
{ say "\tis an integer"; }
if ( /^[+-]?\d+\z/ )
{ say "\tis a +/- integer"; }
if ( /^-?(?:\d+\.?|\.\d)\d*\z/ )
{ say "\tis a real number"; }
if ( /^[+-]?(?=\.?\d)\d*\.?\d*(?:e[+-]?\d+)?\z/i )
{ say "\tis a C float" }

There are also some commonly used modules for the task. Scalar::Util (distributed with 5.8) provides access to perl's internal function looks_like_number for determining whether a variable looks like a number. Data::Types exports functions that validate data types using both the above and other regular expressions. Thirdly, there is Regexp::Common which has regular expressions to match various types of numbers. Those three modules are available from the CPAN.
perl  validation  regex  regexp  solution 
july 2019 by kme
perlfaq6 - Regular Expressions - |
In fact, the question that I had is sort-of-answered in perlfaq4, which refers you to Regexp::Common, which is, unfortunately, not part of the standard library.
This section is surprisingly small because the rest of the FAQ is littered with answers involving regular expressions. For example, decoding a URL and checking whether something is a number can be handled with regular expressions, but those answers are found elsewhere in this document (in perlfaq9: "How do I decode or create those %-encodings on the web" and perlfaq4: "How do I determine whether a scalar is a number/whole/integer/float", to be precise).
perl  regex  regexp  faq  newbie  reference 
july 2019 by kme
Perl Is Still The Goddess For Text Manipulation – Towards Data Science
<code class="language-perl"># insert line numbers
perl -i -ne 'printf "%04d %s", $., $_'</code>

# print columns 1-5
perl -F"\t" -nlae'print join "\t", @F[0..4]'

# print all lines from line 18 to line 29
perl -ne 'print if $. >=18 && $. <=29'

# print all lines between two patterns
perl -ne 'print if (/^START/../^END/);'</code>
perl  textprocessing  oneliners  tipsandtricks  likeawk 
june 2019 by kme
Modulino: both script and module in Perl
<code class="language-perl">main() if not caller();</code>
perl  module  executable  script  tipsandtricks  likepython 
june 2019 by kme
File::Util - Easy, versatile, portable file handling -

Syntax: escape_filename( [string], [escape char] )

Returns it's argument in an escaped form that is suitable for use as a filename. Illegal characters (i.e.- any type of newline character, tab, vtab, and the following / | * " ? < : > \), are replaced with [escape char] or "_" if no [escape char] is specified. Returns an empty string if no arguments are provided. This is an autoloaded method.
perl  module  filesystem  filename  security  sanitization 
june 2019 by kme
arrays - Perl: if ( element in list ) - Stack Overflow
Here is an example which works with any searched (scalar) value, including undef:
<code class="language-perl">use List::MoreUtils qw(any);

my $value = 'test'; # or any other scalar
my @array = (1, 2, undef, 'test', 5, 6);

no warnings 'uninitialized';

if ( any { $_ eq $value } @array ) {
print "$value present\n"
perl  listmembership  lists  syntax  newbie  dammitbrain  likepython  solution 
june 2019 by kme
GitHub - subogero/rename: Perl rename as a separate package
Perl rename as a separate package. Contribute to subogero/rename development by creating an account on GitHub.
Removes confusion about the util-linux vs Perl versions of rename.

Installs into /usr/local/bin, so it has precedence over your system's default rename.
perl  rename  filemanagement  maybesolution 
may 2019 by kme
introspection - How do I list available methods on a given object or package in Perl? - Stack Overflow |
<code class="language-perl">
my @methods = Class::Inspector->methods( 'Foo::Class', 'full', 'public' );
perl  newbie  syntax  introspection  oop  solution 
february 2019 by kme
How do I tell what type of value is in a Perl variable? - Stack Overflow |

Perl provides the ref() function so that you can check the reference type before dereferencing a reference...

By using the ref() function you can protect program code that dereferences variables from producing errors when the wrong type of reference is used...
perl  devel  newbie  introspection  syntax  solution  dammitbrain 
february 2019 by kme
Perl - Subroutine redefined - Stack Overflow |
When I did this, it was because I used Exporter's @EXPORT, and redefined 'read' that some other package had also exported.
errormessage  perl  newbie  packages  devel  sortof  solution 
november 2018 by kme
perl - How can I set default values using Getopt::Std? - Stack Overflow |
The best thing is to use GetOpt::Long and use a hash instead of individual variables. Then you can pass default values by pre-populating the array
<code class="language-perl">
use Getopt::Long;
my %opts = (parameter => 20);
GetOptions( \%opts,
) or die "Invalid parameters!";
perl  argumentprocessing  shellscripting  getopt  solution 
november 2018 by kme
How can I tell if STDIN is connected to a terminal in Perl? - Stack Overflow |
<code class="language-perl">if (-t STDIN) {
# stdin is connected
} else {
# stdin is not connected
perl  devel  stdin  textprocessing  pipes  solution 
november 2018 by kme
What are your thoughts on sigils? : perl |
Larry Wall notes in an interview that «On a syntactic level, in the particular case of Perl, I placed variable names in a separate namespace from reserved words. That's one of the reasons there are funny characters on the front of variable names -- dollar signs and so forth. That allowed me to add new reserved words without breaking old programs.». Furthermore, first order lists allow for cleaner code sometimes. So I think sigils are great, but naturally inexperienced people often complain that they add clutter or make the code "unreadable" or "messy".

And I find that sigils give my code more visual rhythm and makes it easier to read

This, right here.

I don't need a fancy IDE or somehow encoding the type of the thing into the name of the thing to know what it is. Or, at least, the type of thing that the author wanted the interpreter to treat it as.

Having spent the last couple years in node/javascript land, too often it's a "oh, shit, it's a function?" is too common.
perl  language  design  perl5  syntax  thisvsthat  forthecomments  sigils 
september 2018 by kme
How can I send POST and GET data to a Perl CGI script via the command line? - Stack Overflow |
Add 'CGI qw( -debug )'.

<code class="language-perl">#! /usr/bin/perl
use warnings;
use strict;

use CGI qw/ :standard -debug /;

print "Content-type: text/plain\n\n",
map { $_ . " => " . param($_) . "\n" }

Also interesting:
To give a cgi script post data:
<code class="language-bash">$ echo -n 'a=b;c=d' | REQUEST_METHOD=POST CONTENT_LENGTH=999 perl index.cgi</code>

To give a cgi script get data:
<code class="language-bash">
$ perl index.cgi 'a=b;c=d'</code>

Of *course* that's how CGI works, but it's easy to forget that's how it works.
perl  testing  debugging  commandline  solution  webdevel  cgi  dammitbrain 
august 2018 by kme
« earlier      
per page:    204080120160

Copy this bookmark:

to read