Home > Archive > PERL Beginners > April 2004 > erorr with "use constant"
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
erorr with "use constant"
|
|
| DBSMITH@OhioHealth.com 2004-04-27, 3:41 pm |
| Can any provide some help?
I am getting this error:
edm01:/usr/local/bin/perl>> perl -c tape_rotation_vaulting.pl
String found where operator expected at tape_rotation_vaulting.pl line 64,
near"
(Do you need to predeclare TWENTYONEDAYS_STRING?)
syntax error at tape_rotation_vaulting.pl line 64, near
"TWENTYONEDAYS_STRING ""
tape_rotation_vaulting.pl had compilation errors.
I want to be able to print the string "There are xxxxx seconds in 21 days"
xxxx would come from the constant TWENTYONEDAYS_STRING.
thanks!
## Set pragmas
# use strict;
# use diagnostics;
## Set variables
#my $twenty_one_days="/usr/local/log/21days.log";
#my $thiry_days="/usr/local/log/30days.log";
#my $ninety_one_days="/usr/local/log/91days.log";
my $default="/usr/local/log/edmdefault.log";
my $twenty_one_days_LnotesFS="/usr/local/log/LnotesFS.log";
my $lvimg_L_Drive="/usr/local/log/lvimg_L_Drive.log";
my $lvimg_K_Drive="/usr/local/log/lvimg_K_Drive.log";
my $lvimg_JI_Drives="/usr/local/log/lvimg_JI_Drives.log";
my $lvimg_GH_Drives="/usr/local/log/lvimg_GH_Drives.log";
my $lvimg_FE_Drives="/usr/local/log/lvimg_FE_Drives.log";
my $lvimg_DC_Drives="/usr/local/log/lvimg_DC_Drives.log";
## Below are SC clients
#my $idxsql="/usr/local/log/idxsql.log";
#my $ORBaplog="/usr/local/log/ORBaplog.log";
#my $ORBDsch="/usr/local/log/ORBDsch.log";
#my $ORBmodel="/usr/local/log/ORBmodel.log";
#my $ORBmsdb="/usr/local/log/ORBmsdb.log";
#my $ORBOHusr="/usr/local/log/ORBOHusr.log";
#my $ORBPo="/usr/local/log/ORBPo.log";
#my $ORBPr="/usr/local/log/ORBPr.log";
#my $ORB="/usr/local/log/ORB.log";
system ("clear");
## Epoch time == 21,30 and 91
## Define global constants
use constant TWENTYONEDAYS_STRING => 60 * 60 * 24 * 21;
use constant THIRTYDAYS_STRING => 60 * 60 * 24 * 30;
use constant NINETYONEDAYS_STRING => 60 * 60 * 24 * 91;
# use constant THIRTYDAYS_STRING => localtime(time + 2592000);
# use constant NINETYONEDAYS_STRING => localtime(time + 7862400);
&timing;
sub timing {
local $now_string = localtime;
print $now_string, "\n";
print "\n";
printf "There are ", TWENTYONEDAYS_STRING "seconds in 21 days"; print
"\n";
}
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
| |
| Wiggins D Anconia 2004-04-27, 4:43 pm |
|
>
> Can any provide some help?
> I am getting this error:
>
> edm01:/usr/local/bin/perl>> perl -c tape_rotation_vaulting.pl
> String found where operator expected at tape_rotation_vaulting.pl line
64,
> near"
> (Do you need to predeclare TWENTYONEDAYS_STRING?)
> syntax error at tape_rotation_vaulting.pl line 64, near
> "TWENTYONEDAYS_STRING ""
> tape_rotation_vaulting.pl had compilation errors.
>
I think this is misleading you and you actually need an operator.
>
> I want to be able to print the string "There are xxxxx seconds in 21 days"
> xxxx would come from the constant TWENTYONEDAYS_STRING.
>
> thanks!
>
> ## Set pragmas
>
> # use strict;
> # use diagnostics;
>
Commenting out the above prevents them from helping you... The first
should never need to be commented.
> ## Set variables
>
> #my $twenty_one_days="/usr/local/log/21days.log";
> #my $thiry_days="/usr/local/log/30days.log";
> #my $ninety_one_days="/usr/local/log/91days.log";
> my $default="/usr/local/log/edmdefault.log";
> my $twenty_one_days_LnotesFS="/usr/local/log/LnotesFS.log";
> my $lvimg_L_Drive="/usr/local/log/lvimg_L_Drive.log";
> my $lvimg_K_Drive="/usr/local/log/lvimg_K_Drive.log";
> my $lvimg_JI_Drives="/usr/local/log/lvimg_JI_Drives.log";
> my $lvimg_GH_Drives="/usr/local/log/lvimg_GH_Drives.log";
> my $lvimg_FE_Drives="/usr/local/log/lvimg_FE_Drives.log";
> my $lvimg_DC_Drives="/usr/local/log/lvimg_DC_Drives.log";
>
> ## Below are SC clients
>
> #my $idxsql="/usr/local/log/idxsql.log";
> #my $ORBaplog="/usr/local/log/ORBaplog.log";
> #my $ORBDsch="/usr/local/log/ORBDsch.log";
> #my $ORBmodel="/usr/local/log/ORBmodel.log";
> #my $ORBmsdb="/usr/local/log/ORBmsdb.log";
> #my $ORBOHusr="/usr/local/log/ORBOHusr.log";
> #my $ORBPo="/usr/local/log/ORBPo.log";
> #my $ORBPr="/usr/local/log/ORBPr.log";
> #my $ORB="/usr/local/log/ORB.log";
>
>
> system ("clear");
Know why this may or may not work...
>
> ## Epoch time == 21,30 and 91
>
> ## Define global constants
>
> use constant TWENTYONEDAYS_STRING => 60 * 60 * 24 * 21;
> use constant THIRTYDAYS_STRING => 60 * 60 * 24 * 30;
> use constant NINETYONEDAYS_STRING => 60 * 60 * 24 * 91;
>
> # use constant THIRTYDAYS_STRING => localtime(time + 2592000);
> # use constant NINETYONEDAYS_STRING => localtime(time + 7862400);
>
>
> &timing;
>
Drop the ampersand until you know why you need it.
timing();
Is preferred.
> sub timing {
> local $now_string = localtime;
Use lexicals instead of locals until you know why you shouldn't.
my $now_string = localtime;
> print $now_string, "\n";
> print "\n";
> printf "There are ", TWENTYONEDAYS_STRING "seconds in 21 days";
perldoc -f printf
printf takes a format followed by optional parameters to be dropped into
that format, you don't need it here.
print "There are " . TWENTYONEDAYS_STRING . "seconds in 21 days";
Should work. I believe your error is caused because you are missing a
comma after the constant.
HTH,
http://danconia.org
| |
| DBSMITH@OhioHealth.com 2004-04-27, 6:49 pm |
| why not use & for a function call? Aren't & and ( ) the same?
I used local originally b/c I wanted to use this globally from within the
function. Is there a preferred way to use local?
thanks
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
"Wiggins d Anconia" <wiggins@danconia.org>
04/27/2004 03:06 PM
To: DBSMITH@OhioHealth.com, beginners@perl.org
cc:
Subject: Re: erorr with "use constant"
>
> Can any provide some help?
> I am getting this error:
>
> edm01:/usr/local/bin/perl>> perl -c tape_rotation_vaulting.pl
> String found where operator expected at tape_rotation_vaulting.pl line
64,
> near"
> (Do you need to predeclare TWENTYONEDAYS_STRING?)
> syntax error at tape_rotation_vaulting.pl line 64, near
> "TWENTYONEDAYS_STRING ""
> tape_rotation_vaulting.pl had compilation errors.
>
I think this is misleading you and you actually need an operator.
>
> I want to be able to print the string "There are xxxxx seconds in 21
days"
> xxxx would come from the constant TWENTYONEDAYS_STRING.
>
> thanks!
>
> ## Set pragmas
>
> # use strict;
> # use diagnostics;
>
Commenting out the above prevents them from helping you... The first
should never need to be commented.
> ## Set variables
>
> #my $twenty_one_days="/usr/local/log/21days.log";
> #my $thiry_days="/usr/local/log/30days.log";
> #my $ninety_one_days="/usr/local/log/91days.log";
> my $default="/usr/local/log/edmdefault.log";
> my $twenty_one_days_LnotesFS="/usr/local/log/LnotesFS.log";
> my $lvimg_L_Drive="/usr/local/log/lvimg_L_Drive.log";
> my $lvimg_K_Drive="/usr/local/log/lvimg_K_Drive.log";
> my $lvimg_JI_Drives="/usr/local/log/lvimg_JI_Drives.log";
> my $lvimg_GH_Drives="/usr/local/log/lvimg_GH_Drives.log";
> my $lvimg_FE_Drives="/usr/local/log/lvimg_FE_Drives.log";
> my $lvimg_DC_Drives="/usr/local/log/lvimg_DC_Drives.log";
>
> ## Below are SC clients
>
> #my $idxsql="/usr/local/log/idxsql.log";
> #my $ORBaplog="/usr/local/log/ORBaplog.log";
> #my $ORBDsch="/usr/local/log/ORBDsch.log";
> #my $ORBmodel="/usr/local/log/ORBmodel.log";
> #my $ORBmsdb="/usr/local/log/ORBmsdb.log";
> #my $ORBOHusr="/usr/local/log/ORBOHusr.log";
> #my $ORBPo="/usr/local/log/ORBPo.log";
> #my $ORBPr="/usr/local/log/ORBPr.log";
> #my $ORB="/usr/local/log/ORB.log";
>
>
> system ("clear");
Know why this may or may not work...
>
> ## Epoch time == 21,30 and 91
>
> ## Define global constants
>
> use constant TWENTYONEDAYS_STRING => 60 * 60 * 24 * 21;
> use constant THIRTYDAYS_STRING => 60 * 60 * 24 * 30;
> use constant NINETYONEDAYS_STRING => 60 * 60 * 24 * 91;
>
> # use constant THIRTYDAYS_STRING => localtime(time + 2592000);
> # use constant NINETYONEDAYS_STRING => localtime(time + 7862400);
>
>
> &timing;
>
Drop the ampersand until you know why you need it.
timing();
Is preferred.
> sub timing {
> local $now_string = localtime;
Use lexicals instead of locals until you know why you shouldn't.
my $now_string = localtime;
> print $now_string, "\n";
> print "\n";
> printf "There are ", TWENTYONEDAYS_STRING "seconds in 21 days";
perldoc -f printf
printf takes a format followed by optional parameters to be dropped into
that format, you don't need it here.
print "There are " . TWENTYONEDAYS_STRING . "seconds in 21 days";
Should work. I believe your error is caused because you are missing a
comma after the constant.
HTH,
http://danconia.org
| |
| Wiggins D Anconia 2004-04-27, 7:54 pm |
| Please bottom post...
>
> why not use & for a function call? Aren't & and ( ) the same?
> I used local originally b/c I wanted to use this globally from within
the
> function. Is there a preferred way to use local?
>
& and () may not be the same, see
perldoc -q calling
I am not sure what you mean by "use this globally from within the
function". Remember that we only see a small portion of your code, from
what I have seen there is no reason to use local in this context.
'local' just tells Perl to restore the value of the variable after you
leave the current scope, which didn't seem to be needed in this context.
An excellent discussion of scoping can be found here:
http://perl.plover.com/FAQs/Namespaces.html
http://danconia.org
|
|
|
|
|