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
"Type mismatch" Error While Using Win32:OLE for MS Outlook
No replies — Read more | Post response
by dushyant
on Jul 03, 2015 at 03:30

    Hi Monks,

    I am tring to download email attachments from Microsoft Outlook using Win32::OLE. But I stuck at initial level I don't even able to get outlook folder list.
    Please find below code I am using and Error I got.

    I am using,
    32 bit Straberry Perl ( perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int),
    OS (64 bit) = Windows 7 Enterprise Service Pack 1
    Microsoft Outlook 2013

    Error :

    Win32::OLE(0.1712) error 0x80020005: "Type mismatch" in METHOD/PROPERTYGET "GetDefaultFolder" argument 1 at D:\Perl_Project\OutLook\test1.pl line 9.
    Can't call method "Folders" on an undefined value at D:\Perl_Project\OutLook\test1.pl line 15.
    D:\Perl_Project\OutLook>perl -v

    #! D:\Straberry\perl\bin\perl -w use strict; use Win32::OLE qw/in/; #use Win32::OLE::Const 'Outlook.Application'; #use Win32::OLE::Variant; my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32:: +OLE->new('Outlook.Application') or die "$!\n";; my $NameSpace = $OL->GetNameSpace("MAPI"); my $Folder = $NameSpace->GetDefaultFolder("olFolderInbox"); #print ref($Folder->{Items}) . "\n"; foreach my $subfolder ( in $Folder->Folders) { printf "%s\n", $subfolder->{Name}; }

Perl expect : send command executing multiple times
No replies — Read more | Post response
by ryalagikar
on Jul 03, 2015 at 03:11

    I am writing perl-expect script, in script am trying to login to remote machine then sudo su to another user and then execute two commands. Everything is working fine but the first command is executing multiple times.

    my $ssh = Net::OpenSSH->new("$user:password\@$host"); $ssh->error and die "Unable to connect $host " . $ssh->error; my ($pty,$pid) = $ssh->open2pty({stderr_to_stdout => 1}, 'sudo su - us +er1') or die "Failed to attempt"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); my $result = $expect->expect(3, ["\[\r\n]?\[^\r\n]+\[%#>\$] \$" ,sub { shift->send("da +te\r"); exp_continue;}], [qr/Day/ , sub { my $self = shift; $self->send("touch +test.txt\r"); $self->soft_close();}] )or die "**** Failed ** ";

    Here 'date' command is executing multiple times(2...20times).

    Suggestions Please

missing values when using Parallel::ForkManager
No replies — Read more | Post response
by plagent
on Jul 03, 2015 at 01:51
    I used Parallel::ForkManager to scan the motifs in DNA string pairs. The script is the following:
    foreach my $id (1..100) { PWM: for my $pwm (@ciona_pwm_array) { $pm->start and next PWM; ($count) = count_pwm_num($pwm,$seq_1,$seq_2); $pm->finish; } $pm->wait_all_children; }
    There are three parameters for the function count_pwm_num. The first one is $pwm, which is from list @ciona_pwm_array and is the motif feature. The second and third are DNA strings. The function is to calculate the motif number (how many?)using motif feature $pwm in the DNA strings. The aim of the function count_pwm_num is to report the motif number from both strings. The following table is the report from the program. However, I calculated the same DNA strings 100 times ( the first for-loop) and used same motif list (@ciona_pwm_array, the second for-loop), there is always missed motif(s) in the report. For example, row a (first row), the program reported all six motif number from A-F. row b missed the number of the motif A (because they were same DNA strings, the output should keep the same). row c missed the number of motif B.row d missed the number for motif A and B. It seemed the missed motif numbers were randomly selected. So my question is: why count_pwm_num randomly skip some $pwm and do not perform the function of count_pwm_num?

    program result table:

    id	A	B	C	D	E	F
    a	1	1	0	1	1	0
    b		1	0	1	1	0
    c	1		0	1	1	0
    d			0	1	1	0
    e	1	1	0	1	1	0
    Expected result
    id	A	B	C	D	E	F
    a	1	1	0	1	1	0
    b	1	1	0	1	1	0
    c	1	1	0	1	1	0
    d	1	1	0	1	1	0
    e	1	1	0	1	1	0
