siddheshsawant has asked for the wisdom of the Perl Monks concerning the following question:

Hello friends I have written one script and one module as follows.I am giving both the things in detail

#!/usr/bin/perl use UserScenarioDesc; #providing web_link and user_scenario_name for testing the working of +the script my $web_link="http://lcla238.ping.com/nightly_results/2010_03_23/log_l +cla133.ping.com_64___TestSuiteDARE_Tx_Debug_MpaaPseudoIBM_AIX__3_37.h +tml"; my $us_name="testdare/UserScenarioDAREenableDisableEncryptionTx"; #print statement wrote to check the bug print"hello\n"; #calling the user sceanrio description function for testing my $user_scenario_desc = UserScenarioDesc::get_user_scenario_desc($we +b_link,$us_name); #print statement wrote to check the bug print"Hello\n"; print "UserScenario Description is as follows:\n"; print $user_scenario_desc."\n";

the corresponding module is as follows:

package UserScenarioDesc; use strict; use Cwd qw( abs_path ); my ($cwd, $above, $below, $tinc); BEGIN { $cwd = abs_path "."; ($above, $below) = $cwd =~ m~^(.+)/pp2dev/src(/.+|)$~ or die "Not in a pp2dev source tree\n"; my $tinc = "$above/pp2dev/src/testsuite/user/tinc"; my $Common="$above/pp2dev/src/testsuite/user"; unshift @INC, $tinc; unshift @INC, $Common; } use DHPL::System; use nightly::common; use Logs::LogReader; #Defining function BEGIN { use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( &get_user_scenario_desc ); } sub get_user_scenario_desc{ my($web_link, $us_name) = @_; # constructing web link to open the remote log file if($web_link =~ m/nightly_results(.*?)(.html)/) { $web_link= "/nightly_results".$1.".html"; } #remote copy command `rcp lcla238.ping.com:$web_link /tmp/nightly_db_scenarios.html`; my $file = "/tmp/nightly_db_scenarios.html"; #Generating SUiteLog object my $sul = SuiteLog->new( { FILE => $file } ); # $logfile is the log f +ile of test run #parsing all the log. $sul->parse_suite( ); # get_scheduled will return the list of all the test_suites present in + the respective test_run foreach my $sname ( @{$sul->get_scheduled( )} ) { #creating scenario_log variable using SuiteLog object my $scl = $sul->get_log( $sname ); #invoking method to list all the scenarios names for the given web lin +k. my $name = $scl->name( ); ##invoking method to extract the description (if any) for the given sc +enario name of the provided test_web_link. my $description=$scl->get_decription(); if($name eq $us_name){ return $description; } } } 1;

I am getting an output as follows:

hello (234113)Hello UserScenario Description is as follows: Steps for testing basic encryption: 1) turn on encryption on a device and verify 2) copy test data file to device 3) copy data from device to output file 4) verify test data file and output file are the same 5) reboot 6) verify device is still encrypted 7) copy data from device to output file again 8) verify test data file and output file are still the same 9) turn off encryption and verify 10) copy data from device to output file 11) verify test data file and output file are not the same

In the script I wrote two print statments purposely to specify that the error is coming from line

UserScenarioDesc::get_user_scenario_desc($web_link,$us_name);

The number (234113) that you can see in the output in between two hellos is not expected...One interesting thing about this is when I change my input web_link value the garbage value gets changed...If anybody knows why I am getting such garbage value in the output then please let me know...Thanks in advance !!!!!

Replies are listed 'Best First'.
Re: getting some random number for subroutine call in perl
by SuicideJunkie (Vicar) on Mar 24, 2010 at 15:18 UTC

    You have both too much code and not enough code in your node.

    Make a copy of your program and then Trim! Hack and slash and burn away the extraneous code. Delete all of the function calls that do not bear on the problem before posting it. When you are left with only a get_scheduled() call, you will know what additional code to inspect, trim and then show. If you do this recursively, I am sure that you will be left with just a plain old print statement somewhere in the bowels of the sub-sub-routines which you have not shown. Then you will know why and what it prints.

    You had the right idea with the print statements but there are a few things you can do to improve them:

    1. Use a more descriptive print: "Getting user scenario description", rather than "hello".
    2. Recurse! Put more prints into the problem sub, and see which of its subs or lines of code are causing the problem.
    3. Make them conditional: print "Frobnicating the $foo\n" if $DEBUG;, so that you can turn them on and off when you need them again later.

Re: getting some random number for subroutine call in perl
by ikegami (Patriarch) on Mar 24, 2010 at 15:11 UTC

    I am giving both the things in detail

    Why? Continue narrowing the source of the output.

Re: getting some random number for subroutine call in perl
by Anonymous Monk on Mar 24, 2010 at 14:53 UTC
    GIGO
    print "__expect GIGO after this__\n"; #remote copy command `rcp lcla238.ping.com:$web_link /tmp/nightly_db_scenarios.html`; print "__expect GIGO before this__\n"; print "__expect GIGO after this if no GIGO before__\n";
Re: getting some random number for subroutine call in perl
by Jenda (Abbot) on Mar 25, 2010 at 14:45 UTC

    You might also want to see whether the message was actually printed to STDOUT or STDERR. It might be a message printed to STDERR by some program you run using `backticks`. Redirect the STDOUT and STDERR of the script to two different files and see in which does it end up.

    perl the_script.pl > STDOUT.log 2> STDERR.log

    And if the number changes whenever the $web_link changes, then it's probably printed by something that uses that parameter. It might for example be the size of the document on that address and be printed by the `rcp ...`.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.