Perform regular expression in PERL PDL variable

Is it possible to execute a regular expression for an n-dimensional variable PDL?

For example, I can add 100 to all elements by doing

$a1 = pdl [1,2]; 
print $a1 + 100;

However, what if my array was a bunch of strings for which I would like to perform some task. For example, this fails:

$a = pdl ['suze','david'];
$a =~ s/suze/female/;
print $a;

Not sure if this is possible, but thanks in advance.

+4
source share
2 answers

The fact is that it PDLis a perl extension intended for scientific and mass processing and display of numerical data. So this is really not done to manipulate String. When you try to iterate through a script:

use strict;
use warnings;
use PDL;

my $a = pdl ['suze','david'];
print $_ . "\n" foreach ($a->list);

You'll get:

Argument "suze" isn't numeric in subroutine entry at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 1296, <DATA> line 207.
0
0
Argument "david" isn't numeric in subroutine entry at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 1296, <DATA> line 207.

When you delve deeper into POD, you will find:

$a = pdl(SCALAR|ARRAY REFERENCE|ARRAY|STRING);

STRING

pdl bad, inf nan , ( , ). , .

, PDL ? - ?

use strict;
use warnings;
use Data::Dumper;

my $a = ['suze','david'];
s/suze/female/ for @{$a};
print Dumper $a;

:

$VAR1 = [
          'female',
          'david'
        ];
+3

Paulchenkiller PDL PDL:: Char. , PDL:: Char . , . , PDL:: Char.

, Perl , , .

+1

Source: https://habr.com/ru/post/1543932/


All Articles