Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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
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:

    BEGIN:VCARD
    VERSION:3.0
    N:;Naresh;;;
    FN:Naresh
    TEL;TYPE=CELL;TYPE=PREF:+917734807608
    END:VCARD

    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]
1 direct reply — 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(http://www.perlmonks.org); 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.

    Thanks

    Alok

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 facebook.com and twitter.com. 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

    $hash{$b}<=>$hash{$a}

    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}; } }
Trying dirty trick with Imager and Inline C, but having difficulties. Can you help?
1 direct reply — Read more / Contribute
by vr
on Aug 01, 2015 at 04:00

    At some point in my program, it seems that easiest (fastest, etc.) thing to do is to directly replace raw image data with data from Perl scalar. Needless to say, Imager API (both Perl and C) don't provide for this, but I thought I'd get away with following subroutine (here it is with a test program that, of course, makes no sense):

    use strict; use warnings; use Imager; use Inline with => 'Imager'; use Inline C => << 'END_OF_C'; void _replace( Imager img, SV* str ) { unsigned char* ptr = SvPV_nolen( str ); myfree( img-> idata ); img-> idata = ptr; } END_OF_C my $i = Imager-> new( xsize => 99, ysize => 99 ); for ( 'A' .. 'F' ) { print "$_\n"; my $s; $i-> write( data => \$s, type => 'raw' ); my $j = $i-> copy(); # Here, it's rumored, some nasty things # happening, that involve $j and $s. # But maybe nothing happens. _replace( $i, $s ); } __END__ ~$ perl test.pl A B *** Error in `perl': double free or corruption (!prev): 0x0000000002d6 +7990 *** Aborted (core dumped)

    Unfortunately, my C is below-zero level. I understand I should prevent Perl from freeing memory that now is Imager responsibility, but don't know how. And, actually, replacement itself works OK. There's only error freeing memory, that happens just sometimes. This program seems to reproduce it always.

Difference between leftward and rightward list operators
2 direct replies — Read more / Contribute
by Firsov
on Aug 01, 2015 at 02:25

    Greetings!

    I was reading perlop manual. And i don't understand one thing: What difference between rightward and leftward list operators?

    I guess that leftward list operator this is function that accept LIST (has higher precedence that comma operator). But what is a right ward list operator and why it has low precedence?


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!
  • 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 browsing the Monastery: (5)
    As of 2015-08-03 08:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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













      Results (27 votes), past polls