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

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
change unintialized warning
3 direct replies — Read more / Contribute
by hailholyghost
on Mar 02, 2015 at 08:31
    Hello, I have a 355 line code that takes about 3 hours to run. I find errors like "Use of uninitialized value in subroutine entry at line 311" I have 4 different arrays on this line which could have been uninitialized. How can I set perl to change this warning to something like "Use of uninitialized value $hash{key1}{key2} in subroutine entry at line 311" in other words, how can I get the uninitialized warnings to tell me which value is uninitialized? To compensate for the vague warning, I have littered my code with "if(!defined($var))" but I would prefer a better solution than this. thanks, -DEC
Who called Perl?
4 direct replies — Read more / Contribute
by Discipulus
on Mar 02, 2015 at 03:25
    Hello monks, I asked yet this in chat and i'm almost convinced there is no answer but..
    as we say in my country ask is free so:

    Perl has some knoweledge about who called him? It must be some shell in all Linux flavours (bash, csh, ksh..) or in win32 the stupid cmd.exe, or maybe another modified shell-like program (Console2, powershell.. ).

    Once Perl has started I can easily make a system call to get description of the PID using $$ but i'd like to investigate the parent of such PID.

    Any ideas?

    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.
How can I debug a weird "Undefined subroutine..." error that should be defined.
1 direct reply — Read more / Contribute
by dly
on Mar 01, 2015 at 03:12

    Apologies for no real code, but the simple case does not exhibit my problem, only my real world case needing an FTP server set up exhibits the problem.

    The Simple code:

    # OVERRIDE_BUILD imports run_star_commands(). use App::Fetchware qw(:OVERRIDE_BUILD); run_star_commands();

    seems to work just fine :(

    But my complicated test environment involving a test FTP server exhibits this problem (Partial code listing):

    ... use Sub::Mage 'sublist'; diag("WEBAPPSLOADED!!!!!!!!!!!["); print "$_\n" for sublist(); diag("]"); use B::Deparse; my $deparse = B::Deparse->new("-p", "-sC"); my $body = $deparse->coderef2text(\&run_star_commands); diag("RUNSTARCOMMANDS["); diag("$body"); diag("]"); # Use run_start_commands from :OVERRIDE_BUILD to support uploa +d_commands # being a true ONEARRREF and having multiple commands to call. run_star_commmands(@upload_commands); } else { ...

    That has the following output:

    # WEBAPPSLOADED!!!!!!!!!!![ have after DATA_PROT_CONFIDENTIAL ... run_star_commands ... constructor filter splitpath CMD_OK download_dirlist # ] # RUNSTARCOMMANDS[ # { # package App::Fetchware; # use warnings; # use strict; # no feature; # use feature ':5.10'; # (my(@star_commands) = @_); # foreach my $star_command (@star_commands) { # if (($star_command =~ /,\s*/)) { # (my(@star_commands) = split(/,\s*/, $star_command, 0)); # foreach my $split_star_command (@star_commands) { # run_prog($split_star_command); # } # } else { # run_prog($star_command); # } # } # } # ] Undefined subroutine &App::FetchwareX::WebApp::run_star_commmands call +ed at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX/WebApp line 768 (#2) (F) The subroutine indicated hasn't been defined, or if it was, it + has since been undefined. Uncaught exception from user code: Undefined subroutine &App::FetchwareX::WebApp::run_star_commma +nds called at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX +/ line 768. at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX/ +line 768. App::FetchwareX::WebApp::build('a') called at t/App-FetchwareX +-WebApp.t line 733 # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 25 just after 5. Dubious, test returned 25 (wstat 6400, 0x1900) Failed 1/6 subtests Test Summary Report ------------------- t/App-FetchwareX-WebApp.t (Wstat: 6400 Tests: 6 Failed: 1) Failed test: 5 Non-zero exit status: 25 Parse errors: No plan found in TAP output Files=1, Tests=6, 0 wallclock secs ( 0.03 usr 0.01 sys + 0.36 cusr + 0.12 csys = 0.52 CPU) Result: FAIL

    As you can see from the output right before I call run_star_commands() I call Sub::Mage's sublist() subroutine that returns all subroutines defined in the current package. I snipped the output, but the important part is that run_star_commands() is listed.

    I also use B::Deparse to deparse run_star_commands() to see if run_star_commands() can be deparsed, and it deparses it just fine.

    Then the very next thing I do is call run_star_commands(), but it fails with an "Undefined subroutine" error message.

    My test setup is a real disaster, so testing my code would require installing a bunch of modules, setting some crazy environment variables, and access to a FTP server. So, instead of asking you guys to git clone my repo, set insane environment variables, and setup an FTP server, what I'm looking for is a way to debug this problem myself.

    Could setting a watchpoint in the debugger for run_star_commands() reveal what's making it vanish without a trace right before perl calls it? Watchpoints only seem to work for regular variables as using something like:

    w $App::FetchwareX::WebApp{run_star_commands}{CODE}

    causes the debugger to freak out. Is their some sort of way of accessing a subroutine "as a variable", so that I can set a watch expression on it to see where it changes?

ip_match doesn't seem to work
3 direct replies — Read more / Contribute
by mwhiting
on Feb 27, 2015 at 10:54

    This is something of a ressurection of a question from this past month.

    I am using Session Id's and have started trying to use -ip_match so that you can't cut and paste an url with the session id embedded in it from one computer to the next. But since I have added -ip_match I don't get any different results when accessing the same script from computers with different IP's. I modified my Use statement to be:

    use CGI::Session qw/-ip-match/;

    instead of my usual use cgi::Session; line. I also tried adding

    $session::IP_MATCH = 1;

    to the mix, after the creation of the session object, and still I see no difference in the results on browsers with different ip's. The different computers still access the session info just fine and pass the authentication using info in the session variable.

    What am I missing here in the use of -ip_match ? Your help would be greatly appreciated!   :)

