Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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
Using Tk inside a Perl exe
1 direct reply — Read more / Contribute
by Garden Dwarf
on Nov 16, 2018 at 05:58
    Hello,

    I have a perl program working fine as perl, but when converting to an exe (using pp), it dies by saying "Can't call method crc32String...".

    After investigation I notice that I build a button with a "png" graphic part. The image is loaded using Tk:findINC(), which seems to be an issue (and as it is part of a third party module, I cannot avoid this). I didn't find anything about this (which dll do I have to include?) on Google, so I need some help if you don't mind.

    The line to generate this error is as follows:

    print Tk::findINC('icon.png')."\n";

    Thanks in advance!

Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl
2 direct replies — Read more / Contribute
by spriyada29
on Nov 15, 2018 at 22:29

    I want to generate an array of bit streams depending on the width with each nibble(4 bits)taking either all 1s or 0s. Width is a multiple of 4 E.g. 1. if my Width= 8. I would like to generate 3 bit streams as 11110000 00001111 11111111 if Width=12 , My array should have elements like 111111111111 111111110000 111100001111 000011111111 111100000000 I have tried to generate it using the following perl code

    my $numofstrobes; my @strobes; # To generate the stream of all 1s my $all1stream="1" x $width; my $x_num = oct("0b" . $all1stream); # to convert string into int #To Calculate the number of streams for($i=4;$i<=$width;$i=$i+4){ $numofstrobes+=int($width/$i); } #To calculate the bit stream `my $j=4; for($i=0; $i<$numofstrobes-1; $i++){ my $k=$j-4; my $temp_num=$x_num; while($k<$j) { $temp_num=$temp_num-(2**$k); $k++; } $strobes[$i]=$temp_num; $j+=4; $strobes[$numofstrobes-1]=$x_num`;
    It's working fine to generate stream with changing just nibbles around but doesn't work for case where I need to make let's say 2 nibbles 0s(1111 0000 0000) can someone help me with it or can suggest a better way to do it ?
Multiple Line Regex Not Working
2 direct replies — Read more / Contribute
by ImJustAFriend
on Nov 15, 2018 at 17:06
    Hello again monks. Now that I have the right log file to code against, I have come across another issue. I have a log formatted like this:
    <13>Nov 15 21:26:00 OamCOMM[365626]: TIMESTAMP=Thu Nov 15 21:26:00 2018 MSGCLS=OAMOPE Title=OAM Create OPERATION Severity=Inform message={username:xxxxxxxx@xxxxxxxxxxxxxxxxxxx; causeDISTINGUISH_NAME=label=x,label=x,;label=x,label=xxxxxxxxxxxxxxx, +label=x,label=xxxx USER_LABEL= ******************* parameters after change =******************* label=xxxxxxxxxxxxx label=xxxxxxxxxxxxxxxxxxxxxxx label=xxxxxxxxxxxxxxxxxxxxxxxxxxxx label=sxxxxxxxxxxxxxxxxxxxxxxxxxxxxx label=xxxxxxxxxxxx ******************* xxxxxxxxxxxx =******************* label=x } Message Id=xxxxxxxx
    For troubleshooting purposes I extracted one "chunk" of the log and put it into a text file t.txt. I then crafted t.pl to see if I could get the coding to work without impacting my larger script. Basically, I need to capture everything between "message=" and "Message Id" for this log entry. I am thinking in an array for processing after extraction. I have literally tried 40 different ideas, either my own or found on internet search, and nothing works. Here's my t.pl code I'm trying to make work:
    #!/bin/perl use strict; use warnings; use Data::Dumper; my $mlsf = "t.txt"; my @res; open IN, "<", $mlsf or die "IN: $!\n"; while (my $mls = <IN>) { @res = $mls =~ m/^.*message=(.*?)Message Id.*$/gs; } print Dumper (\@res);
    When I execute this script, I get:
    $VAR1 = [];
    Anyone have any ideas?
