Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
Hi Monks could you pls help Perl dummy user
3 direct replies — Read more / Contribute
by sibyurik
on Dec 16, 2014 at 19:54

    I need analyze dir structure and find all files that larger than 515 kbytes and recursion doesn't work i have no clue why? Please help me without fancy module and package style. Thx a lot

    #!/usr/bin/perl # #Author: Yury Sibirski #Name: users_home_dir #Date: 16 December 2014 #Purpose: This program analyze the directory structure of a Linux disk + and identify any files larger than 500 kbytes # $path = shift || '.'; read_dir($path); sub read_dir { $dir = shift; opendir (DH, $dir) or die "Couldn't open current directory: $! +"; while ($file = readdir(DH)) {#print "$file\n"; if ($file eq "." or $file eq "..") { next; } elsif (-z $file) { next; } elsif (-r $file and -f $file) { $size = -s $file; print $file," ",$size, "\n" if $size > 512000; } #recursion doesn't work i don't know why? # elsif (-d $file) # { # read_dir($file); # } } closedir DH; }
Tk Canvas Item Bind
1 direct reply — Read more / Contribute
by JadedAegis
on Dec 16, 2014 at 19:11
    use strict; use Tk; use Tk::DialogBox; #Character Variables. my $name = "Na"; my $health = "HP"; my $morality = "Mo"; my $willpower = "WP"; my $potency = "Po"; my $resource = "Re"; my $target = 0; # MainWindow my $mwin = new MainWindow(-background=>'black'); #Button for adding character information my $chrb = $mwin->Button(-text=>'Add Character',-activeforeground=>'bl +ack', -activebackground=>'green',-foreground=>'green',-backgroun +d=>'black', -command=>\&charadd) -> pack(-anchor=>'w'); #Canvas, which character info is drawn on. my $canv = $mwin->Scrolled('Canvas',width=>600,height=>600,-background +=>'black',-confine=>0) -> pack(); $canv->createLine(0,20,600,20,-fill=>'green'); #DialogBox, for when a new character is added. my $diag = $mwin->DialogBox(-title=>'Add Character',-buttons=>['Ok','C +ancel'], -default_button=>'Ok'); $diag->add('Entry',-textvariable=> \$name) -> pack(); $diag->add('Entry',-textvariable=> \$morality) -> pack(); $diag->add('Entry',-textvariable=> \$willpower) -> pack(); $diag->add('Entry',-textvariable=> \$potency) -> pack(); $diag->add('Entry',-textvariable=> \$resource) -> pack(); $diag->add('Entry',-textvariable=> \$health) -> pack(); Tk::MainLoop; #Maintain GUI. $canv->bind('<current>','<Button-1>', =>\&damage); our $charc = 0; sub charadd() { ++$charc; $canv->createText(20,($charc*60)+10,-text=>$charc,-fill=>'green'); $diag->Show(); $canv->createText(40,($charc*60)+10,-text=>$name,-fill=>'green'); $canv->createText(160,($charc*60)+10,-text=>"Po: $potency",-fill=> +'green'); $canv->createText(220,($charc*60)+10,-text=>"WP: $willpower",-fill +=>'green'); $canv->createText(280,($charc*60)+10,-text=>"Re: $resource",-fill= +>'green'); $canv->createText(360,($charc*60)+10,-text=>"Mo: $morality",-fill= +>'green'); for (my $i = 1; $i <= $health; $i++) { $canv->createRectangle($i*30,($charc*60)+20,($i*30)+20,($charc +*60)+40, -fill=>'green',-tag=>'hpbox'); } } sub damage() { }
    It runs, but when I click on one of the healthboxes drawn it doesn't do anything.
    Once the script ends it feeds me this huge error that ultimately ends in:
    Usage $widget->bind(...) ... Derived.pm line 469
about DateTime::Format::Strptime
2 direct replies — Read more / Contribute
by bcostacurta
on Dec 16, 2014 at 15:59
    Hello,

    I have a problem using the package DateTime::Format::Strptime.

    Using the two following patterns :

    pattern => '%B %d %Y %H:%M:%S' eg. 'Dec 16 2014 21:03:46'

    pattern => '%B %d %H:%M:%S' eg. 'Sep 16 21:00:00'

    The first pattern works, but not the second (which does not include the year neither in pattern neither in string).

    Where could be the problem ?

    #!/usr/bin/perl use DateTime::Format::Strptime; my $t = 'Dec 16 2014 21:03:46'; my $Strp = DateTime::Format::Strptime::->new( pattern => '%B %d %Y %H:%M:%S', locale => 'en_US', ); # my $dt = $Strp->parse_datetime($t); print "'$dt'\n"; my $t2 = 'Sep 16 21:00:00'; my $Strp2 = DateTime::Format::Strptime::->new( pattern => '%B %d %H:%M:%S', locale => 'eu_US', ); # my $dt2 = $Strp2->parse_datetime($t2); print "'$dt2'\n";
    Output is :
    '2014-12-16T21:03:46' ''
