The Perl debugger is a wonderful tool, and I use it quite often - whenever I find it is the appropriate tool for the task. Before I fire up the debugger, I always stare at the messages, the code and at the docs, and in your example this turns out to be sufficient to see what's happening.

I simply thought that this problem might be a good way for me to get my feet wet with the debugger. I thought it might bring me close to perl's machine model.

That's also quite obvious: You're calling the sub without any parameters, but it expects one which can be used as a HASH reference in line 35 of debug1.pm:

Yes indeed. I needed to change that line with caller:

my $rvars = \%vars; ## this function is to be debugged using the perl debugger my $return2 = make_initial_captions($rvars); say "return2 is $return2";
Keep your code concise: Eliminate stuff which isn't relevant to your question. For example, I'm not going to install Net::SFTP::Foreign to get it even compiled.

Let's consider this. I know that we're encouraged to come up with an SSCCE, but this is not, nor can it easily be made so. It's an html templating system that has evolved according to my needs. I've tried to make a distribution of it, but I couldn't manage how to deal with filesystems on github. What would you use instead of Net::SFTP::Foreign?

Keep your own example complete. utils1.pm is missing.

This was my effort to be concise. I don't see how the use statements in subroutines affects other modules:

Update: put module source between readmore tags

package utils1; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( invert_aoa print_hash print_aoa highest_number ); sub invert_aoa{ use strict; use warnings; use 5.010; my $a = shift; my @AoA = @$a; my $k = $#AoA; #say "k is $k"; my @BoB; for my $i ( 0 .. $#AoA ) { my $aref = $AoA[$i]; my $x = $#{$aref}; #say "x is $x"; for my $j ( 0 .. $#{$aref} ) { $BoB[$j][$i]= $AoA[$i][$j]; } } my $b = \@BoB; return $b; } sub print_aoa{ use warnings; use 5.011; my $a = shift; my @AoA = @$a; for my $i ( 0 .. $#AoA ) { my $aref = $AoA[$i]; for my $j ( 0 .. $#{$aref} ) { print "elt $i $j is $AoA[$i][$j]\n"; } } return $a; } sub highest_number{ use strict; use File::Basename; use Cwd; my ($aref, $filetype, $word) = @_; my $number; my @matching; my $ext = ".".$filetype; push (@matching, 0); #min returned value for my $file (@{$aref}) { #print "file is $file\n"; if ($file =~ /^$word(\d+)$ext$/){ #print "matching is $file\n"; push (@matching, $1); } } @matching = sort @matching; my $winner = pop @matching; return $winner } sub print_hash{ use 5.011; my $hash_ref = shift; ## 10-15-18 adding sorted keys print "subroutine says this is your hash: \n"; my %hash = %$hash_ref; foreach my $name (sort keys %hash) { say "key: $name, value: $hash{$name}\n"; } } 1;

Question: what use statements can be removed from everything I've posted?

This routine has a breakpoint now:

sub make_initial_captions { use 5.016; use warnings; use POSIX; use Path::Tiny; use Encode; use open OUT => ':encoding(UTF-8)', ':std'; use Data::Dumper; my $rvars = shift; my %vars = %$rvars; #print Dumper $rvars; my $image_path = $vars{"to_images"}; my $caption_path = $vars{"eng_captions"}; # put a break point here $DB::single = 1; return "nothing yet"; }

, and, I got to see some values at this mark:

$ perl -d 1.debug.11.pl Loading DB routines from perl5db.pl version 1.55 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. Subroutine debug1::getcwd redefined at /usr/share/perl/5.30/Exporter.p +m line 66. at template_stuff/debug1.pm line 400. debug1::BEGIN() called at template_stuff/debug1.pm line 400 eval {...} called at template_stuff/debug1.pm line 400 require debug1.pm called at 1.debug.11.pl line 4 main::BEGIN() called at template_stuff/debug1.pm line 400 eval {...} called at template_stuff/debug1.pm line 400 main::(1.debug.11.pl:12): my $ts = "template_stuff"; DB<1> n + main::(1.debug.11.pl:13): my $images = "aimages"; DB<1> c + title is 1.debug.1 path1 is /home/hogan/6.scripts/1.debug.1 abs is /home/hogan/6.scripts/1.debug.1/1.debug.11.pl debug1::make_initial_captions(template_stuff/debug1.pm:43): 43: return "nothing yet"; ... DB<3> p $vars{to_images} + /home/hogan/6.scripts/1.debug.1/template_stuff/aimages DB<4> p $vars{eng_captions} + /home/hogan/6.scripts/1.debug.1/template_stuff/captions DB<5> c + return2 is nothing yet ini path is /home/hogan/Documents/html_template_data/6.values.ini ...[normal execution] return is 1.debug.13.html http://www.merrillpjensen.com/perlmonks/1.debug.13.html Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<5> q + $

It then executed to the end and behaved.


In reply to Re^2: Using the perl debugger to look at a renaming files function by Aldebaran
in thread Using the perl debugger to look at a renaming files function by Aldebaran

Title:
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, details, 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, summary, 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.