value of variable switches from ' ' to 'value'

--------------000108090907030800060105
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

I'm trying to figure out what exactly a script I wrote (see the attachment) is
doing by stepping through it in the debugger.  I have an array of dates in
%Y-%m-%d format for each of the last 7 days.  So, for instance, the range of
dates for today (June 17, 2007) is from the 10th to the 16th.  I then take these
dates and use them to find work tickets in our ticketing system which were last
updated on the day currently being checked.

So, the first date would be 2007-06-16 (having pushed, rather than shifted, the
array).  I then grab the date of a ticket transaction, dropping the time from it
so it is only the date (my $lstupdt = $ticket->LastUpdated) =~ s/\s.*$//;
The ticket system uses datetime format so I have to remove the space following
the date and everything after it.  LastUpdated is a built in method for the
ticket system which does pretty much what its name implies, gets the date of the
last transaction on the ticket.

In the debugger I've set the 'w' command to watch the variable containing the
day being looked for ($day).  I would have thought $day stays the same throught
an iteration of the while loop but the debugger keeps stopping to tell me it
switched from '2007-06-15' (for instance) to ''.  I then continue and it tells
me it switched back from '' to '2007-06-15'.  Is it supposed to do that?
Shouldn't the $day variable remain constant?

I know this is convoluted and not having knowledge of the ticket system may make
this difficult to help with, but anything you can offer will be appreciated

Mathew
-- 
Keep up with me and what I'm up to: http://theillien.blogspot.com

--------------000108090907030800060105
Content-Type: application/x-perl;
 name="weekly_timesheet.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="weekly_timesheet.pl"

#!/usr/bin/perl

#######################################################
#  Name:    weekly_timesheet.pl
#  version: 1.0
#  Date:    May 15, 2007
#  Author:  Mathew Snyder
#######################################################

use warnings;
use strict;
use lib '/usr/local/rt-3.6.1/lib';
use lib '/usr/local/rt-3.6.1/local/lib';
use RT;
use RT::Tickets;
use RT::Users;
use MIME::Lite;

RT::LoadConfig();
RT::Init();

# Declare our global variables
my (@days, @months, @years, @searchDate);
my $time = time();

for (1 .. 7) {
  $time -= 24*60*60;
  my @date = (localtime($time))[3 .. 5];
  push @days, (sprintf '%02d', $date[0]);
  push @months,(sprintf '%02d',$date[1] + 1);
  push @years, $date[2] + 1900;
  push @searchDate, join "-", ($date[2] + 1900), (sprintf '%02d',$date[1] + 1), (sprintf '%02d', $date[0]);
}

