Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is the different...

Status
Not open for further replies.

broloc

Programmer
Jun 10, 2002
27
JP
could someone please tell me the different of these variable.
1. '=='
2. 'eq'
3. 'defined( a = b)'

i would be very appreciate if someone could help me.
 
Hi broloc,

1. '==' is Perl's NUMERIC comparison operator
Code:
  $num1 = 9;
  $num2 = 9;
  if ( $num1 == $num2 ) { ...do stuff; }

2. 'eq' Same as '==', but comparing STRINGS
Code:
  $string1 = "NAME";
  $string2 = "NAME";
  if ( $string1 eq $string2 ) { ...do stuff; }

If you use 'eq' on numeric values, or vice-versa, the return value will most likely not be what you expected. [wink]

3. ... ..confused by question...[wink] But 'defined' is generally used in an expression to check whether or not a variable has been 'defined', (i.e., is not a NUL value). So I guess
Code:
  if ( defined($a = $b)) { ..do stuff; }

would be checking to make sure the results of that expression evaluate to 'something' before it enters the if block... Not sure though. I've never tried it [smile] Notorious P.I.G.
 
i have one problem...my script cannot compare the local time with the time that user give.here is my coding:

#!/usr/local/bin/perl

$time = 0;
open(FILE,'readme.txt')||die$!;
$realtime = <FILE>;

while (defined($realtime != $time) ) {
open(FILE,'readme.txt')||die$!;
$realtime = <FILE>;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time + (3600*$timeoffset));

@days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
@months = qw(1 2 3 4 5 6 7 8 9 10 11 12) ;
$year = $year + 1900;

$time= &quot;$mday/$months[$mon]/$year&quot;;
print &quot;$time\n&quot;;
if ($realtime eq $time) {
print &quot; this is the time....running schedule\n&quot;;
open(HANDLE,'config.dat')||die$!;
$data = <HANDLE>;
$mday = $mday + $data;
if ( $mday > 365) {
$year = ($data / 365) + $year;
$mday = $mday - $data;
}
elsif ($mday > 31) {
while ( $mday > 31) {
$mday = $mday - 31;
$months[$mon] = $months[$mon] + 1;
if ($months[$mon] > 12 ) {
$months[$mon] = $months[$mon] - 12;
$year = $year + 1;
}
}
}
$realtime = &quot;$mday/$months[$mon]/$year&quot;;
open(FILE,'>readme.txt')||die$!;
print &quot;$realtime\n&quot;;
print FILE &quot;$mday/$months[$mon]/$year&quot;;
close FILE;
exit;
}
else {
print &quot;this is not the time to run any program\n&quot;;
open(FILE,'readme.txt')||die$!;
$data = <FILE>;
print &quot;the next program will be run on &quot;;
print &quot;$data\n&quot;;
sleep(10);
}
}

could someone tell me what is wrong with this coding....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top