Aggregating the column based on the common column values
1 direct reply — Read more / Contribute
by kanskr
on Jul 03, 2015 at 00:08

    My data is like below

    Username | Roles | Type |date |SR NO|Remarks| abc|admin |added | 01072015 abc|developer |deleted |01072015 abc|deploy |added |01072015 xyz |admin |deleted |01072015 xyz| deploy|deleted|01072015 cdf|deploy|added|01072015

    and i need to do the following a) i need to group based on the user, roles and concatenate the roles filed with the delimiter "," b) I need to create the output as below.

    Username |roles added |roles deleted |date username |roles_added |roles deleted |date abc |admin,deploy |developer |01072015 xyz ||admin,deploy |01072015 cdf |deploy||01072015

    In order to achieve this,am using the code below

    use strict; use warnings; use diagnostics; use Data::Dumper; open(FIL,"report.txt") or die("$!"); my %k=(); while (my $line=<FIL>) { next if $. < 2; my ($user,$roles,$type,$dt,$empty1,$empty2)=split(/\|/,$line); push @{$k{$user}{$type}}, $roles; } my @names=(sort keys(%k)); foreach ( @names) { if ( @{$k{$_}{Added}} ne ''){ print "${k{user}}\n"; print join ',', @{$k{$_}{Added}}; print "\n"; } if ( @{$k{$_}{Deleted}} ne '') { print join ',', @{$k{$_}{Deleted}}; print "\n"; } }

    The script fails with below error Can't use an undefined value as an ARRAY reference at report3.pl line 34, <FIL> line 23. at report3.pl line 34 Please help me how i can generate the output as expected. Many thanks

[SOLVED] Ordering DBIx::Class joined searches by timestamp
No replies — Read more | Post response
by LunarCowgirl
on Jul 02, 2015 at 22:59

    Is it not possible to order joined searches by timestamp with DBIx::Class? I have a SQLite table with created and updated columns that are of the type timestamp. I have a search:

    sub get_latest_by_category { my ( $self, $id, $rows ) = @_; return $self->search( { 'category.id' => $id, 'me.published' => 1, }, { join => { 'artist_categories' => 'category' }, order_by => { -desc => 'me.created' }, rows => $rows, } ); }

    It returns the data sorted by the name column in ascending order, which is the first column after the primary key, rather than by the created column in descending order. I can order by created in non-joined searches, and if I change me.created to another column in the above search, it'll return the results in the correct sort order and direction. It just won't do it with a joined search ordered by a timestamp column.

    A DBIC_TRACE shows that it's reading the query correctly "ORDER BY me.created DESC". Is there something special about this type of search? Or if this is a limitation, is there an easy way around it?

    UPDATE: Ah, never mind. I discovered where the error was. It was a problem with the test database.
Max of 23 and 27 is 23?
6 direct replies — Read more / Contribute
by luxgladius
on Jul 02, 2015 at 13:35
    Here's the output of an actual debug session. Can anybody explain this?
    DB<10> p $#l 27 DB<11> p $#F 23 DB<12> p max($#l, $#F) 23 DB<13> p max(27,23) 27 DB<14> p 0+$#l 27 DB<15> p max(0+$#l, $#F) 27 DB<16> p max($#l, 0+$#F) 23
    So the second-to-last line tells me the solution, but I have no clue what the actual problem is. For what it's worth, I'm using 64-bit Activestate Perl 5.20.

    Edit: The max is from List::Util.