Help with using Net::SQL and declaring results as a variable
3 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 16, 2014 at 14:49
    Hey monks, I could do with some real help. Before going any further, yes, I would prefer to be using DBI/dbd, but that's not the point. I need to submit a MySQL query, then take the result and declare it as a new variable.
    $mySQL->query(q{ SELECT * from table ORDER by column desc LIMIT 1; }); my $nextValue = $mySQL->create_record_iterator; while (my $record = $nextValue->each) { printf "%d\n", $record->[0]; }
    returns what I need to use as a variable, however it seems I can't just initiate from $nextvalue or $record. Can anyone come up with a clever work around?
Sendmail only sending sometimes
3 direct replies — Read more / Contribute
by Sirwunton
on Dec 16, 2014 at 13:49
    Hi, I have fallen onto an older script of perl and have been racking my brains trying to figure out the solution. I have a sendmail script, it works only some of the time and when it does work it only sends from my personal email address to the destination...any advice would be deeply appreciated.
Perl Script Error
2 direct replies — Read more / Contribute
by fedeagostini
on Dec 16, 2014 at 12:37

    Hello, I have the following error message when i run my script.

    Scripting *** Error in `/usr/bin/perl': free(): invalid size: 0x00007fffdb68aef0 ***

    I found the problem. RAM was shortly.

    But, after upgrade RAM, the error is

    *** Error in `/usr/bin/perl': munmap_chunk(): invalid pointer: 0x00007fff7db11060 ***

    Aborted


    perl -v says v5.18.2

    The OS is Ubuntu 14.04 LTS

    Any idea?

an exe can be executed from cmd but wraping into perl fail to run
4 direct replies — Read more / Contribute
by kaka_2
on Dec 16, 2014 at 12:10

    Hello Experts,

    I have an application exe which run quite well from the cmd but when put it into thr simple perl file it does not return any output.

    $a = `command.exe`; print $a;

    Question is how to troubleshoot? what make it different when it is being executed from a perl file and not cmd.

    any hint in this regard will be helpful.

    Thank You. -KAKA-

Unaltered child return code on Windows
1 direct reply — Read more / Contribute
by salva
on Dec 16, 2014 at 11:48
    I am wrapping an external executable on Windows that can exit with codes bigger than 255. The issue I am facing is that Perl $? seems to be limited to the combination of one byte for the signal and another byte for the errorlevel. For instance, when the program exits with code 1000 (0x3E8), $? becomes 59392 (0xE800).

    Perl has also the variable ${^CHILD_ERROR_NATIVE}, but it seems that on Windows it gets the same value as $?.

    Does anybody known how to get the real exit code without reverting to using an external module as Win32::Process to start and control the slave processes? (on the other hand, I am already using Win32::API, so solutions using it would be acceptable).

getopt::long treating option as an argument
2 direct replies — Read more / Contribute
by harpreetsammi
on Dec 16, 2014 at 10:43

    Hi Experts,

    I am running a perl script which uses GetOpt::Long

    giveinfo.pl -name mike -long

    where, -name option ("name=s") needs a mandatory string argument

    -long is optional flag if set, will provide more details of the user named mike

    If i miss the user name while running giveinfo.pl as below then it does not error out -

    giveinfo.pl -name -long

    In this case, its treating -long as user name and DOES NOT error out. I want that in above case it should error out and say "Option name requires an argument".

    FYI. in the below scenario it error out as expected if i use -name at the end of command line -

    giveinfo.pl -long -name Option name requires an argument

    Can someone please help how can i error out correctly in the below scenerio which is missing name mike -

    giveinfo.pl -name -long

    I don't want to use "=" as -

    giveinfo.pl -name= -long

    Thanks and Regards,

    Harry
Why doesn't this print when i omit the newline?
5 direct replies — Read more / Contribute
by karlgoethebier
on Dec 16, 2014 at 08:07

    Hi all,

    i,m i'm banging my head against the wall with this:

    use strict; use warnings; use IO::All; # v5.18.2 my $io = io $0; while ( my ( $index, $value ) = each @$io ) { print qq($index\t$value); print qq($index\t$value\n); } __END__

    Only the second print works.

    I wonder why.

    Thank you very much for any hint and best regards,

    Karl

    «The Crux of the Biscuit is the Apostrophe»


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
  • Outside of code tags, you may need to use entities for some characters:
            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 imbibing at the Monastery: (10)
    As of 2014-12-19 07:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (73 votes), past polls