Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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
Forcing DBIx::Class::AuditLog to install to the System perl's path
No replies — Read more | Post response
by davis
on Aug 03, 2015 at 05:10

    Been a while...

    I'm trying to install DBIx::Class::AuditLog. I want it to be available system-wide, so I'm using CPAN or cpanm as root on my CentOS 7 box to install it. Other modules installed system-wide, as expected, but D:C:AL (and it alone) seems to go to root's home directory, and I'm not sure why: Here's what I tried:

    cpan[7]> install DBIx::Class::AuditLog Running install for module 'DBIx::Class::AuditLog' Running make for I/IO/IONCACHE/DBIx-Class-AuditLog-0.6.2.tar.gz Fetching with LWP: +.6.2.tar.gz Fetching with LWP: Checksum for /root/.cpan/sources/authors/id/I/IO/IONCACHE/DBIx-Class-A +uditLog-0.6.2.tar.gz ok Scanning cache /root/.cpan/build for sizes DONE Building I/IO/IONCACHE/DBIx-Class-AuditLog-0.6.2.tar.gz Created MYMETA.yml and MYMETA.json Creating new 'Build' script for 'DBIx-Class-AuditLog' version '0.6.2' Building DBIx-Class-AuditLog IONCACHE/DBIx-Class-AuditLog-0.6.2.tar.gz ./Build -- OK Running Build test t/001_deploy.t ....................... ok t/002_cud.t .......................... ok t/003_get_changes.t .................. ok t/004_force_auditlog.t ............... ok t/005_modify_audit_value.t ........... ok t/006_resultsets-default_rs_class.t .. ok t/007_resultset-loadcomponent.t ...... ok t/008_relationships.t ................ ok t/009_recursive-update.t ............. ok t/010_bug_undef_columns_logged.t ..... ok t/011_update_on_deleted_row.t ........ ok t/012_cud_view.t ..................... ok t/release-pod-syntax.t ............... skipped: these tests are for re +lease candidate testing All tests successful. Files=13, Tests=76, 12 wallclock secs ( 0.09 usr 0.02 sys + 9.94 cus +r 0.73 csys = 10.78 CPU) Result: PASS IONCACHE/DBIx-Class-AuditLog-0.6.2.tar.gz ./Build test -- OK Running Build install Building DBIx-Class-AuditLog Installing /root/perl5/lib/perl5/DBIx/Class/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure. +pm Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/Schema/AuditLog/Structure/ Installing /root/perl5/lib/perl5/DBIx/Class/ResultSet/ Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::View.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::User.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::Action.3pm Installing /root/perl5/man/man3/DBIx::Class::ResultSet::AuditLog.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::Change.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::Base.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::AuditedTable.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::Field.3pm Installing /root/perl5/man/man3/DBIx::Class::Schema::AuditLog::Structu +re::Changeset.3pm Installing /root/perl5/man/man3/DBIx::Class::AuditLog.3pm IONCACHE/DBIx-Class-AuditLog-0.6.2.tar.gz ./Build install -- OK

    Can I simply move the files out of ~/perl5 into /usr/local/share/perl5/ (where other modules have happily installed)? I've completely blown away .cpan and tried again, and tried cpanm, so this problem seems specific to the module. Any ideas?