my $startDate	= join "-", $months[$#months], $days[$#days], $years[$#years];
my $endDate	= join "-", $months[0], $days[0], $years[0];
my $searchStart = $searchDate[6];
#my $searchStart = join "-", $years[$#years], $months[$#months], $days[$#days];
my $searchEnd   = $searchDate[0];
#my $searchEnd   = join "-", $years[0], $months[0], $days[0];

my $tix = new RT::Tickets(RT::SystemUser);
$tix->FromSQL('Queue = "CustomerCare" AND ((LastUpdated > "' . $searchStart . '" AND LastUpdated < "' . $searchEnd . '") OR (LastUpdated = "' . $searchStart . '" OR LastUpdated = "' . $searchEnd. '"))');

# The nitty gritty of the script
open TIMESHEET, ">/work_reports/weekly/debug/timesheet_weekof_$endDate.txt";

print TIMESHEET "Timesheet for $startDate to $endDate\n";

foreach my $day (@searchDate) {
	my %environment;
	my %ticCount;
        my $displayDate = join "-", (shift @months), (shift @days), (shift @years);

        # Print the header for our data
        printf TIMESHEET "\n\n" . $displayDate . "\n";
        printf TIMESHEET "%32s%11s\n", "Time", "Avg Time";
        printf TIMESHEET "%18s%7s%7s%11s\n", "Profile", "Tkts", "hh:mm", "hh:mm";
        print  TIMESHEET ("-" x 44);
        print  TIMESHEET "\n";

	while (my $ticket = $tix->Next) {
		my $env = $ticket->FirstCustomFieldValue('Environment');
		(my $updt = $ticket->LastUpdated) =~ s/\s.*$//;
		if ($updt eq $day) {
			$ticCount{$day}{$env}++;
        		my $transactions = $ticket->Transactions;
			while (my $transaction  = $transactions->Next) {
				(my $date = $transaction->Created) =~ s/\s.*$//;
                		next unless ($transaction->TimeTaken);
				next unless ($date eq $day);
				$environment{$day}{$env} += $transaction->TimeTaken;
        		}
		}else{
			next;
		}
	}

	foreach my $date1 (keys %environment) {
		foreach my $enviro (sort keys %{ $environment{$date1} }) {
			my @endTime;
			my @endtime2;
			my $temp	  = $environment{$date1}{$enviro};
			my $temp2	  = $temp / 60;
			my @temp	  = split /\./, $temp2;
			$endTime[0]	  = $temp[0];
			$endTime[1]	  = $temp % 60;
			my @meantemp = split /\./, ($temp / $ticCount{$date1}{$enviro});
			# If the time divided by the number of tickets has a decimal
	                # value round up if that value is greater than
	                # 0.5.  This will give an even number of minutes to figure
	                # out the mean time with.
	               if ($meantemp[1]) {
	                        if ($meantemp[1] >= 5) {
	                                $meantemp[0]++;
	                        }
	                }
	                my @meantime  = split /\./, ($meantemp[0] / 60);
	                $endtime2[0]  = $meantime[0];
	                $endtime2[1]  = $meantemp[0] % 60;
			my $endTime   = sprintf '%d:%02d', @endTime[0,1];
			my $mean      = sprintf '%d:%02d', @endtime2[0,1];
			printf TIMESHEET "%18s%6s%8s%11s\n", $enviro, $ticCount{$date1}{$enviro}, $endTime, $mean;
		}
	}
}

close TIMESHEET;

exit;

--------------000108090907030800060105--
0
theillien
6/17/2007 5:36:31 AM
perl.beginners 29381 articles. 4 followers. Follow

2 Replies
686 Views

Similar Articles

[PageSpeed] 56

On 06/17/2007 12:36 AM, Mathew Snyder wrote:
> [...]
> In the debugger I've set the 'w' command to watch the variable containing the
> day being looked for ($day).  I would have thought $day stays the same throught
> an iteration of the while loop but the debugger keeps stopping to tell me it
> switched from '2007-06-15' (for instance) to ''.  I then continue and it tells
> me it switched back from '' to '2007-06-15'.  Is it supposed to do that?
> Shouldn't the $day variable remain constant?
> [...]

The variable $day on line 50 is restricted to the scope of the for loop. 
I suspect that $day becomes empty or undefined when execution goes into 
a subroutine who's scope is outside of the for loop.



0
mumia
6/17/2007 7:51:12 AM
Mumia W. wrote:
> On 06/17/2007 12:36 AM, Mathew Snyder wrote:
>> [...]
>> In the debugger I've set the 'w' command to watch the variable
>> containing the
>> day being looked for ($day).  I would have thought $day stays the same
>> throught
>> an iteration of the while loop but the debugger keeps stopping to tell
>> me it
>> switched from '2007-06-15' (for instance) to ''.  I then continue and
>> it tells
>> me it switched back from '' to '2007-06-15'.  Is it supposed to do that?
>> Shouldn't the $day variable remain constant?
>> [...]
> 
> The variable $day on line 50 is restricted to the scope of the for loop.
> I suspect that $day becomes empty or undefined when execution goes into
> a subroutine who's scope is outside of the for loop.
> 
> 
> 
> 

That actually makes sense.  It hadn't occurred to me that it would be
reinitialized during each iteration.

Thanks
Mathew
--
Keep up with me and what I'm up to: http://theillien.blogspot.com
0
theillien
6/17/2007 8:21:26 AM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

how to specify 'near to' value and 'from-to' value
Hi, I have a property search  with a ability to enter minimum and maximum price and also a sq. m. area size. How do I implement this in my sql query  - 'from-to' value and 'near to' value ThanksAndy Current project: Cycle round the world  Hi,you could use the BETWEEN statement. SELECT PropertyName, Price WHERE Price BETWEEN 100 AND 500  for your "NEAR TO" search you also could use the BETWEEN statement. SELECT PropertyName, Price WHERE Price BETWEEN @SearchValue - 100 AND @SearchValue + 100 Hope this helps :-) ...

Why 'and' not '&&' ? (was Cleaning up 'uninitialized value')
> Use: > > if (@ARGV and -T $ARGV[0]) { ... } Just wondering if there is a reason for using the lower precedence 'and' here instead of '&&'? I haven't been finding many uses for 'and' which tells me I might not fully understand it. Thanks, Peter C. On May 30, Peter Cornelius said: >> if (@ARGV and -T $ARGV[0]) { ... } > >Just wondering if there is a reason for using the lower precedence 'and' >here instead of '&&'? I haven't been finding many uses for 'and' which >tells...

ObjectDataSource 'odsUser' has no values to insert. Check that the 'values' dictionary contains values
Hi All! I am currently trying to pull 2 values from two different sources (Details View & a Session) to use in a Stored Proceedure.  I have spent quite a bit of time trying to determine what is occuring without any luck. However, by the Subject Line you can tell that it's not getting anything for some reason?  Here are the components:Object Datasource:<asp:ObjectDataSource ID="odsUser" runat="server" DataObjectTypeName="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************]]"DeleteMethod="RemoveEnrollment...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

why a string column with a '' value synchronize from ASE to ASA, in ASA it's value become ' ' with a blank in it?
"darcy.zhai" <zhaizy@e-future.com.cn> wrote in news:43967064@forums-2-dub of sybase.public.sqlanywhere.mobilink: Please try to ask your question in the _body_ of the post, not the subject line. There are many people that never really look at the subject line (like myself most of the time). > why a string column with a '' value synchronize from ASE to ASA, in > ASA it's value become ' ' with a blank in it? This has to do with nullability. First, connect to ASE via ISQL and try the same query ML is executing. What is returned? An...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated ...

RGB values of 'Transparent' and 'ButtonFace'
Hi, I want to dynamicaly change the colorvalues of some controls. But what are the color or RGB-values of 'Transparent','ButtonFace' and this colors like 'Mint','Sky' and 'Cream'???? Is there any way to get these colors? Roy Bungert /* COLOURS RGB coded */ constant long BUTTONFACE = 78682240 constant long WINDOW_BACKGROUND = 1087434968 constant long WINDOW_TEXT = 33554592 constant long APPLICATION_WORKSPACE = 268435456 constant long TRANSPARENT = 553648127 constant long DEFAULT_REQUIREDCOLOR = RGB(255, 255, 230) constan...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

'b'..'a'
Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

Web resources about - value of variable switches from ' ' to 'value' - perl.beginners

Resources last updated: 11/25/2015 3:38:10 AM