One-liner to append text at fixed column
2 direct replies — Read more / Contribute
by LanX
on Nov 15, 2018 at 17:01
    Hi

    I wanted to be able to mark lines with comments at a fixed column an came up with this one-liner solution.

    Did I miss a more elegant solution?

    |perl -pe 'substr $_, -1, 0, " "x(68-length$_) . "  #:$1" if /(^#|nextstate|var\d+)/;'    

    Explanation:

    • -p loop over input and print $_ at the end of -e evalcode
    • substr is inserting the text just before the newline (index -1, length 0)
    • " " x (68 - length $_) fills in space till column 68
    • "  #:$1" inserts the match at column 70
    • if line $_ longer than 68 char, append the match after two spaces
    example with column 50

    $ perl -MO=Concise,-src tst_b_xref4.pl|perl -pe 'substr $_, -1, 0, " " +x(48-length$_) . " #:$1" if /(^#|nextstate|var\d+)/;' tst_b_xref4.pl syntax OK j <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 # 1: for ( #:# 2 <;> nextstate(main 3 tst_b_xref4.pl:1) v:{ ->3 #:nextstate 4 <1> preinc[t2] vK/1 ->5 - <1> ex-rv2sv sKRM/1 ->4 3 <#> gvsv[*var1] s ->4 #:var1

    Use case: Re^12: B::Xref buggy?

    update

    a bit shorter |perl -pe 'chomp, $_.=" "x(48-length$_) . "  #:$1\n" if /(^#|nextstate|var\d+)/;'

    update

    meh, I expected a printf solution to be shorter

    |perl -pe 'chomp, printf ("%-48s  #:$1\n",$_), $_="" if /(^#|var|nextstate)/'

    update

    |perl -pe 'chomp, $_ = sprintf "%-48s  #:$1\n",$_ if /(^#|var|nextstate)/'

    IMHO best solution so far. :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Can't install CPAN module "Make had returned bad status, install seems impossible"
2 direct replies — Read more / Contribute
by msnyder424
on Nov 15, 2018 at 17:01

    Hi Monks, I am trying to install a CPAN module but every time I try I get a long result that ends in an error.

    When I run:

    cpan install Algorithm::Permute

    I get...

    Reading '/Users/matthewsnyder/.cpan/Metadata' Database was generated on Thu, 15 Nov 2018 14:17:03 GMT Running install for module 'Algorithm::Permute' Running make for S/SL/SLOYD/Algorithm-Permute-0.16.tar.gz Checksum for /Users/matthewsnyder/.cpan/sources/authors/id/S/SL/SLOYD/ +Algorithm-Permute-0.16.tar.gz ok CPAN.pm: Building S/SL/SLOYD/Algorithm-Permute-0.16.tar.gz Checking if your kit is complete... Looks good Warning: prerequisite Test::LeakTrace 0 not found. Generating a Unix-style Makefile Writing Makefile for Algorithm::Permute Writing MYMETA.yml and MYMETA.json ---- Unsatisfied dependencies detected during ---- ---- SLOYD/Algorithm-Permute-0.16.tar.gz ---- Test::LeakTrace [build_requires] Running make test Delayed until after prerequisites Running make install Delayed until after prerequisites Running install for module 'Test::LeakTrace' Running make for L/LE/LEEJO/Test-LeakTrace-0.16.tar.gz Checksum for /Users/matthewsnyder/.cpan/sources/authors/id/L/LE/LEEJO/ +Test-LeakTrace-0.16.tar.gz ok CPAN.pm: Building L/LE/LEEJO/Test-LeakTrace-0.16.tar.gz Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for Test::LeakTrace Writing MYMETA.yml and MYMETA.json cp lib/Test/LeakTrace.pm blib/lib/Test/LeakTrace.pm cp lib/Test/LeakTrace/JA.pod blib/lib/Test/LeakTrace/JA.pod cp lib/Test/LeakTrace/Script.pm blib/lib/Test/LeakTrace/Script.pm Running Mkbootstrap for LeakTrace () chmod 644 "LeakTrace.bs" "/usr/bin/perl" "-Iinc" -MExtUtils::Command::MM -e 'cp_nonempty' -- Le +akTrace.bs blib/arch/auto/Test/LeakTrace/LeakTrace.bs 644 "/usr/bin/perl" "-Iinc" "/System/Library/Perl/5.18/ExtUtils/xsubpp" - +typemap '/System/Library/Perl/5.18/ExtUtils/typemap' LeakTrace.xs > +LeakTrace.xsc mv LeakTrace.xsc LeakTrace.c cc -c -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstac +k-protector -Os -DVERSION=\"0.16\" -DXS_VERSION=\"0.16\" "-I/Syste +m/Library/Perl/5.18/darwin-thread-multi-2level/CORE" LeakTrace.c LeakTrace.xs:2:10: fatal error: 'EXTERN.h' file not found #include <EXTERN.h> ^~~~~~~~~~ 1 error generated. make: *** [LeakTrace.o] Error 1 LEEJO/Test-LeakTrace-0.16.tar.gz /usr/bin/make -- NOT OK 'YAML' not installed, will not store persistent state Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible Running make for S/SL/SLOYD/Algorithm-Permute-0.16.tar.gz Has already been unwrapped into directory /Users/matthewsnyder/.cpan +/build/Algorithm-Permute-0.16-bq41zl CPAN.pm: Building S/SL/SLOYD/Algorithm-Permute-0.16.tar.gz Warning: Prerequisite 'Test::LeakTrace => 0' for 'SLOYD/Algorithm-Perm +ute-0.16.tar.gz' failed when processing 'LEEJO/Test-LeakTrace-0.16.ta +r.gz' with 'make => NO'. Continuing, but chances to succeed are limit +ed. cp lib/Algorithm/Permute.pm blib/lib/Algorithm/Permute.pm Running Mkbootstrap for Permute () chmod 644 "Permute.bs" "/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Permute.bs + blib/arch/auto/Algorithm/Permute/Permute.bs 644 cc -c -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstac +k-protector -Os -DVERSION=\"0.16\" -DXS_VERSION=\"0.16\" "-I/Syste +m/Library/Perl/5.18/darwin-thread-multi-2level/CORE" -DPERL_EXT cool +lex.c In file included from coollex.c:11: ./coollex.h:13:10: fatal error: 'EXTERN.h' file not found #include "EXTERN.h" ^~~~~~~~~~ 1 error generated. make: *** [coollex.o] Error 1 SLOYD/Algorithm-Permute-0.16.tar.gz /usr/bin/make -- NOT OK Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible

    I'm pretty experienced with scripting but this sort of stuff is out of my realm. I see a couple issues but I have not been able to resolve any of them:

    1. Twice it says "fatal error: 'EXTERN.h' file not found". But I can locate this file. It's actually in many locations in my home folder and elsewhere on my hard drive.

    And 2. Near the end: "/usr/bin/make -- NOT OK"

    I tried reinstalling CPAN and updating Perl. The weirdest part is that I can install other modules just fine, provided I do sudo. But running the above command as a super user returns the same thing.

    Any help is much appreciated!

