logo
Tags down

shadow

How to do unary and/reduction of bus to a bit in Perl?


By : Fiarina Fabrics Tail
Date : October 17 2020, 06:10 AM
like below fixes the issue If $A is an 8-bit value, and if you want to AND all 8 bits with one another, you will always get 0 unless all 8 bits are 1
code :
+----+----+----+----+----+----+----+----+---------------------------------------+
| A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0 | A7 & A6 & A5 & A4 & A3 & A2 & A1 & A0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  0 |  0 |  0 |  0 |  0 |  0 |  0 |  1 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  0 |  0 |  0 |  0 |  0 |  0 |  1 |  0 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  0 |  0 |  0 |  0 |  0 |  0 |  1 |  1 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  0 |  0 |  0 |  0 |  0 |  1 |  0 |  0 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
...
+----+----+----+----+----+----+----+----+---------------------------------------+
|  1 |  1 |  1 |  1 |  1 |  1 |  1 |  0 |                                     0 |
+----+----+----+----+----+----+----+----+---------------------------------------+
|  1 |  1 |  1 |  1 |  1 |  1 |  1 |  1 |                                     1 |
+----+----+----+----+----+----+----+----+---------------------------------------+
my $B = $A == 255 ? 1 : 0;
( $A >> $bitnum ) & 1
my $B =
     ( ( $A >> 7 ) & 1 )
   & ( ( $A >> 6 ) & 1 )
   & ( ( $A >> 5 ) & 1 )
   & ( ( $A >> 4 ) & 1 )
   & ( ( $A >> 3 ) & 1 )
   & ( ( $A >> 2 ) & 1 )
   & ( ( $A >> 1 ) & 1 )
   & ( ( $A >> 0 ) & 1 );
my $B = 1
   & ( $A >> 7 )
   & ( $A >> 6 )
   & ( $A >> 5 )
   & ( $A >> 4 )
   & ( $A >> 3 )
   & ( $A >> 2 )
   & ( $A >> 1 )
   & ( $A >> 0 );
my $B =
     ( $A >> 7 )
   & ( $A >> 6 )
   & ( $A >> 5 )
   & ( $A >> 4 )
   & ( $A >> 3 )
   & ( $A >> 2 )
   & ( $A >> 1 )
   & ( $A >> 0 );
 my $B = $A;
 $B &= $B >> 4;
 $B &= $B >> 2;
 $B &= $B >> 1;


Share : facebook icon twitter icon

Can't make work Opencl Sum Reduction from AMD sample reduction when changing WorkGroups dimension


By : 4xtra
Date : March 29 2020, 07:55 AM
Hope that helps First of all, those reduction kernels only work correctly if the workgroup size is a power of two. This means that instead of 60 you should use something 64. Also, there is no way that changing the GLOBAL_DIM makes you run out of local memory: you're most probably doing something wrong when invoking the kernel.

How to generate an unary XML tag with Perl LibXML::XML


By : user3280839
Date : March 29 2020, 07:55 AM
it fixes the issue To remove a node, use removeChild. To produce an empty element, remove its text child:
code :
#! /usr/bin/perl
use warnings;
use strict;

use XML::LibXML;

my $xml = 'XML::LibXML'->load_xml( string => << '__XML__');
<root>
  <node id="a">
    <isSomething>_xxx_</isSomething>
    <someValue>_xxx_</someValue>
  </node>
  <node id="b">
    <isSomething>_xxx_</isSomething>
    <someValue>_xxx_</someValue>
  </node>
</root>
__XML__

my %nodes = ( a => [ 'true',  1 ],
              b => [ 'false', 2 ],
            );