Want END block to run except when usage()/--help invocation
2 direct replies — Read more / Contribute
by CoVAX
on Feb 26, 2015 at 23:50

    This is the first time I've used an END block. I need its functionality because I call 'die' at several points throughout this program and I have to always perform the code in the END block.

    I was making the final edits to a program's usage() function and noticed the following warnings following a --help invocation:

    perl -w -h
    Use of uninitialized value $time in concatenation (.) or string at ks. +pl line 253. Use of uninitialized value in concatenation (.) or string at lin +e 258. Use of uninitialized value in concatenation (.) or string at lin +e 258. Use of uninitialized value in concatenation (.) or string at lin +e 258. Use of uninitialized value in concatenation (.) or string at lin +e 258. Character in 'c' format wrapped in pack at line 262. Use of uninitialized value $time in concatenation (.) or string at ks. +pl line 283.

    Ah so! (German for "I see!") -- these warnings were the result of the END block being (unconditionally) executed after the usage() function.

    While I understand why this is happening, my question is: is there a way to have an unconditional END block execute except when the program's usage() function is being invoked? If not, then I propose to create yet another function to be called prior to die()'ing that will execute what's presently in the END block.

    Here's the relevant code:

    #!/usr/bin/perl -w use strict; use Getopt::Std; ... # Don't want END block to execute when these are invoked: sub HELP_MESSAGE(); # getopts() --help automatically invokes VERSIO +N_MESSAGE() first sub VERSION_MESSAGE(); # getopts() supports arguments --version and -- +help sub usage(); ... INIT { $| = 1; # Make Getopt::Std exit after printing # VERSION_MESSAGE() and/or HELP_MESSAGE() $Getopt::Std::STANDARD_HELP_VERSION = 1; } ...By design, main-line code comes to this END block: # An END block is always executed (barring some exceptions) as # late as possible, even after die() is called END { export_to_file_csv(); export_to_storable(); warn "Pages : $pages of Total Pages: $total_pages"; warn "Projs : $projs of Total Projs: $total_projs"; warn sprintf ("Images: %d amounting to bytes: %s", $imgs, $bytes)); } # END OF PROGRAM (normal or otherwise).

    I thank you for your time and assistance.

    Searched for donut and crumpit. Found donate and stumbit instead.
cpanm not retrieving remote files
2 direct replies — Read more / Contribute
by cLive ;-)
on Feb 26, 2015 at 16:43

    Confused about this. From the cpanm build log:

    Searching Net::SSH on cpanmetadb ... --> Working on Net::SSH Fetching -> FAIL Download +.tar.gz failed. Retrying ... -> FAIL Download +.tar.gz failed. Retrying ... -> FAIL Download +.tar.gz failed. Retrying ... -> FAIL Failed to download +t-SSH-0.09.tar.gz -> FAIL Failed to fetch distribution Net-SSH-0.09

    But, if I run this in the shell:


    the module downloads as expected, and I can install manually.

    That's great and all, but then I have to install each dependency manually.

    I've deleted the .cpanm and .cpan directories in /root, but I still keep hitting this issue with every module I install. I've tried specifting wget or curl as CL args on cpanm, but they don't seem to be making a difference.

    It worked fine when I first installed it, but then just stopped a few weeks ago.

    I'm not sure how to debug this one. Any ideas?

Why did @$ variable bite me in the ass?
3 direct replies — Read more / Contribute
by dmitri
on Feb 26, 2015 at 14:12
    So there I was, happily rolling along, writing my class, and using an array ref as my underlying data structure. I then wrote another method:
    sub another_method { my ($self, $magic_val) = @_; $$[MAGIC_VALS]{$magic_val} = 1; }
    and ran it. There were no compile-time or run-time errors, but the logic did not work. Can you spot the problem? That's right: it should be $$self[MAGIC_VALS]{$magic_val} instead! What is this magical @$? Perl does not complain about it and will happily use this array:
    use strict; use warnings; $$[0] = 1; $$[1] = 'dude!'; print "@$", "\n"; # Prints "1 dude!"
    It's not in perlvar... What's up with this variable?
