Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
I want to build a Craigslist clone
1 direct reply — Read more / Contribute
by newbietocode
on Mar 25, 2019 at 20:50
    Hello everyone,

    I want to create a bare bones, text only site classifieds site which is global. My site will be a niche one, but built like Craigslist and I want it to be able to handle robust traffic. I have seen Craigslist clone software to buy on the internet but they are usually modernised copies built on php or ruby and not really what I want. They have too many gimmicks.

    I want to use perl to create my webste because thatís what Craigslist used (I understand it is built on perl and Mysql database). I will host it on a dedicated server.

    I have created websites in the past for myself but I used Frontpage 2003. I donít have a degree in computer science or anything like that, and my knowledge of computers is general (home, university, small business). But I am quick to learn.

    I am not a programmer, although I have bought a Perl book to start learning. In fact, I got this websiteís url from the book. My questions are:

    1.Are there any sections of code here for building a classified site like Craigslist?

    2.If not, is there a particular section I should start learning first? I am assuming Iíll have to build the database first, then code the html pages later?

    Thank you in advance.
IO::Socket recv and send
2 direct replies — Read more / Contribute
by milanpwc
on Mar 24, 2019 at 23:48
    When I call recv() or send() from IO::Socket, how can I determine if the remote end has crashed or the connection is broken (ie broken pipe)? When I check the return value, it always return a null string:
    while (defined $client_socket->recv($data, 1024)) { + ### always true even if the remote end has crashed print "received data: $data\n"; }
Rosetta Code Error or $n // 100
3 direct replies — Read more / Contribute
by pgmer6809
on Mar 24, 2019 at 15:58

    On Rosetta (https://rosettacode.org/wiki/Continued_fraction#Perl )

    there is the perl solution to evaluating Continuous fractions. The code given is: (<===== comments added by me)

    sub continued_fraction { my ($a, $b, $n) = (@_[0,1], $_[2] // 100); #<========= what is $_[2] // 100 ?? $a->() + ($n && $b->() / continued_fraction($a, $b, $n-1)); } printf "&#8730;2 &#8776; %.9f\n", continued_fraction do { my $n; sub +{ $n++ ? 2 : 1 } }, sub { 1 }; # <===== Note there is no third arg p +assed printf "e &#8776; %.9f\n", continued_fraction do { my $n; sub { $n++ + || 2 } }, do { my $n; sub { $n++ || 1 } }; # <===== Note there is no + third arg passed printf "&#960; &#8776; %.9f\n", continued_fraction do { my $n; sub { + $n++ ? 6 : 3 } }, do { my $n; sub { (2*$n++ + 1)**2 } }, 1_000; #<== +== Here there is a 3rd arg printf "&#960;/2 &#8776; %.9f\n", continued_fraction do { my $n; sub { + 1/($n++ || 1) } }, sub { 1 }, 1_000; #<==== Here there is a 3rd arg

    The output shown on Rosetta is correct

    .

    My TWO questions are:

    1) Why can they pass in two arguments sometimes (two function refs) and three arguments other times (two function refs, and an integer count?

    2) What value does the expression $_[2] // 100 assign to $n ?

Tk change pupup label
3 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 24, 2019 at 15:01

    Hello Monks

    Having the following popups in a TK application, is there a way to modify the Label of the pop-up buttons by clicking on my button "Change popup" without having to recreate my popup?

    use warnings; use strict; use Tk; my $mw = MainWindow->new; my $text = $mw->Text()->pack; add_edit_popup($mw, $text); my $but = $mw->Button( -text => "Change me", -command => \&push_button, ); $but->pack(); MainLoop; sub add_edit_popup { my ($mw, $obj) = @_; my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>"Move col to the right", -command=>[sub {MoveColumn( +'right')}, $obj,]], [command=>"Move col to the left", -command=>[sub {MoveColumn(' +left')}, $obj,]], ]); $obj->menu($menu); $obj->bind('<3>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]); return $obj; } sub push_button{ #change/configure #command=>"Move selected column to the right" #command=>"Move selected column to the left", }
Mojolicious::Plugin::OpenAPI strict or filter object representation
1 direct reply — Read more / Contribute
by Veltro
on Mar 24, 2019 at 11:33

    Dear monks,

    I am looking for a possibility to indicate that the schema definition must be 'exact' in the sense that if more parameters are specified I want the validation to 'fail' for the request, and 'fail' or 'filtered' for the response (hopefully by specifying this in the OpenAPI spec). I wonder if anyone knows if this can be done in swagger 2.0 (or newer versions)?

    As far as I understand now, swagger 2.0 allows you to tell that parameter are 'required' by defining the parameters like this (Just as an example a 'animal' object):

    # In a POST request: ... parameters: - in: body name: body schema: $ref: '#/definitions/animal' required: true ... # In a resonse: ... responses: 200: description: animal response schema: $ref: '#/definitions/animal' ... # and then create the animal definition: definitions: animal: description: animal properties: animalid: description: The animal ID type: integer animalname: description: The animal name type: string type: object required: [ 'animalid', 'animalname' ]

    However, there is nothing that stops anyone from sending an animal with many more parameters other than 'animalid' or 'animalname' or could even add completely unrelated data in the request. Similarly it also does not stop the back-end from creating an object containing many more parameters and send those to the client as well.

    What if I would send a 'user' object and I had accidentally created a database query resulting in an object containing the password as well (because let's say I was turning beer instead of coffee into code one night). I did not specify the password as a valid parameter in the spec, but it gets send anyhow! How could I potentially either block the entire response, or if desired, filter out the password and send the response with just those parameters that were specified in the spec?

    Another reason why this would be desired is to detect typos, In case a parameter is optional and e.g. called animalname, but is send as animalName, this is not detected. But when the definition would have been taken 'strict' then this typo would have been detected. The response error could say something like: animalName is not a valid parameter!

    I was digging through the entire OpenAPI spec, but have not been able to find anything. Has anyone found a solution for this?

    Thanks,

    Veltro

Can I use Mojo::IOLoop::Subprocess for a non-blocking process?
1 direct reply — Read more / Contribute
by talexb
on Mar 23, 2019 at 00:05

    I have a Mojolicious monitoring web app that's working well. I'd like to extend it to give it the ability to start scripts running.

    My code is something like this:

    use Mojolicious::Lite; use Mojo::IOLoop::Subprocess; ... post '/' => sub { ... my $message = 'INFO: Something useful'; my $cmd = 'cd /home/foo/bar && ./some-script.pl >some.out 2>some.e +rr'; my $subprocess = Mojo::IOLoop::Subprocess->new; $subprocess->run( sub { my $subprocess = shift; my $result = qx/$cmd/; return $result; }, sub { my ($subprocess, $err, @results) = @_; if ( $err ) { $message .= "ERROR: $err"; } else { $message = $results[0]; } } ); $subprocess->ioloop->start unless $subprocess->ioloop->is_running; ... $c->render(template => 'index'); };
    In the $cmd, I'm cd'ing into a directory and running a known script. The good news is that this works .. the script does actually run fine, and the output and error files are created correctly. What I'm not expecting is that the Mojolicious web app doesn't return immediately while the script runs; rather, it waits for the script to finish.

    The behaviour that I'd like is to see that the script started, with the web page refreshing a second or two later. At some point a couple of minutes later, the script will finish .. but I really don't care about the output.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

With substr, index the offset don't get proper start position
5 direct replies — Read more / Contribute
by Oskym
on Mar 21, 2019 at 06:26

    Hi PerlMonkeys!

    I'd made a simple script trying to get the final part from a line from the 4th space occurrence.

    The Output should be like this:

    "GetCertificate](3) Returning context. ID=PTWEBSERVER, Lang=ENG"

    Instead of that I'm getting this:

    "(6) 01/02/19 06:30:30 GetCertificate(3) Returning context. ID=PTWEBSERVER, Lang=ENG"

    Can I ask for help to any expert?

    Here is the code:

    use strict; use warnings; my $line='PSAPPSRV.26476584 (6) 01/02/19 06:30:30 GetCertificate(3) Re +turning context. ID=PTWEBSERVER, Lang=ENG'; my $SpaceChar = ' '; my $offset = 0; my $result = substr $line,index($line, $SpaceChar, $offset); while ($offset &lt; 4) { $result = substr $line,index($line, $SpaceChar, $offset); print "$result \n"; $offset++; print "offset: $offset \n"; }

    Thanks for your help!!

Reading and printing an XLSX file
2 direct replies — Read more / Contribute
by jsuresh
on Mar 21, 2019 at 03:03
    Hi Team, I'm trying to read an XLSX file and write it as XLSX file. I can read it but unable to print it as a new XLSX file. I have also used the required module XLSX::writer but still it is now allowing me to create a new xlsx file. I also need to to check for the values starting from 0.00 and replace it as '0.00'(just wanted to add a single quotes to it). please provide us a solution. It is not allowing me to proceed further.

    Thanks,

    use Spreadsheet::XLSX;

    my $excel = Spreadsheet::XLSX -> new ('/tmp/temp.xlsx');

    print $excel;

    my @array;

    my $workbook = Excel::Writer::XLSX->new( 'perl.xlsx' );

    #my $FILENAME="/tmp/Newfile.xls";

    my $workbook = Spreadsheet::WriteExcel->new("$FILENAME");

    my $worksheet1=$workbook->addworksheet("Worksheet1");

    $worksheet1->write( "A1", "Hi Excel!" );

    foreach my $sheet (@{$excel -> {Worksheet}}) {

    printf("Sheet: %s\n", $sheet->{Name});

    $sheet -> {MaxRow} ||= $sheet -> {MinRow};

    foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) {

    $sheet -> {MaxCol} ||= $sheet -> {MinCol};

    foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) {

    my $cell = $sheet -> {Cells} $row $col;

    if ($cell) {

    printf("( %s , %s ) => %s\n", $row, $col, $cell -> {Val});

    my $temp=$cell->{Val};

    $worksheet1->write($row,$col,$cell -> {Val});

    # push(@array,$temp);

    # $sheet->write($row,$col,"CHECK");

    } }

    }

    last

making a markovian "mad lib"
2 direct replies — Read more / Contribute
by Aldebaran
on Mar 20, 2019 at 18:32

    Hello Monks,

    I'm trying something new that I've been bouncing around in my head since bliako posted his markovian meditation n-dimensional statistical analysis of DNA sequences (or text, or ...). bliako has all these interesting and abstruse scripts that are right on the edge of what I can replicate. I was able to do so once with the Markovian Frankentext of that thread but could not do it again. I want to reach for something much simpler, indeed as simple as I can imagine it as an SSCCE. With that as an introduction, I'll put a statement of the problem in readmore tags:

    Thanks for your comment

Split lines in file to columns
4 direct replies — Read more / Contribute
by Magnolia25
on Mar 20, 2019 at 05:35
    Hi Monks,

    Below are the lines in my file. I am reading them into array and storing column values into variables.

    ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription at RowCode ValuesInColumn1 DataColumnB ABC RowDescription at RowCode

    The following will take data from my file, split it.That works if the columns are divided on spaces. But value for colD is not captured correctly, as string in colD has sapces in between. If value for $colB = XYZ and $colD contains substring = Region , I need to replace the $colB from XYX to N/A.

    foreach my $line (@a) { my ($colA, $colB, $colC,$colD) = split( /\s+/, $line); #print "$colD \n"; }

    Please help.

circular area in a coordinates grid (AoA)
8 direct replies — Read more / Contribute
by Discipulus
on Mar 19, 2019 at 17:34
    Hello monks,

    I have an array of arrays full of o and, given the coordinates of one element and a radius I want to change all elements around the center into x

    My AoA can be eventually big so I do not want to process every element of the AoA.

    The sub ( illuminate in the example below ) must not complain if a point is outside of the AoA (for example giving a corner as vertex).

    A pure perl solution will be the best, but also using modules will be ok.

    Sorry if I only have the below sketch but I'm very scarce in trig and until now I can only figure to hardcode series of coordinates relative to the vertex (that is silly..)

    use strict; use warnings; my $max = 19; my @aoa = map { [ ( 'o' ) x ($max + 1) ] } 0..$max ; display( @aoa ); # @to_change will contain [row1,col1],[row2,col2]... my @to_change = illuminate( 5, 4, 6 ); sub illuminate{ my $center_row = shift; my $center_col = shift; my $radius = shift; ... } sub display{ foreach my $row ( @_ ){ foreach my $col ( @$row ){ print $col; } print "\n" } }

    Thanks

    L*

    PS the above code displays the AoA before the change: I want to be able to select into @to_change the serie of elements falling inside the circle.

    minor changes to explain better

    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.
mod_perl sharing modules with other accounts when I don't want it to
1 direct reply — Read more / Contribute
by ultranerds
on Mar 19, 2019 at 11:05
    FYI I have already posted this on SO, but not had any replies yet:

    https://serverfault.com/questions/958937/mod-perl-seems-to-be-sharing-modules-across-user-accounts

    I'm hoping people here will be more knowledgeable :) Rather than repeating everything I posted on the other forum, I won't put too much.

    Basically the issue I'm having is that mod_perl is sharing modules from one <VirtualHost> to another (and I don't want this). I was reading that doing something like this should partition it:

    PerlOptions +Clone PerlSwitches -Mlib=/home/steampunkcom/web/uk.steampunkjunkies.com/lib


    ...but while mod_perl works, it still shares the modules :/ Am I missing something?

    Thanks

    Andy
New Perl Poetry
obfupoetry II
No replies — Read more | Post response
by Discipulus
on Mar 21, 2019 at 04:46
    In occasion of first day of Spring* i give you the second issue of perl obfupoetry:

    How:to:forget:when:I:was:young: join ' had ', (glob'spr{a,e,i,o,u}ng')[2,4]; Now:I:get:in:the:middle:of: join ' and ', (glob'Y{i,a}n{,g}')[0,-1]; and:I:remember:it:was:a:bang: seek DATA,0,0;while(<DATA>){last if/DATA/; chomp&&print/:/?(join$",split':',$_):eval,$/} __DATA__

    L*

    (*)please do not reply with positivist comments about the exact first day of Spring: seasons always start in day 21: the notion is in my mind since..

    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.
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 chanting in the Monastery: (7)
As of 2019-03-26 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (125 votes). Check out past polls.

    Notices?