Hang on STDOUT
2 direct replies — Read more / Contribute
by DanEllison
on Jul 02, 2015 at 08:55

    I'm using Strawberry Perl in a Windows 8 environment. I have a scheduler I have written in Perl that I have been using for a couple of years. Its a threaded application that runs more than 1500 jobs every night, so its doing a lot of the same thing over and over.

    The main engine spawns worker threads to run the individual jobs and reports some progress to STDOUT. I have had issues in the past where STDOUT would somehow get corrupted and the engine would stop reporting progress but continue to run and I would eventually find my progress messages in one of the job log files.

    I haven't seen that issue in a while, but lately I find the engine has simply hung. It writes messages to both STDOUT and to a log file, and I've been adding debugging left and right, and it simply appears to be hanging on prints to STDOUT.

    Autoflush is on and I can see single character updates, but here's an example:

    sub message { if ($options{verbose} && $options{verbose} >= ($_[1] || 0)) { if ($inprogress) { print "\n"; $inprogress = 0; } print "<"; my @time = localtime; print ">"; printf "%04d-%02d-%02d %02d:%02d:%02d %s\n", $time[5] + 1900, $time[4] + 1, $time[3], $time[2], $time[1], $time[0], $_[0]; } }
    $_[0] is the message I want to print. I thought maybe I was hanging trying to get the local time, but no. I put the < and > prints on either side of the localtime, but it hung between the > and the printf of the message.

    Has anyone had experience with this?

Using DBI to make connection to a database
5 direct replies — Read more / Contribute
by campbell
on Jul 02, 2015 at 08:22

    Greetings O enlightened ones

    I have a problem with opening a handle to a database using the DBI Perl module, since, alas, I am a total DBI noob. I would figure it out myself, but I'm in a hurry...

    I am using Strawberry Perl version 5.22 and Windows 7.

    With the help of Windows' ODBC Data Source Administrator, I have configured a system DSN (named $myDSN), using the windows native ODBC driver (Version 06.01.7601) that connects to a MS-SQL database (named $db) on a remote server (named $srvr) on port $port with username $usr and password $pwd. I have tested the connectivity using the ODBC administrator, and it is fine.

    The question is, how do I then get the DBI Perl module to use this information to set up a filehandle so that I can query / retrieve on the database?

    I've tried to follow the syntax given in CPAN and (perhaps naively) tried the following:

    my $dbh=DBI->connect("dbi:ODBC:Server=$srvr; UID=$usr;PWD=$pwd");
    $DSN= 'dbi:DriverName:database=$db;host=$host;port=$port;' my $dbh=DBI->connect($DSN);

    ...which just results in various error messages to the effect that a connection isn't happening.

    These error messages are, respectively:

    DBI connect('variansystem; Server=10.1 75.68.28; UID='reports';PWD='reports'','',...) failed: [Microsoft][ODB +C Driver M anager] Data source name not found and no default driver specified (SQ +L-IM002) a t C:/Users/rpuser/Documents/RTDS/RTDS_include.pl line 232.
    install_driver(DriverName) failed: Can 't locate DBD/DriverName.pm in @INC (you may need to install the DBD:: +DriverName module) (@INC contains: C:/Strawberry/perl/site/lib C:/Strawberry/per +l/vendor/l ib C:/Strawberry/perl/lib .) at (eval 16) line 3.

    I'm obviously using the completely wrong syntax / approach (maybe I need to set enviroment variables or something?), but I haven't got the time to figure it out myself (which would obviously be more satisfying).

    Thanks in advance.

Win32::GUI - need a window within a window
1 direct reply — Read more / Contribute
by levW
on Jul 02, 2015 at 07:41
    HI, With Win32::GUI - need to create a window with scroll bar , within a main window. This second window (child of a main window) will hold different buttons/checkboxes ,etc , and will have a scroll bar . Did not find so far any package in win32::GUI that will enable me to achieve the above. Help appreciated. thanks
Perl Variable Help.
6 direct replies — Read more / Contribute
by arvindmarlabs
on Jul 02, 2015 at 05:19
    Need a urgent help. I am new in perl. My sample script below.
    my $date = `date +%Y%m%d`; my $tar = '.tar'; my $gz = '.gz'; my $dbfile = bugs_db_.$date.$gz."\n"; my $webfile = bugzilla_.$date.$tar.$gz."\n"; print $dbfile; print $webfile; exit;
    I am execting this script but i am getting result like
    bugs_db_20150702 .gz bugzilla_20150702 .tar.gz
    I need a output like
    bugs_db_20150702.gz bugzilla_20150702.tar.gz
    in one line. Please help me guys as soon as possible.

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!
  • 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.