http://www.perlmonks.org?node_id=479

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
Regexp issue
2 direct replies — Read more / Contribute
by QuasarD
on Feb 21, 2018 at 05:55
    Hi, i have some issues with a regular expression:
    use strict; use warnings; my $string1 = '"18/02/2018"'; print $string1 . "\n" if ($string1 =~ m/^"{1}[^"{1}]/); my $string2 = '"28/02/2018"'; print $string2 . "\n" if ($string2 =~ m/^"{1}[^"{1}]/); exit;
    The scalar string1 doesn't match...but why??
Replace a patern_2 in 30 lines from the line with the patern_1 founded
1 direct reply — Read more / Contribute
by thao4
on Feb 21, 2018 at 05:05

    Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the new patern "Model Regle" by "Heath Rule A" in this new line (30 lines after the line with patern "CADRE 1.1 CPU" Could you help me, please, thank you very much exemple of the text

sns sender id
1 direct reply — Read more / Contribute
by bigup401
on Feb 21, 2018 at 05:05

    does anyone has good documentation of this coz cant find it anywhere

    how to add sender id coz sns has that funcation of sender id

    this is like sending using default sender id of sns

    use Paws; my $paws = Paws->service('SNS'); $paws->Publish( Message => "test", PhoneNumber => "+1XXXXXXXXXX", );
Opening bad Excel files
4 direct replies — Read more / Contribute
by Arik123
on Feb 21, 2018 at 02:30

    I have an excel file which I need to extract data from. When I open it (with Spreadsheet::XLSX) it reports an empty file - no worksheets. This is not correct. Opening it with Excel itself shows that there is data.

    The problem might be that the file wasn't created by Excel itself - it may have been created by another program, which pretends to create 100% compatible Excel files.

    Is there any way to convert such files to valid Excel files, or is there another Perl module that can open and process them? I need a permanent solution, to process many such files automatically.

    The file can be found here: https://ufile.io/f06gn

    Thank you very much!

Original name of a PAR-Packed shared object file?
1 direct reply — Read more / Contribute
by ek15
on Feb 20, 2018 at 16:30

    Hi all,

    I am seeing the below error when trying to run an executable that I packed with PAR Packer (pp). How can I find out the original name of the shared object file b1934410.so? I'm trying to get more clues as to why this error is coming up. Thanks.

    [root@ektest1 DarkEther-v1.15.3]# ./switchscan local/mlnx cfgfile=192. +168.20.141.cfg 192.168.20.141 Can't find 'boot_IO' symbol in /tmp/par-726f6f74/cache-b7a72e3a0413c42 +480d6dae1f533764a0bf93415/b1934410.so at /usr/local/share/perl5/PAR/Heavy.pm line 78. Compilation failed in require at /usr/lib64/perl5/IO/Handle.pm line 26 +6. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/Handle.pm lin +e 266. Compilation failed in require at /usr/lib64/perl5/IO/Seekable.pm line +101. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/Seekable.pm l +ine 101. Compilation failed in require at /usr/lib64/perl5/IO/File.pm line 133. BEGIN failed--compilation aborted at /usr/lib64/perl5/IO/File.pm line +133. Compilation failed in require at -e line 138.
Regex match multiple line output
4 direct replies — Read more / Contribute
by bartrad
on Feb 20, 2018 at 10:32

    Hopefully a relatively simple one for somebody, but I've been staring at it too long it's all now a blur. I have the following output generated and it's either:

    Output1

    ====================================================================== +======== LDP Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- ---------------------------------------------------------------------- +-------- No Matching Entries Found ====================================================================== +========

    OR

    Output 2

    ====================================================================== +======== LDP IPv4 Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- 1.1.1.1:0 Targeted Established 822443 822431 273d 15:02:2 +0 ---------------------------------------------------------------------- +-------- No. of IPv4 Sessions: 1 ====================================================================== +========

    I'm trying to match using the following code to trigger an IF statement. Basically I'm looking for if the output contains an IP address then stop, otherwise keep going. But, it seems my IF statement returns true even if nothing that looks like an IP address is returned. I've been on regex101 to test my matching and it checks out there, but must be something obvious!

    if ( $output1 || $output2 =~ m/\d+\.\d+/gm ) { print "Found something"; exit; } else { print "Do this instead";
Grouped Regular Expression not set assign default value
4 direct replies — Read more / Contribute
by gbwien
on Feb 20, 2018 at 09:26

    Hi Monks, I am learning to write code to parse text files using grouped regular expressions. For the following section of code I am trying to find a way to determine if the entire group $1 is found in the input file. If it is I write group $2 to line. I am interested in modifying the code below to write MSISDN=notSet to $line if the entire line group $1 is not set in the code extract below? Thank your for your help

    pseudo code check line for tabMSISDN=digits; if found extract digits and assign to line otherwise assign MSISDN=notSet to the line for printing later

    Section of code

    if (/^(\t*MSISDN=(\d+));/) { print OUTFILE "Update Command $line\n" if defined $line; $line = "<$2>"; #group 2 #otherwise assign MSISDN=notSet to the line for printing later }

    full program below

    #!/usr/bin/perl use strict; use warnings; my $HSSIN='D:\testproject\sample-input.txt'; my $ofile = 'D:\testproject\sample-output.txt'; my $add; open (INFILE, $HSSIN) or die "Cant open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my $line; while (<INFILE>) { if (/^(\t*MSISDN=(\d+));/) { print OUTFILE "Update Command $line\n" if defined $line; $line = "<$2>"; #group 2 } if (/(\t*ODBIC=([\w]+?\w.*));/) { #print OUTFILE "$line\n" if defined $line; #$line = $2; $add = $2; $line .= ",$add"; } if (/(\t*ODBOC=([\w]+?\w.*));/) { $add = $2; $line .= ",$add"; } } print OUTFILE "Update Command $line\n"; close INFILE; close OUTFILE;

    input file may contain multiple entries

    <SUBBEGIN MSISDN=123476789678; ODBIC=BIC; ODBOC=BAOC; <SUBEND <SUBBEGIN ODBIC=BIC; ODBOC=BAOC; <SUBEND
    desired output Update Command <123476789678>,BIC,BAOC Update Command MSISDN=notSet,BIC, BAOC
timer in perl
7 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 20, 2018 at 05:53
    my $duration = 1000000; # in seconds my $wait = $duration; while ($wait >= 0) { $cmd1; $cmd2; $cmd3; $wait = $duration-time;#Decrement the time till it executed $cmd3 wi +th $duration }

    In the above code, i want to execute the while loop for $duration seconds. Once it reaches $duration while should break. Sleep won't help here , neither the time . Is there a way to acheive this

Counting PDL vectors in a PDL matrix
3 direct replies — Read more / Contribute
by mxb
on Feb 20, 2018 at 04:19

    Hi all, I am currently learning PDL and I've come up against a situation for which I cannot figure out how to proceed. I have a 2D array, comprised of multiple 1D byte vectors which may or may not be unique. I wish to count the number of unique vectors within the array - essentially a histogram of vector counts. My data is too big for here, but the following example demonstrates the issue I am having.

    pdl> p $x [ [0 1 2] [3 4 5] [6 7 8] [0 1 2] [0 1 2] [6 7 8] ]

    I know I can retrieve a list of unique elements:

    pdl> p uniq $x [0 1 2 3 4 5 6 7 8]

    I know I can retrieve a histogram of all elements:

    pdl> p scalar hist $x,0,256,1 [3 3 3 1 1 1 2 2 2 0 0 0 0 0 ....]

    What I would like is something like the following output:

    [0 1 2] 3 [3 4 5] 1 [6 7 8] 2
    I think my issue stems from the fact that PDL is designed for operations on PDL elements. I am currently contemplating if the best solution to my problem is to have a lookup table of the data I am putting in vectors to an index, for example:
    my %lookup = ( 0 => "0 1 2", 1 => "3 4 5", 2 => "6 7 8", ); # Then $x reduces down to $x = [ 0 1 2 0 0 2 ];

    Any advice would be welcome, as both PDL and numerical computing are new to me, thanks!

parse string into multidimensional hash
2 direct replies — Read more / Contribute
by chickenman
on Feb 20, 2018 at 02:58
    Hi there,
    i need your help. I am trying to parse the following output.

    Configuration - DGCONF Protection Mode: MaxAvailability Databases: DB1 - Primary database DB2 - Physical standby database Properties: FastStartFailoverThreshold = '30' OperationTimeout = '30' FastStartFailoverLagLimit = '30' CommunicationTimeout = '180' ObserverReconnect = '0' FastStartFailoverAutoReinstate = 'TRUE' FastStartFailoverPmyShutdown = 'TRUE' BystandersFollowRoleChange = 'ALL' ObserverOverride = 'FALSE' ExternalDestination1 = '' ExternalDestination2 = '' PrimaryLostWriteAction = 'CONTINUE' Fast-Start Failover: DISABLED Configuration Status: SUCCESS
    As a result i need a hash like this
    $VAR2 = { 'Configuration' => 'DGCONF', 'ProtectionMode' => 'MaxAvailability', 'Databases' => { 'DB1' => 'Primarydatabase', 'DB2' => 'Physicalstandbydatabase' }, 'Properties' => { 'ExternalDestination2' => '', 'FastStartFailoverThreshold' => '30', 'ObserverReconnect' => '0', 'ObserverOverride' => 'FALSE', 'OperationTimeout' => '30', 'PrimaryLostWriteAction' => 'CONTINUE', 'FastStartFailoverAutoReinstate' => 'TRUE', 'BystandersFollowRoleChange' => 'ALL', 'FastStartFailoverPmyShutdown' => 'TRUE', 'ExternalDestination1' => '', 'FastStartFailoverLagLimit' => '30', 'CommunicationTimeout' => '180' }, 'ConfigurationStatus' => 'SUCCESS' };
    Please help!

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.