Win32::GUI won't display an NI menu properly
No replies — Read more | Post response
by wardmw
on Aug 03, 2015 at 04:59
    Greetings honoured friars,

    I have a program that creates an icon in the system tray of Windows 7 and displays a tool-top when the mouse is hovered over it.

    The issue comes when the user right-clicks the icon, it should display a menu but instead I get a thin sliver of a window, like a menu but with no text (the word "File" in this case). Something is there as if I click where "File" should be I get a sub-menu, no problem, I just cannot see the word "File".

    I have worked through the articles elsewhere on Perlmonks but to no avail, even the "" code has this same problem, at least on my machine anyway.

    The following code shows this exact problem, feel free to change the icon path to any .ICO file you have spare, or leave it blank and right-click in the blank space that will appear in your system tray.

    # A simple Perl program to show the fly-out menu problem.
    # Uses and requires
    use strict;
    use Win32::GUI();
    my $win_main;	# Pointer to the main window.
    my $menu_popup;	# Pointer to the menu that should appear.
    my $icn;		# Ptr to an icon.
    my $debug = 1;	# Debug flag
    # Windows event handlers go here.
    sub Main_Terminate {
    sub NI_RightClick() {
    	print "NI_RightClick event called.\n" if ($debug);
    		$win_main->TrackPopupMenu($menu_popup, Win32::GUI::GetCursorPos());
    # Main program start
    # First, build everything
    # Create the context menu to be displayed when the icon is right-clicked
     # Translate the menu
    $menu_popup = Win32::GUI::Menu->new(
    "&File"     =>            "File",
    	">E&xit"           => { -name => "File_Exit",  -onClick => sub{-1} },
    #  Create the main window - this will not be displayed.
    $win_main = Win32::GUI::Window->new(
    	-name	=> 'Main',
    	-menu	=> $menu_popup,
    	-width	=> 1,
    	-height	=> 1,
    	-text	=> '',
    # Create an icon that will appear in the system tray. Pick any icon you want.
    $icn = new Win32::GUI::Icon("c:/Windows/System32/PerfCenterCpl.ico");
    # Add the icon to the window.
    	-name		=> 'NI',
    	-icon            => $icn,
    	-tip             => 'Thi is a notify fly-out/tool-tip thing.',
    	-balloon         => 0,
    # Enter the Windows message loop
    I would appreciate your thoughts on this, or even a simple test to see if this code works on your system (in which case it is environmental, but I still have no clue as to what it might be!)


absolute beginner in perl
3 direct replies — Read more / Contribute
by kviki_kiki
on Aug 03, 2015 at 02:22

    Hi guys!

    I am not a programmer, but here and there I have to do some programming in HTML. My next task is to do some modifications in a perl script which generates a HTML code. I have a problem starting with programing, because I have no idea how to make the script run and let me see the resulting HTML script

    I am working in Windows and have instaled Padre, but when I run the script it does not produce anything. I know it is a working script because it is already in use on a server.

    Thanks in advance!

How to extract Name and No from .vcf file.
5 direct replies — Read more / Contribute
by shankonit
on Aug 03, 2015 at 00:22

    When i tried to extract name and number and print in a file then they are being repeated. I tried with and if condition to prevent the repeating with an regex at the start but not successful.

    Like Naresh -> 8890328840
    Naresh -> 8890328840
    Naresh -> 8890328840
    Naresh -> 8890328840
    Naresh -> 8890328840

    file.vsf structure is:


    Code i tried is:

    use strict; use warnings; my $filename = $ARGV[0]; my ($name, $number); open my $fh, "<", "$filename" or die "$!"; open my $fh2, ">", "list.txt" or die "$!"; while(my $line = <$fh>) { if( /!^\s*FN/ || /!^\s*TEL/ ) { next ; } elsif( $line =~ /^\s*FN:(\w+\s*\w*)\b/ ) { $name = $1; } elsif( $line =~ /^\s*TEL;TYPE=CELL;TYPE=PREF:([+|(?:91)]?\d{10})\b +/ ) { $number = $1; } printf $fh2 "%15s -> %d\n", $name, $number ; } close $fh2 or die "$!"; close $fh or die "$!";

    I appreciate your time taken to read and answer. Thank u in advance.:)

Moo From Hell #1: How to proxy a sub from a non OO module [SOLVED]
2 direct replies — Read more / Contribute
by karlgoethebier
on Aug 02, 2015 at 11:07

    Hi all,

    here is what did:

    The role:

    package Utils; use URI; use List::MoreUtils qw(uniq); use Types::Standard qw(InstanceOf); use Moo::Role; requires qw(list monks); sub my_uniq { my $self = shift; my @result = uniq @{ $self->list }; wantarray ? @result : scalar @result; } has 'uri' => ( is => 'lazy', isa => InstanceOf ['URI'], default => sub { my $self = shift; URI->new( $self->monks ) }, handles => [qw(host)], ); 1; __END__

    The class:

    package Karl; use Types::Standard qw(ArrayRef Str); use Moo; has list => ( is => 'lazy', isa => ArrayRef ); has monks => ( is => 'lazy', isa => Str ); with qw(Utils); 1; __END__

    And the script:

    #!/usr/bin/env perl use strict; use warnings; use feature qw(say); use Data::Dump; use Karl; my $monks = qq(; my $list = [qw(cuke cuke)]; my $nose = Karl->new( list => $list, monks => $monks ); dd $nose; my $uniq = $nose->my_uniq; say $uniq; my @uniq = $nose->my_uniq; say for @uniq; say $nose->host; __END__

    This works as expected and i hope that it is good practice. OK, i'm a bit unsure about this :-(

    But i wonder how to handle the call to uniq like the call to host.

    I would like to say $nose->uniq, instead of $nose->my_uniq.

    In other words: how can i proxy (or delegate) a sub from a non OO module?

    I must admit that i'm a bit confused for the moment.

    Best regards and thank you very much for any hint, Karl

    «The Crux of the Biscuit is the Apostrophe»

Table in Perl CGI
5 direct replies — Read more / Contribute
by alokranjan
on Aug 02, 2015 at 04:53
    Hi All,

    Can anyone please let me know how can I print the values of hash in tabular form in Pel CGI?

    Below is my code, which is not showing the table:

    print $cgi->header(), $cgi->start_html("Fruits and colors"), $cgi->table({-border=>1}, $cgi->Tr($cgi->th([" Fruit"," Color"])), for my $f (keys %tbl){ map { $cgi->Tr($cgi->td([$f,$tbl{$f}])) } sort keys %tbl } ), $cgi->end_html();
    Any help/assistance would be highly appreciated.



plotting roc curve using roc package
4 direct replies — Read more / Contribute
by numita
on Aug 02, 2015 at 02:56

    hello everyone,I tried to write a code for roc curve using perl module statistic:roc, but when i run the program it gives the error value out of range for table lookup (2):0.711752437,1 at line 16.

    use Statistics::ROC; open(fh,"<roc_tp_fp.txt"); while ( <fh> ) { ($a,$b)=split/,/; push @AoA, [ split ]; } for $aref ( @AoA ) { #print "[ @$aref ],"; } @curves=roc('decrease',0.95,@AoA); print "$curves[0][2][0] $curves[0][2][1] \n";

    input_file:roc_tp_fp.txt looks like as follows: 0.9883817,1 0.770431568,1 0.983195895,1 0.812109932,1 0.901505931,1 0.72431528,1 0.73553418,1 0.724572657,1

regex help
6 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 02, 2015 at 01:03
    I have a text below and along with this there is some more text which is p tags, br tags. Please help me to remove entire sentence if contains 23456.
    <p>Find more business news at and Text BUSIN +ESS to 23456 for breaking business news text alerts on your mobile ph +one. Text JOBS to 23456 for job alerts.</p> <p>Want your news even faster? Text NEWS to 23456 to sign up for break +ing news text alerts. See for a complete list of alerts.</p> <br>SIGN UP FOR MOBILE NEWS ALERTS! Get your news on the go, text NEWS + to 23456
Help fixing this piece of code
4 direct replies — Read more / Contribute
by perlynewby
on Aug 01, 2015 at 17:28

    Hello Monks, I am interested in finding out how to get this specific subroutine to work.

    I have worked it out using other method but very interested in finding the method to this specific hash format below since I couldn't find the solution myself

    Since I couldn't fix it myself and still interested to see to see how you guys do it

    sub routine must find the MODE in a given set of numbers. must find the most duplicated number and pass the value.

    data 2 3 3 3 5 7 8 12 32 44 55 12 3 23 43 33 1 4 25 43 42 1 4 5 3 3 3
    sub mode_num{ my %count=(); %opt = %{shift @_ } ; #creating hash #dump \%opt; #check data coming in.. #need to get integrate count as I format data into hash(next task + to make it reable) for (sort{$a <=> $b} %opt{NUMBERS}){ #dump \$opt{NUMBERS}++; $opt{NUMBERS}++; } our @keys= sort{$opt{NUMBERS}->{$b}<=>$opt{NUMBERS}->{$a}} key +s %opt{NUMBERS}; return }
Why am I getting message «Operation "<=>": no method found,» ?
4 direct replies — Read more / Contribute
by RCH
on Aug 01, 2015 at 10:44

    Dear Perl Monks

    I'm getting the message

    Operation "<=>": no method found, left argument in overloaded package Class::Measure::Length, right argument in overloaded package Class::Measure::Length

    from what I thought was just a simple sort


    I found a work-around, by sprintf-ing the values in the hash - see code below - but I would like to (try to) understand what is going on.

    I'm on Ubuntu 12.04

    perl -v says

    This is perl 5, version 14, subversion 2 (v5.14.2) built for i686-linux-gnu-thread-multi-64int
    The following script gives the no method found message the second time round
    use strict; use Carp; use GIS::Distance; my $from_lat = 50.815717; my $from_long = 4.436326; my $to = { Montana => [ 46.536026, -111.935062 ], Correze => [ 45.341874, 1.79531 ], ParisFR => [ 48.850407, 2.347304 ], }; my %distance; foreach my $demo ( 'solution', 'problem' ) { print STDOUT "\n", "-" x 60, "\n\n"; print STDOUT "This is to demonstrate the $demo ...\n"; print STDOUT " Here comes the contents of the hash \%distance\n"; print STDOUT " (distances as calculated by GIS::Distance\n"; if ( $demo eq 'problem' ) { print STDOUT " and stored as that value)\n"; } elsif ( $demo eq 'solution' ) { print STDOUT " and stored as sprintf \"%25.15f\", value )\n"; } foreach my $place ( keys(%$to) ) { my $gis = GIS::Distance->new(); my $to_lat = $to->{$place}->[0]; my $to_long = $to->{$place}->[1]; my $km = $gis->distance( $from_lat, $from_long => $to_lat, $to_long, ); if ( $demo eq 'problem' ) { $distance{$place} = $km; } elsif ( $demo eq 'solution' ) { $distance{$place} = sprintf "%25.15f", $km; } print STDOUT " \$distance{$place} = $distance{$place}\n"; } print STDOUT "\n"; print STDOUT "And here comes the result of sorting the keys of that hash\n"; foreach my $place(sort {$distance{$b} <=> $distance{$a}}( keys(%distance))) { printf STDOUT "%10s is %25.15f km from here\n", $place, $distance{$place}; } }

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.
  • 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 contemplating the Monastery: (10)
    As of 2015-08-03 09:18 GMT
    Find Nodes?
      Voting Booth?

      The oldest computer book still on my shelves (or on my digital media) is ...

      Results (28 votes), past polls