play mp3 stream (music) portably
2 direct replies — Read more / Contribute
by Discipulus
on Nov 15, 2018 at 06:07
    Hello nuns and monks,

    As you can see in my read an mp3 stream and save tracks using icy-metaint (ICY protocol) i was able to succesfully read an mp3 stream cutting it at icy-mataint occurences and also able to (possibly) skip advertisements.

    Now, and was my original goal, I want to reproduce this stream and I found that all modules I investigated need a file while I have a stream.

    If you take a look at my above mentioned code, I just read froma a socket by chunk and, in the read_stream sub, I get $buf populated with just the music (no metadata) and I pass $buf to the write_stream sub.

    So my original idea was to push all these $buf into something like a big cache and have some other sub shifting such cache and play each chunk..

    Some help on how to implement it? ;=) I'd like a perl solution, portable as much as it is possible (you know I mainly work on win32..): so using external programs as'mpeg123' and similar are not what i'm searching for. Until now I have mumbled the following:

    1 - tempfile)As all modules (and programs too) I investigated, needs to be feed with a file, it will be possible to have a temp file and append to it. It's not a optimal solution: how to know how much of the the neverending file was already played? how to rotate it?

    2 - reproxing) Once i have $buf i can re-stream them using a local server listening on 127.0.0.1 and launch an external program (like vlc or you preferred one) to connect to such stream to play it. This is an overcomplicated solution..

    The only module I found that seems able to play music contained in a variable is SDL::Mixer::Music that can receive data via SDL::RWOps but I was not able to make it to run. Examples in this direction will be appreciated. I suppose SDL has some limitation playing mp3 on windows (missing libraries?) I had success only playing wav files (not varibles with wav inside).

    Form the SDL::Mixer::Music documentation

    use SDL; use SDL::Mixer; use SDL::Mixer::Music; use SDL::RWOps; my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music ); my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );

    Any help and suggestion will be very much appreciated

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Browser cache with Selenium::Remote::Driver
No replies — Read more | Post response
by Perlchaoui
on Nov 15, 2018 at 05:55

    Hello Monastery

    Is there a way to clear the browser cache, using Selenium::Remote::Driver module with Chrome driver. I want to clear the cache each time i need to quit the browser/driver

    Thank you in advance for your wise support

