Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
Trying to Understand Callback(s)
5 direct replies — Read more / Contribute
by DanielSpaniel
on Nov 23, 2017 at 17:06

    Hi,

    This isn't a problem so much as me trying to understand something, but I hope someone might be kind enough to help explain.

    So, I have some code, which was sourced from elsewhere (it's from a Mojo example), which uses a callback, but I don't really quite get the idea of callbacks, and particularly I don't understand the syntax.

    $ua->get($url => \&get_callback);

    So, sure enough there is a subroutine called get_callback, but I don't really understand what's happening. I did find an O'Reilly doc on callbacks, but the syntax was different.

    sub get_callback { my (undef, $tx) = @_; .... .... }

    I don't really get the first line of the get_callback routine either, when nothing appears to be being passed across

    If someone might explain in kiddie-steps what's happening, and why, then it would be much appreciated. Many thanks!

Calculate seconds between dates
4 direct replies — Read more / Contribute
by packetstormer
on Nov 23, 2017 at 16:31

    Hello Monks

    Could anyone point me in the right direction to calculate the number of seconds between two dates, taking into consideration weekends, holidays and the working day (9-5:30)?

    I have been looking at Data:Calc and Date::Calendar to figure out the days between two working days. However, I need it figure out how it make it more exact. For example, a start time of Friday @4:33pm to end time of the following Wednesday @5:10pm. I was hoping the former two libraries might have a "to_epoch" routine but no such luck

    Suggestions would be most welcome!!

Array of strings search
4 direct replies — Read more / Contribute
by maikelnight
on Nov 23, 2017 at 10:19

    Hi Monks, i have an array with Strings, which looks like:

    $VAR1 = 'Nov 19 06:31:17 proxy postgrey[2439]: action=pass, reason=tri +plet found, client_name=r41.newsletter.otto.de, client_address=185.15 +.51.41, sender=otto@newsletter.otto.de, recipient=some.one@some.domai +n'; $VAR2 = 'Nov 19 06:37:45 proxy postgrey[2439]: action=pass, reason=tri +plet found, client_name=uspmta194080.emarsys.net, client_address=217. +175.194.80, sender=suite17@xpressus.emarsys.net, recipient=other.one@ +some.domain';

    I need to push some strings from the array into another array - for example the date, sender and recipient. I first try with date, like:

    for my $x ( @results ) { chomp $x; my ($date) = split /'[A-z]*.[0-9]*.[0-9]*:[0-9]*:[0-9]*/, $x; push @out, $date; }

    What results in the whole line:

    $VAR1 = 'Nov 19 06:31:17 proxy postgrey[2439]: action=pass, reason=tri +plet found, client_name=r41.newsletter.otto.de, client_address=185.15 +.51.41, sender=otto@newsletter.otto.de, recipient=some.one@some.domai +n';
    May i ask someone to shed some light, please! Thanks!

Alternatives for index() ... substr() ?
7 direct replies — Read more / Contribute
by zarath
on Nov 23, 2017 at 10:02

    Hello Monks!

    This question is all about keeping the written code as clean, clear and simple as possible.

    The code works, so I would not classify this as a 'problem', but if for example next year something changes about the way the inputfiles are written, I will be having a hard time deciphering what I did here again. So I was just wondering if there is a clearer way of doing what I do here?

    Maybe something like my $msg = "the string that comes between" 'copying ' "and" ' from ';? Is there a function that does what the double-quoted text says?

    Thank you in advance!

Do you know any online IDE where user can choose some or any version of perl?
5 direct replies — Read more / Contribute
by rsFalse
on Nov 23, 2017 at 06:27
    Hello.
    I want to try running my program on different versions: 5.8, 5.14, 5.20, 5.26, etc. But I have only one perl at my PC. How can I easily do that?
    Maybe you know online IDEs with different perl versions?
Polygon Creation -- Request for Algorithm Suggestions
4 direct replies — Read more / Contribute
by golux
on Nov 22, 2017 at 14:13
    I'm working on a "hobby" Perl project in my spare time, where I want to take a set of points and order them so as to define the enclosing polygon. Ultimately this will be used in a web page (for shapes representing towns in different counties) presented using the <area shape="poly" coords="..."> tag.

    I've abstracted what I have so far into a short test program "test.pl":

    I'm happy with my prune_interior_points method, which takes the initial set of points and discards all but the outline of the shape (both of which you can see by running the script "test.pl".

    The final step will be to order the points in such a way that no two consecutive points have too much distance between them, but still using ALL of the points, so as to produce a polygon. The distance algorithm for any two points is, of course, sqrt(($y1 - $y0) ** 2 + sqrt($x1 - $x0) ** 2), but I'm getting stuck on finding a simple algorthm for producing this ordering.

    Does anyone have any suggestions for such an algorithm?

    Edit: It occurs I could have made this a Meditation, since it's more about discussing algorithms than it is about a specific Perl question.

    say  substr+lc crypt(qw $i3 SI$),4,5
Case insensitive hash key existance
5 direct replies — Read more / Contribute
by merrymonk
on Nov 22, 2017 at 10:26
    I want to test the existence of a hash key so that the case of the key does not matter. I would prefer to do this in the normal way of
    if(exists($data{$str})) {
    where any of abcd, aBcd, AbcD and so on would pass for the key of abcd.
    What is the simplest way of achieving this?
Global symbol "$isenchere" requires explicit package name at UserAction.pm line 416.
1 direct reply — Read more / Contribute
by *alexandre*
on Nov 22, 2017 at 10:15
    Hi I could not fond what the error mind with the $isecnchere variable
    sub payedSuccess { my $article = $query->param("article"); my $id_a_livre = $query->param("id_a_livre"); my $buyer = $query->param("buyer"); my $note = $query->param("note"); my $session = new CGI::Session( "driver:File", $session_id, {Dir +ectory=>"$session_dir"} ); my $username = $session->param("username"); if ($username) { my ($userID)=sqlSelect("id_personne", "personne", "nom_utilis +ateur = '$username'"); my ($isenchere)=sqlSelect("enchere", "article", "id_article = + '$isenchere'"); if ($isenchere eq '1') { ($ARTICLE{'max_enchere'})=sqlSelect("MAX(prix)", "ench +ere", "ref_article = '$article'"); ($ARTICLE{'ref_enchereur'},$ARTICLE{'id_enchere'})=sql +Select("ref_enchereur,id_enchere", "enchere", "ref_article = '$articl +e' AND prix = '$ARTICLE{'max_enchere'}'"); + }else { $ARTICLE{'ref_enchereur'} = sqlSelect("id_personne", "pers +onne", "nom_utilisateur = '$buyer'"); } my ($articleUserID)=sqlSelect("id_personne", "personne,articl +e,met_en_vente", "met_en_vente.ref_article = id_article AND id_artic +le = $article AND ref_vendeur = id_personne"); if ($userID eq $articleUserID) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd +st)=localtime(); my $date = sprintf "%4d-%02d-%02d \n",$year+1900,$mon ++1,$mday; my $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec); # sqlUpdate("article", "id_article=$article",(ref_statu +t => "14")); my $condition; ($condition) = sqlSelect("ref_condition_livraison", "a +rticle", "id_article = $article"); sqlUpdate("a_livre", "id_a_livre=$id_a_livre",(ref_sta +tut => "14", ref_mode_livraison => $condition)); ($ARTICLE{'email'})=sqlSelect("email", "personne", "id +_personne = $ARTICLE{'ref_enchereur'}"); + # article livré #article livré mail my $Message = new MIME::Lite From =>'robot@djmarketpl +ace.biz', To =>$ARTICLE{'email'}, Subject =>$SERVER{'article +_deliver'} , Type =>'TEXT', Data =>"$SERVER{'article_deliver'}"; $Message->attr("content-type" => "text/html; chars +et=iso-8859-1"); $Message->send_by_smtp('localhost:25'); loadMyEnchereDeal(); } else { #modification d'un article d'un autre user } } }
    thx
Win32::OLE Excel temporary objects destruction
5 direct replies — Read more / Contribute
by ndts
on Nov 22, 2017 at 08:42

    Hello PerlMonks,

    I have inherited from another person some Perl scripts dealing with logfile manipulation. The idea is simple, read data from some text file, decode it and write the results in an Excel file. The script is working ok, but it takes a huge amount of time to finish, even though the log files are not that big (30MB max). Moreover, the script runs 10x faster on my colleague machine. I use Win32::OLE to deal with Excel manipulation as I also need to do some formatting on the output.

    To find out which parts of the code are slow I have done a profiling of my application using Devel::NYTProf and I have found some interesting results. A snippet of the code is the following:

    $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OL +E->new('Excel.Application', 'Quit'); $Book = $Excel->Workbooks->Open( $templateFile ); # #decoding code here # $Book->Worksheets($sheetNumber)->Range("A$Row:E$Row")->{Value} = [[$Ti +meAbs,$TimeRel,$TimeLog,$Info,$SigValue]];

    The NYTProf output for the last line of code shows something like:

      "# spent 35.5s making 44688 calls to Win32::OLE::AUTOLOAD, avg 794µs/call"

    and a few lines below:

      "# spent 454s making 22344 calls to Win32::OLE::DESTROY, avg 20.3ms/call"

    What I want to understand is why the AUTOLOAD function is called here? (Moreover why it is called 2 times every time the line is passed(the line is called 22344 times). Could this be related to the fact that I use Win32::OLE on a configuration on 64bits (both Windows and Excel)? Also, why is the destructor so time expensive and why is it called every time the line is executed? I suppose that some temporary objects are created there but I do not have enough experience with Win32::OLE to figure it out.

    Any suggestions, hints, tutorials are welcome. Thanks.

    Sebi

Since when did "\N{U+5678}" work as an alternative to "\x{5678}"?
5 direct replies — Read more / Contribute
by daxim
on Nov 22, 2017 at 07:01
    n/t

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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the pool shimmers...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (3)
    As of 2017-11-25 04:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:













      Results (355 votes). Check out past polls.

      Notices?