HELP: Problem with PDF
2 direct replies — Read more / Contribute
by cristofayre
on Feb 26, 2015 at 13:24
    I'm tearing my hair out!!

    I generated a PDF with AP12. If I click the file locally, it loads into reader fine. But no matter what I do in perl, it stops loading data at around 4K of a 212K file. (Reading the data sent to page in a text editor, it seems to stop at %%EOF)

    I have tried the usual "While(<xx>)" and "@file=<ZZ>", and even tried the "local $/" to set to undefined size ... but still it stops reading at 4K / %%EOF

    << /Info 4 0 R /Root 1 0 R /Size 815 >> startxref 207080 %%EOF

    So I can't even 'grab' it to send it to a zip file, (everything is code based from generating file to delivery) 'cos I can't read the entire file ... My ultimate aim is to get the file to the browser, or to a save prompt - but can't do either.

    Annoying thing is, I've got it to work before using the "Content-disposition" "content-type: application/pdf" ... but I suspect those files are less than the buffer size (??)

    I even tried it with another file (8MB) Whilst I got the correct number of pages after 20 seconds - and having to switch to an older reader ... there was no text on any page!!

    I can't even email it to people ... cos I can't read the entire file to memory.

    Final try:

    open (QR, "<QR_labels.pdf"); binmode(QR); print "Content-type: application/pdf\n\n"; print 'Content-Disposition', "attachment; filename=Booth_guide.pdf\n\n +"; while(read(QR,$buffer,10000)){ print $buffer; } close(QR);

    Same thing. Only 4K delivered to browser from 212K, and breaking as shown above. This has me beaten! I don't know what to try next

[OT] Stats problem
7 direct replies — Read more / Contribute
by BrowserUk
on Feb 26, 2015 at 04:47

    Any group of 4 bytes in memory can contain any of 2^32 values.

    4GB of memory contains 2^29 (1/2 a billion) 8-byte aligned, 4-byte fields.

    If a runaway loop writing random bytes overruns its buffer and scribbles over one of the 32-bit fields, what are the odds that the 4-bytes, viewed as an unsigned 32-bit integer, would match that fields offset into the 4GB of ram?


    memory:(hex)[00000000........][00000008........][00000010........][000 +00018........]...[12345678........][12345680........]... offset:(dec) 0 8 16 24 + ... 305419896

    The premise is that if free blocks are maintained with their offset into the 4GB block, and a buffer overun occurs, then any block that has been overwritten is easily detectable, with a high degree of certainty. A far higher degree than if the typical fixed known bit-pattern is written there.

    Corruption could write any of the possible values anywhere; and if a fixed bit-pattern is used as the marker, there is, assuming total random corruption, a 1 in 2^32 chance of a specific field being mistaken for the fixed bit pattern. But with potentially 2^29 fields, those odds reduce markedly. I think to 1:(2^32/2^29) = 1 in 8 chance if the whole 4GB were corrupted.

    But the odds that an exact offset value will be written at that exact offset has to be many time higher. But how high?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Is there an IO::*-like interface for accessing tar files?
2 direct replies — Read more / Contribute
by atcroft
on Feb 25, 2015 at 11:46

    Can anyone recommend a module that would provide an IO::*-like interface for accessing tar files?

    In a recent project at $work, I used IO::File and IO::Uncompress::AnyUncompress to simplify processing of compressed (bzip2 or gzip) or uncompressed files. (For example, reading lines via $foo->getline(), or current line number by $foo->input_line_number.) Now, I have been asked to add processing for tar archives. While I have used Archive::Tar for processing tar archives before, I was hoping that there might be module that could provide an IO::*-like interface so I could minimize the changes needed to add the support.

    Thank you for your time and attention, and any direction you may provide.

STDOUT msg routing
2 direct replies — Read more / Contribute
by sandy105
on Feb 25, 2015 at 05:11

    I have many legacy scripts which print logs directly to STDOUT and use a scheduler where they pipe the stdout to a log file >>alog.log ; however is there any way inside perl to force these msgs to print to a file rather than console

    --just wondering if its possible to do it

Name of caller if aliased?
3 direct replies — Read more / Contribute
by LanX
on Feb 24, 2015 at 23:15
    Precious Monkses!

    (caller(0))[3] shows me the name of the currently executed function.

    But in case of importing/aliasing it'll be the original one not the alias' name.

    Any way to find the name of the alias?


    $\="\n"; sub show { print join "\t",(caller(0))[0..3]; }; show(); *func = \&show; func();


    /usr/bin/perl -w /tmp/ main /tmp/ 6 main::show main /tmp/ 10 main::show

    any straight forward way to get "main::func" in the second case?

    (no, parsing the calling line is not an option)

    Thankses for your attention! :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

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 chilling in the Monastery: (21)
As of 2015-03-02 17:19 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (52 votes), past polls