df -h script to 10 servers and append the printout into one file
3 direct replies — Read more / Contribute
by sabas
on Nov 14, 2018 at 20:07

    Can i ask a favor if I can have a perl script to login ssh into multiple servers and execute a command like "df -h" and have the printout written into one log file. example: 10 servers, and the 10 printout of those 10 servers using df -h command will be appended into one file. Thank You and appreciate your help.

B::Xref buggy?
1 direct reply — Read more / Contribute
by LanX
on Nov 14, 2018 at 19:09
    Hi

    I'm not sure but it seems like B::Xref is buggy, after running perl -MO=Xref,-r,-d tst_b_xref.pl

    with 5.24 Activestate on

    D:\tmp>perl -c tst_b_xref.pl tst_b_xref.pl syntax OK D:\tmp>more tst_b_xref.pl use strict; my $sth; my $lines; while ( my @row = $sth->fetchrow_array ) { #5 print "@row.\n"; #7 push @{$lines},+{status => $row[0]}; #9 }

    I'm getting

    tst_b_xref.pl (main) 2 (lexical) $ sth + intro tst_b_xref.pl (main) 2 (lexical) $ lines + intro tst_b_xref.pl (main) 7 main $ " + used tst_b_xref.pl (main) 7 (lexical) @ row + used tst_b_xref.pl (main) 9 (lexical) $ lines + used tst_b_xref.pl (main) 9 (lexical) @$ lines + used tst_b_xref.pl (main) 9 (lexical) $ sth + used tst_b_xref.pl (main) 9 (lexical) $ sth + subused tst_b_xref.pl (main) 9 (lexical) @ row + intro

    please note that @row was "intro"-duced in line 5 inside while and "used" in line 7 and 9,

    But the output says used in 7 and introduced in 9, which doesn't really make sense.

    (I'm taking no issues (yet) on the "$ sth subused" line which is reporting the ->fetchrow method call.)

    update
    Reproduced with 5.18 under Ubuntu
    $ cat /tmp/xref.out tst_b_xref.pl (main) 2 (lexical) $ sth + intro tst_b_xref.pl (main) 3 (lexical) $ lines + intro tst_b_xref.pl (main) 7 main $ " + used tst_b_xref.pl (main) 7 (lexical) @ row + used tst_b_xref.pl (main) 9 (lexical) $ lines + used tst_b_xref.pl (main) 9 (lexical) @$ lines + used tst_b_xref.pl (main) 9 (lexical) $ sth + used tst_b_xref.pl (main) 9 (lexical) $ sth + subused tst_b_xref.pl (main) 9 (lexical) @ row + intro

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    update

    Added line numbers

    update

    Perl seems to optimise to my ($sth,$lines);', that's why '$lines is reported at line 2 not 3.

Ambigious fields
3 direct replies — Read more / Contribute
by Johndow
on Nov 14, 2018 at 17:05
    I need to split the .bin file based on the combination of Account Number and Page number (Page 1 of X) using Perl. As provided in the sample data for account number 111-111111 there are two pages of statement which starts from Page 1 of 1 and ends at Page 1 of 1 itself and the second account number is 222-222222 which starts from Page 1 of 3 and ends at Page 3 of 3. The sample input needs to be split up in two files. File 1 and File 2. Below is the code which I wrote,I am unable to understand how do I put the page validation in place with a combination of a unique account number My perl version v5.10.1. Appreciate any help and thanks in advance.
    #!/usr/bin/perl use strict; use warnings; my $input = do { local $/; <DATA> }; my @input = split /(?=\d+ Page)/, $input; foreach (0 .. $#input) { say "Record $_ is: $input[$_]"; }
    Here is the sample Data
    Page 1 of 1 Account Account_Number Beginning_Value GENERAL 111-111111 $88,0853.95 Page 1 of 3 Account Account_Number Beginning Value PERSONAL 222-222222 $88,0853.95 Page 2 of 3 Account Account_Number Beginning Value Educational 222-222222 Page 3 of 3 Account Account Number Beginning Value Educational 222-222222

Add your question
Title:
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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (10)
    As of 2018-11-16 13:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My code is most likely broken because:
















      Results (195 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!