in reply to Re^2: Regexp works with some elements and doesn't with others
in thread Regexp works with some elements and doesn't with others

Something I use sometimes is the Data::Dumper module. It helps especially with complex lists, e.g. hashes of hashes of hashes, but the same concept applies here. By using it, you can literally see how contents of variables change, or even if the original values are what you expect them to be.

In this case, for example, you could modify the code to be -

use Data::Dumper; .... <snip> .... if ($text2 =~ m/^The website has been restructured/) { print "text array before is " . Dumper(\@text, $value); splice(@text,$value,1); print "text array after is " . Dumper(\@text, $value); splice(@links,$value,1); }

This way, you can see for yourself how @text is changing, and how it's different from what you expect. Note that you have to pass a reference to a list to the Dumper function call, since @text is one of two elements in the list of things you want to show.

Although you have to go through and uncomment/delete the Dumper lines once you've got it working, if you like actually 'seeing' changes as they happen, this may work very well for you, especially once you start using complex data structures.

Replies are listed 'Best First'.
Re^4: Regexp works with some elements and doesn't with others
by diotalevi (Canon) on Feb 07, 2006 at 04:15 UTC

    Hey, try this. The output is updated in place and whatever changed is highlighted as it changes.

    use Data::Dumper; use Term::HiliteDiff 'watch'; for ( ... ) { my $before = "text array before is " . Dumper(\@text, $value); ... watch( $before . "text array after is " . Dumper(\@text, $value) ) +; }

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^4: Regexp works with some elements and doesn't with others
by GrandFather (Saint) on Feb 07, 2006 at 03:29 UTC

    Even better is to use the debugger, and better still is to use an IDE such as Komodo and inspect the variables at run time without having to change your code at all.


    DWIM is Perl's answer to Gödel