for my $node ($xml->documentElement->findnodes('//node')) {
    my $id = $node->{id};
    my ($is_something, $value) = @{ $nodes{$id} };

    my ($s) = $node->findnodes('isSomething[.="_xxx_"]');
    if ('true' eq $is_something) {
        my ($text) = $s->findnodes('text()');
        $s->removeChild($text);
    } else {
        $node->removeChild($s);
    }

    my ($v) = $node->findnodes('someValue/text()[.="_xxx_"]');
    $v->setData($value);
}
print $xml;

Perl operator precendece for a combination of list and unary operators


By : Amii_B
Date : March 29 2020, 07:55 AM
like below fixes the issue I came across an odd case, related to operator precendence, I guess. Consider this test program: ,
Why does the second test fail?
code :
    |       '!' term                               /* !$x */
                    { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
    |       NOTOP listexpr                       /* not $foo */
                    { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
$ perl -Dpv -e'ok(! -e "foo", "bar")'
...

Next token is token '(' (0x1966e98)
Shifting token '(', Entering state 185
Reading a token:
Next token is token '!' (0x1966e98)
Shifting token '!', Entering state 49
Reading a token:
Next token is token UNIOP (0x110)
Shifting token UNIOP, Entering state 39
Reading a token:
Next token is token THING (0x1966e58)
Shifting token THING, Entering state 25

index:        2        3        4        5        6        7        8        9
state:        8       15      103       68      185       49       39       25
token:       @1 remember  stmtseq    amper      '('      '!'    UNIOP    THING
value:        0       22 (Nullop)    rv2cv 26635928 26635928      272    const

Reducing stack by rule 184 (line 961), THING -> term
Entering state 128
Reading a token:
Next token is token ',' (0x1966e58)

index:        2        3        4        5        6        7        8        9
state:        8       15      103       68      185       49       39      128
token:       @1 remember  stmtseq    amper      '('      '!'    UNIOP     term
value:        0       22 (Nullop)    rv2cv 26635928 26635928      272    const

Reducing stack by rule 199 (line 999), UNIOP term -> term
Entering state 150
Next token is token ',' (0x1966e58)

index:        1        2        3        4        5        6        7        8
state:        1        8       15      103       68      185       49      150
token: GRAMPROG       @1 remember  stmtseq    amper      '('      '!'     term
value:        0        0       22 (Nullop)    rv2cv 26635928 26635928     ftis

Reducing stack by rule 148 (line 829), '!' term -> termunop
Entering state 62

index:        1        2        3        4        5        6        7
state:        1        8       15      103       68      185       62
token: GRAMPROG       @1 remember  stmtseq    amper      '(' termunop
value:        0        0       22 (Nullop)    rv2cv 26635928      not

...
( ! -e "foo"
$ perl -Dpv -e'ok(not -e "foo", "bar")'
...

Reading a token:
Next token is token '(' (0x26afed8)
Shifting token '(', Entering state 185
Reading a token:
Next token is token NOTOP (0x26afed8)
Shifting token NOTOP, Entering state 48
Reading a token:
Next token is token UNIOP (0x110)
Shifting token UNIOP, Entering state 39
Reading a token:
Next token is token THING (0x26afe98)
Shifting token THING, Entering state 25

index:        2        3        4        5        6        7        8        9
state:        8       15      103       68      185       48       39       25
token:       @1 remember  stmtseq    amper      '('    NOTOP    UNIOP    THING
value:        0       22 (Nullop)    rv2cv 40566488 40566488      272    const

Reducing stack by rule 184 (line 961), THING -> term
Entering state 128
Reading a token:
Next token is token ',' (0x26afe98)

index:        2        3        4        5        6        7        8        9
state:        8       15      103       68      185       48       39      128
token:       @1 remember  stmtseq    amper      '('    NOTOP    UNIOP     term
value:        0       22 (Nullop)    rv2cv 40566488 40566488      272    const

Reducing stack by rule 199 (line 999), UNIOP term -> term
Entering state 65
Next token is token ',' (0x26afe98)

index:        1        2        3        4        5        6        7        8
state:        1        8       15      103       68      185       48       65
token: GRAMPROG       @1 remember  stmtseq    amper      '('    NOTOP     term
value:        0        0       22 (Nullop)    rv2cv 40566488 40566488     ftis

Reducing stack by rule 105 (line 683), term -> listexpr
Entering state 149
Next token is token ',' (0x26afe98)
Shifting token ',', Entering state 162
Reading a token:
Next token is token THING (0x26afdd8)
Shifting token THING, Entering state 25

index:        3        4        5        6        7        8        9       10
state:       15      103       68      185       48      149      162       25
token: remember  stmtseq    amper      '('    NOTOP listexpr      ','    THING
value:       22 (Nullop)    rv2cv 40566488 40566488     ftis 40566424    const

Reducing stack by rule 184 (line 961), THING -> term
Entering state 249
Reading a token:
Next token is token ')' (0x26afdd8)

index:        3        4        5        6        7        8        9       10
state:       15      103       68      185       48      149      162      249
token: remember  stmtseq    amper      '('    NOTOP listexpr      ','     term
value:       22 (Nullop)    rv2cv 40566488 40566488     ftis 40566424    const

Reducing stack by rule 104 (line 678), listexpr ',' term -> listexpr
Entering state 149
Next token is token ')' (0x26afdd8)

index:        1        2        3        4        5        6        7        8
state:        1        8       15      103       68      185       48      149
token: GRAMPROG       @1 remember  stmtseq    amper      '('    NOTOP listexpr
value:        0        0       22 (Nullop)    rv2cv 40566488 40566488     list

Reducing stack by rule 196 (line 993), NOTOP listexpr -> term
Entering state 65
Next token is token ')' (0x26afdd8)

index:        1        2        3        4        5        6        7
state:        1        8       15      103       68      185       65
token: GRAMPROG       @1 remember  stmtseq    amper      '('     term
value:        0        0       22 (Nullop)    rv2cv 40566488      not

...
( not -e "foo"
, "bar"
$ perl -MO=Concise,-tree -e'ok(! -e "foo", "bar")'
<a>leave[1 ref]-+-<1>enter
                |-<2>nextstate(main 1 -e:1)
                `-<9>entersub[t1]---ex-list-+-<3>pushmark
                                            |-<6>not---<5>ftis---<4>const(PV "foo")
                                            |-<7>const(PV "bar")
                                            `-ex-rv2cv---<8>gv(*ok)
-e syntax OK
$ perl -MO=Concise,-tree -e'ok(not -e "foo", "bar")'
<c>leave[1 ref]-+-<1>enter
                |-<2>nextstate(main 1 -e:1)
                `-<b>entersub[t1]---ex-list-+-<3>pushmark
                                            |-<9>not---<8>list-+-<4>pushmark
                                            |                  |-<6>ftis---<5>const(PV "foo")
                                            |                  `-<7>const(PV "bar")
                                            `-ex-rv2cv---<a>gv(*ok)
-e syntax OK
|-<6>not---<5>ftis
|-<9>not---<8>list
$ perl -MO=Deparse,-p -e'ok(! -e "foo", "bar")'
ok((!(-e 'foo')), 'bar');
-e syntax OK
$ perl -MO=Deparse,-p -e'ok(not -e "foo", "bar")'
ok((!((-e 'foo'), 'bar')));
-e syntax OK
!(-e 'foo')
!((-e 'foo'), 'bar')
ok( ! 'bar' );

Perl 6 reduce function and reduction metaoperator give different results


By : mborba22
Date : March 29 2020, 07:55 AM
Any of those help Both the meta-operator and reduce take into account the associativity of the operator passed to them; in the case of <, the operator is chaining.
When passing a custom block, reduce cannot see inside of it, and so it falls back to the default of left-associative; it then compares the later values against the boolean returned from the reducer, which numifies to 0 or 1, which is why the result ends up as True in the end.
code :
my @s1 =<1 2 3 2 3 4>;
my @s2 =<1 2 3 4>;
sub my-reducer($a, $b) is assoc('chain') {
    $a < $b
}
say reduce &my-reducer, @s1;    # False
say reduce &my-reducer, @s2;    # True

perl unary ~ gives not the expected result


By : Ghada
Date : March 29 2020, 07:55 AM
this one helps. Seems that on your setup, PHP ints are 32bit signed while perl ints are 64bit unsigned.
This will probably do what you need on the given system but it is not guaranteed to work the same if you use it on another installation of perl.
Related Posts Related Posts :
  • How to resolve @INC related issue in Perl
  • Perl DBI case insensitive methods
  • Unable to get page via HTTPS with LWP::Simple in Perl
  • Using Perl's File::Basename to rename a file extension
  • using an array as a reference is deprecated in perl
  • How to get unicode code points in perl v5.24?
  • Get array in perl from json_encode
  • perl print to a file and STDOUT which is the file
  • How to process variable dimension array in Perl
  • How to fetch a one table from HTML source file using lwp module?
  • Using Win32::Env perl module, environment variable not setting permanently in windows
  • why doesn't make -C change $PWD as seen through a scripting language such as Perl?
  • Assign temp file from cgi and read it in .sh
  • Displaying 12-h time in Perl using DateTime
  • Using Perl to replace empty string with space
  • Why Perl ignores spaces between a sigil and variable name?
  • how get the last directory using perl?
  • Perl parsing email body without parts using MIME::Parser
  • Graph.pm - how to get all paths with particular length?
  • Count tandem repeats in Perl
  • How to install Filter::Crypto module for perl under ubuntu
  • I'm facing problem with the email program in Perl
  • Use tr with arrays
  • How do I concisely check warning categories up to the root of the hierarchy in my package?
  • Is there a way to host a webServer in perl which should in HTTPS
  • Can't open perl script "Build.PL": No such file or directory in response to perl Build.PL
  • Query about how to unpack a packed binary data
  • How to print part of header and string in another file in Perl
  • Why does the below Perl code show "Use of uninitialized value in concatenation (.) or string" when I try to us
  • Is there any way to check whether a file is an empty file using PERL program?
  • Perl Date::Manip detects timezone wrong for EST and EDT
  • Which http headers to suppress "This document is no longer available." on browser back button?
  • How to read a excel file using perl?
  • While running an email program on Windows ActivePerl I'm getting an error
  • verify login+password in Perl via SAML
  • i want to search for a string in a file using perl
  • perl mismatched tag, problem = XML::Simple module?
  • Comparison of Math::BigInt with scalars in Perl
  • How do I do a case sensitive rename or move operation in perl?
  • how to convert column into row in perl
  • Conditions in Perl loops and performance
  • Packing an array causes "Can't locate method" error in perl
  • I need help regarding perl hash of array
  • Is there a faster way to get floating point bits than pack/unpack in Perl?
  • How do I collect coverage from child processes when running `cover -test`, and not otherwise? (Devel::Cover)
  • Google Maps API returned status 'REQUEST_DENIED' in perl
  • How to process the filename from multiple directory by Perl?
  • Can we run a Perl script in a browser without web server?
  • How can I create an RPM from a module and recursively create separate independent RPMs for the dependencies?
  • How to install dmake with perl?
  • perforce: Source of integration in perforce
  • How can you make an animated loading sign in Perl?
  • Perl with backticks - I do not understand the operation inside the backticks
  • Perl: Print the lines of the file in order of length, lines of equal length should be sorted alphabetically
  • I want to access private variable of a subroutine outside it
  • count number of times and print line number of occurence of a string in a file by reading that file line by line
  • Perl: How to join two columns of a text file, in which values of the first column should match in order with the values
  • General information about CGI redirections
  • Why comparison operator == does not work for strings in perl?
  • Rearrange print order of key-value data read from file in Perl
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk