Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Seekers of Perl Wisdom

( #479=superdoc: print w/ replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Win32::SerialPort install error on Strawberry Perl PDL
1 direct reply — Read more / Contribute
by derneue
on Aug 26, 2016 at 02:35
    Hi Monks, does anybody knows if Win32::SerialPort works with Win7x64 and the Perl Version noted in the title? I receive the following error after fetching from CPAN:
    Creating new t/ Creating new nomake_test Creating new nomake_install Checking if your kit is complete... Looks good Generating a dmake-style Makefile Writing Makefile for Win32::SerialPort Writing MYMETA.yml and MYMETA.json BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\perl\bin\perl.exe Makefile.PL +-- OK Running make for B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz cp lib/Win32/ blib\lib\Win32\ cp lib/Win32API/ blib\lib\Win32API\ BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\c\bin\dmake.exe -- OK Running make test "C:\strawberry-perl-\perl\bin\perl.exe" "-MExtUtils: +:Command::MM" "-MTest::Harness " "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'b +lib\arch')" t/*.t t/test1.t .. 1/309 # Failed test at t/test1.t line 534. t/test1.t .. 305/309 # Looks like you failed 1 test of 309. t/test1.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/309 subtests t/test2.t .. ok t/test3.t .. ok t/test4.t .. ok t/test5.t .. ok t/test6.t .. 1/? SetCommState failed at t/test6.t line 306. t/test6.t .. ok t/test7.t .. ok Test Summary Report ------------------- t/test1.t (Wstat: 256 Tests: 309 Failed: 1) Failed test: 195 Non-zero exit status: 1 Files=7, Tests=1808, 62 wallclock secs ( 0.11 usr + 0.22 sys = 0.33 +CPU) Result: FAIL Failed 1/7 test programs. 1/1808 subtests failed. dmake.exe: Error code 255, while making 'test_dynamic' BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\c\bin\dmake.exe test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports BBIRTH/Win32-SerialPort-0.22.tar.gz Stopping: 'install' failed for 'Win32::SerialPort'. Failed during this command: BBIRTH/Win32-SerialPort-0.22.tar.gz : make_test NO cpan>
Code rendering issue with specific vars in MetaCPAN POD
2 direct replies — Read more / Contribute
by stevieb
on Aug 25, 2016 at 13:46

    I've found an interesting issue with POD rendering on MetaCPAN.

    I have the following snippet in the POD for one of my modules:

    =head2 send_cmd($command) Sends any arbitrary command to the LCD. (I've never tested this!). Parameters: $command Mandatory: A command to submit to the LCD. =head2 position($x, $y) Moves the cursor to the specified position on the LCD display. Parameters: $x Mandatory: Column position. C<0> is the left-most edge. $y Mandatory: Row position. C<0> is the top row.

    The $x and $y variables don't show up. The code block for them does, but the variables don't. Things work as expected for the $command variable in the send_cmd(), as it shows up fine. You can see that here.

    It works with Pod::Readme:

    position($x, $y) Moves the cursor to the specified position on the LCD display. Parameters: $x Mandatory: Column position. 0 is the left-most edge. $y Mandatory: Row position. 0 is the top row.

    ...and even in view source on meta:

    <h2 id="position-x-y">position($x, $y)</h2> <p>Moves the cursor to the specified position on the LCD display.</p> <p>Parameters:</p> <pre><code> $x</code></pre> <p>Mandatory: Column position. <code>0</code> is the left-most edge.</ +p> <pre><code> $y</code></pre> <p>Mandatory: Row position. <code>0</code> is the top row.</p>

    ...but doesn't render properly in any browser I've tested with.

    I'm wondering if I should just work around this, or whether this is a known issue (I couldn't find anything by searching), and if it's worth taking up the chain or not (perhaps other specific vars don't render correctly either).

    Can anyone please let me know if they are seeing what I am?

perl dbi, prepare function using place holder
1 direct reply — Read more / Contribute
by leostereo
on Aug 25, 2016 at 11:56

    Hi guys , im trying to declare an 'insert into' statement for a prepare function using a place holder for the table name but ... can not get it to work, the idea is as follows:

    $sth = $dbh->prepare("INSERT INTO ? (ip,bsid,firmware) VALUES (?, ?, ? +)"); $sth->execute($table_name,$ip,$bsid,$firmware);

    but im getting:

    DBD::mysql::st execute failed: called with 4 bind variables when 3 are + needed
Printing an element of a list not an array
4 direct replies — Read more / Contribute
by raghuprasad241
on Aug 25, 2016 at 11:13
    GMAN all,

    GMAN (Good Morning, Afternoon, Night) depending on where you are :-)

    Is it possible to print individual elements of a list with out putting them into an array ? I think putting the list into an array is a wastage of memory if you are just trying to print it. For e.g. I am trying to do below with no success

    perl -e 'use v5.10; say (localtime)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

    Am I missing something simple ?

    A Monk!
finding a file exist amongst many files
2 direct replies — Read more / Contribute
by t-rex
on Aug 25, 2016 at 10:00

    Hello Monks, I want to test if a file with name tpsm exists, and my folder might contain many file such as

    tpsm_01 tpsm_12 tpsm_23 . . . and so on

    the above code didnt work as i didnt have exact file name , on the shell we can directly use file* to check for multiple files with the same name ( some part of the name) but how fdo i check here?

    basically i want to test if a file with name tpsm _x exists or not, i don't know what will be the value of x , but i just want to know if files having such names are there or not. i tried with

    $pwd = $ENV{'PWD'}; $file = "$pwd/tpsm*"; if (-e $file) { #do something }

    please let me know how can i achieve this

Compare array of hashes
3 direct replies — Read more / Contribute
by AnishaM
on Aug 25, 2016 at 08:20
    Hi Perl Monks, I have the below two hash of array of hashes.I need to compare these two array of hashes,each and every field needs to be compared.I cant use diff, I need to do it without using any inbuilt functions. Please help me out with this as I am really new to Perl. Thanks a lot in advance. HASH OF ARRAY OF HASHES 1:
    { 'details' => [ { 'name' => 'bbbb', 'time' => 1234, 'place' => AB }, { 'name' => 'aaaa', 'time' => 5678, 'place' => CD }, { 'name' => 'aaaa', 'time' => '91011', 'place' => EF }, { 'name' => 'aaaa', 'time' => '121314', 'place' => GH }, { 'time' => '151617', 'name' => 'cccc', 'place' => IJ }, ] };
    { 'details' => [ { 'name' => 'dddd', 'time' => 1234, 'place' => AB }, { 'name' => 'eeee', 'time' => 5678, 'place' => CD }, { 'name' => 'eeee', 'time' => '91011', 'place' => EF }, { 'name' => 'eeee', 'time' => '121314', 'place' => GH }, { 'time' => '151617', 'name' => 'cccc', 'place' => IJ }, ] };
Perl Array - What an array contains
4 direct replies — Read more / Contribute
by rahulme81
on Aug 25, 2016 at 07:51
     my $string = 'London,Paris,Madrid,Berlin';                                  

    Above string is passed to a function defined in another script where I am storing this in an array.

     my @capitals= split(/,/,$string);                                            

    Sometime $string can contain only one element as London

    I have a logic which requires me to check

    If my @capitals array contains only 'London'


    it contains all elements of my @capitals.

    Please help !!!

Use of uninitialized value $1
1 direct reply — Read more / Contribute
by Pazitiff
on Aug 25, 2016 at 07:42
    Hi to all. I have simple example:
    my $var; $var = "path_to_my_lib"; $var =~ m/lib/; say $1;
    Why i get exception - Use of uninitialized value $1 Sorry for noob question.
Check multiple array elements for a single condition
5 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 25, 2016 at 06:38

    Just a quick question - is there a shorthand form of this:

    if ($array[0] == 0 && $array[1] == 0)

    A statement that would check both elements [0] and 1 for the condition ==0 without having to repeat the statement?

My PerlTidy utility is choking on non-ASCII characters, help me figure out why?
2 direct replies — Read more / Contribute
by Cody Fendant
on Aug 25, 2016 at 03:05

    I have a Perl::Tidy utility/text filter which works with my editor (BBEdit) and I've just noticed it's killing non-ASCII characters.

    The code itself is pretty simple:

    #!/usr/local/bin/perl -wn use Perl::Tidy; BEGIN { my $input_string = ""; my $output_string = ""; } $input_string .= $_; END { Perl::Tidy::perltidy( source => \$input_string, destination => \$output_string, argv => '-ce -l=80' ); print "$output_string\n"; }

    As you can see it just runs over the input file with  -n, putting it into a scalar. Then Perl::Tidys that scalar, then puts it back.

    It works in every other way just as I'd like, but when it encounters unicode characters (I've been working on some Russian text and need to recognise these chars: 'ОЕАИН') it replaces them with question marks.

    I can't add command-line flags like -CIO, that's not allowed. I've tried adding binmode STDOUT, ":utf8" and binmode STDIN, ":utf8" to the BEGIN block but that hasn't changed anything.

    Of course I can use Perl::Tidy in other ways, but I'm used to this utility and would like to get it working again in a way I can trust, it's become a habit.

Add your question
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2016-08-26 09:13 GMT
    Find Nodes?
      Voting Booth?
      The best thing I ever won in a lottery was:

      Results (366 votes). Check out past polls.