specifying use strict

G

g3000

Hello,
I have the following code:
use strict;
use warnings;
use Cwd;
use Math::Random;
our $curr = 'C:\\BackupSamsDB\export\samsdb9877333771';
our $configtime = localtime();
our $ORAHOME = 'C:\oracle\ora81\bin';
our $ORASID = 'SAMSDB';
our $dblocation = 'c:\oracle\oradata\samsdb';
our $backupid = 'samsdb9877333771';
our $lstBackupLoc;
sub getRepository()
{
my $display = shift || 1;
if ( -e 'backupRepository.conf' and $display )
{
open (CONFREP, "< backupRepository.conf");
undef $/;
eval <CONFREP>;
close CONFREP;
for my $bkpID ( keys %rep )
{
print "This is the time: $rep{$bkpID}->{TIMESTAMP}";
$lstBackupLoc = $rep{$bkpID}->{BACKUP_LOCATION};
$ORAHOME = $rep{$bkpID}->{ORAHOME};
$ORASID = $rep{$bkpID}->{ORASID};
$dblocation = $rep{$bkpID}->{DBFILES};
}

} #END IF
else
{
writeToRepository();
}#end else
}#end getRepository
sub writeToRepository()
{
use Data::Dumper;
$Data::Dumper::purity = 1;
if (!(-e 'backupRepository.conf'))
{

my %rep = ($backupid => {
TIMESTAMP => $configtime,
SERVER => "bc12025",
BACKUP_LOCATION => $curr,
ORAHOME => $ORAHOME,
ORASID => $ORASID,
DBFILES => $dblocation
}
);
open (CONFREP, "> backupRepository.conf");
print CONFREP Data::Dumper->Dump([\%rep], ['*rep']);
close CONFREP;
}#end if
else
{
my $bid = 'samsdb9432164421';
open (CONFREP, "< backupRepository.conf");
undef $/;
eval <CONFREP>;
close CONFREP;
$rep{$bid} = {TIMESTAMP => $configtime,
SERVER => "SAMSDEV",
BACKUP_LOCATION => $curr,
ORAHOME => $ORAHOME,
ORASID => $ORASID,
DBFILES => $dblocation
};
open (CONFREP, "> backupRepository.conf");
print CONFREP Data::Dumper->Dump([\%rep], ['*rep']);
close CONFREP;
}#end if
}#END writeToRepository

getRepository();
which gives me the following:
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 20.
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 22.
Global symbol "$lstBackupLoc" requires explicit package name at
c:\wip\pdb.pl line 24.
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 24.
Global symbol "$bkpID" requires explicit package name at c:\wip\pdb.pl
line 24.
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 25.
Global symbol "$bkpID" requires explicit package name at c:\wip\pdb.pl
line 25.
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 26.
Global symbol "$bkpID" requires explicit package name at c:\wip\pdb.pl
line 26.
Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
line 27.
Global symbol "$bkpID" requires explicit package name at c:\wip\pdb.pl
line 27.
BEGIN not safe after errors--compilation aborted at c:\wip\pdb.pl line
36.

why is it when I comment out use strict I dont get the above errors?

If it is in a doc somewhere can u post the link so I can read for
myself?
Thank you.
 
P

Paul Lalli

g3000 said:
Hello,
I have the following code:
which gives me the following:

why is it when I comment out use strict I dont get the above errors?

If it is in a doc somewhere can u post the link so I can read for
myself?

Have you read the documentation for strict itself?
type:
perldoc strict
from your command line. Look at the section labeled "strict vars"

Paul Lalli
 
U

Uri Guttman

g> use strict;
g> use warnings;
g> use Cwd;
g> use Math::Random;
g> our $curr = 'C:\\BackupSamsDB\export\samsdb9877333771';
g> our $configtime = localtime();
g> our $ORAHOME = 'C:\oracle\ora81\bin';
g> our $ORASID = 'SAMSDB';
g> our $dblocation = 'c:\oracle\oradata\samsdb';
g> our $backupid = 'samsdb9877333771';
g> our $lstBackupLoc;

why are those package globals (which is what our declares)? use my.

g> sub getRepository()

why the ()? do you know what that does and why it is not usually wanted
nor needed?
g> {
g> my $display = shift || 1;
g> if ( -e 'backupRepository.conf' and $display )
g> {
g> open (CONFREP, "< backupRepository.conf");

always handle failures from open.

g> undef $/;

that is going to affect all other file handles. localize it. better yet
use File::Slurp from cpan

g> eval <CONFREP>;

g> close CONFREP;

g> for my $bkpID ( keys %rep )
g> {

g> print "This is the time: $rep{$bkpID}->{TIMESTAMP}";
g> $lstBackupLoc = $rep{$bkpID}->{BACKUP_LOCATION};
g> $ORAHOME = $rep{$bkpID}->{ORAHOME};
g> $ORASID = $rep{$bkpID}->{ORASID};
g> $dblocation = $rep{$bkpID}->{DBFILES};

fix your indenting. or if it is ok, use a better newsreader that doesn't
screw up white space.

g> }

g> if (!(-e 'backupRepository.conf'))

unless is better there.

g> {

g> }#end if

with clean indenting, it is rare that you need to mark end of block

g> else
g> {
g> my $bid = 'samsdb9432164421';
g> open (CONFREP, "< backupRepository.conf");
g> undef $/;

remember the time before when you did that? it is still undef. again,
File::Slurp is cleaner and faster and safer.

and you should factor out this load config stuff to a sub or use one of
the many config modules on cpan.


g> getRepository();
g> which gives me the following:
g> Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
g> line 20.
g> Global symbol "%rep" requires explicit package name at c:\wip\pdb.pl
g> line 22.

you never declare %rep but you use it as $rep{foo}.

g> why is it when I comment out use strict I dont get the above errors?

because that is what strict is for. it forces you to properly declare
all variables before you use them.

uri
 
G

g3000

Thanks all for the reply.

Uri,
I thought that when I opened the file with my hash in it using
eval <'my file handle here'>
that it would bring %rep "into" my code?
Obviously that is not doing that.
Should I give my config file a package name in the begining?
Like
package restoreconfig;
%rep = ( blah, ........);

Other responses........
No I dont know what the '()' does after the
subroutine name
guess I should research it.

I would look at File::Slurp why is it better and
cleaner?

I will change if ( ! (-e 'backupRepository.conf') )
to unless

I dont know what a newsreader is ( dont think I used
one )

I use our because some of those scalars I need to be
global to
the package not to the subroutines.
The code I posted here is just to test it out, it (
the two subs ) will
be used in another script where I want to be able to
know what
certain variables are at anytime during the program.
I changed them from my to our to make sure I could
see them.

As obvious I am a novice Perl user but outside my
power I had
to teach myself Perl under time constraints.
Need to find a good Perl book for after hours and
learn more
details instead of winging it.
Thanks again for your time and comments.
 
J

jkeen_via_google

g3000 said:
Thanks all for the reply.


As obvious I am a novice Perl user but outside my
power I had
to teach myself Perl under time constraints.
Need to find a good Perl book for after hours and
learn more
details instead of winging it.

1. Many of us are originally self-taught in Perl, so no problem there.
2. Purchase and work through "Learning Perl," 3rd ed., Randal L
Schwartz & Tom Phoenix (O'Reilly) -- or other Perl books recommended
here: http://learn.perl.org.
3. Acquaint yourself with the posting guidelines for
comp.lang.perl.misc. They are regularly posted on this list and are
also available at
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html.
Following the guidelines therein will (a) win you respect on this list
for doing so; and (b) help train you to diagnose your Perl problems
prior to posting.
4. Also, there are a number of good mailing lists for Perl beginners,
including http://groups.yahoo.com/group/perl-beginner/ and the
beginners list at learn.perl.org.
 
S

Sherm Pendley

g3000 said:
No I dont know what the '()' does after the
subroutine name
guess I should research it.

Have a look at "perldoc perlsub" - especially the section about prototypes.
I dont know what a newsreader is ( dont think I used
one )

You know about "regular" email apps like Outlook Express or Eudora,
right? And how some services like Hotmail provide a web-based interface
to their email service?

The same thing is true of news groups. Google groups is just a web-based
interface to Usenet - and not a very good one at that. It's gotten worse
recently, mangling spacing in posts - that might be where your indenting
went. Google groups is really useful for searching the archives; it's
much less so for posting new messages.

Check your provider's support pages for info about Usetnet or NNTP
access. There are a variety of news readers you can use - OE, Mozilla,
Thunderbird, Emacs, Agent, PAN, etc. You could even write your own with
Net::NNTP if you felt like it.
Need to find a good Perl book

Have a look at <http://learn.perl.org> for recommendations regarding
books and online material.

sherm--
 
U

Uri Guttman

g> Thanks all for the reply.
g> Uri,
g> I thought that when I opened the file with my hash in it using
g> eval <'my file handle here'>

i would read it into a scalar and eval it. that way you can print out
what you read for debugging. but as i said you are doing work you don't
have to do. search cpan for config modules. and if you must roll your
own, isolate it into a sub so you can debug it. do it step by step. open
the file (and handle failures), slurp it in. eval it. return the structure.

g> Other responses........
g> No I dont know what the '()' does after the
g> subroutine name
g> guess I should research it.

yep.

g> I would look at File::Slurp why is it better and
g> cleaner?

because it is faster, cleaner, safer. that is why i wrote it.

g> I dont know what a newsreader is ( dont think I used
g> one )

then how did you post here? your header say you are using google groups
which is your newsreader (web based).

g> I use our because some of those scalars I need to be
g> global to
g> the package not to the subroutines.

that makes little sense. first, you should be passing those values as
args instead of package globals. second, if they must be outside subs,
they should be my which will make the file scoped and not global.

g> The code I posted here is just to test it out, it (
g> the two subs ) will
g> be used in another script where I want to be able to
g> know what
g> certain variables are at anytime during the program.
g> I changed them from my to our to make sure I could
g> see them.

my allows that but it is bad style to use more globalness than you
need.

g> As obvious I am a novice Perl user but outside my
g> power I had
g> to teach myself Perl under time constraints.
g> Need to find a good Perl book for after hours and
g> learn more
g> details instead of winging it.

learn.perl.org is your friend. there is a free decent book on that
site. you can't code stuff like this without knowing some
basics. otherwise you are just cutting and pasting and guessing.

uri
 
G

g3000

Thanks Uri.

I downloaded your module.

Unzipped it to C:\Perl\lib ( just the Slurp.pm, slurp_article and
slurp_bench files)

That path is in @INC.

But perl says it cant find it.
Can't locate File/Slurp.pm in @INC (@INC contains: C:\Perl\lib
.....<snip>

C:\Perl\lib is the first path in @INC.
I also have C:\Perl\lib\File-Slurp-9999.06 folder.

Any ideas?
 
S

Sherm Pendley

g3000 said:
I downloaded your module.

Unzipped it to C:\Perl\lib

That's not how the docs say to install modules.

Have a look at "perldoc perlmodinstall".

sherm--
 
M

Matt Garrish

Sherm Pendley said:
That's not how the docs say to install modules.

Have a look at "perldoc perlmodinstall".

It's not the most useful perldoc if you're running Perl on Windows. It
assumes your options are ppm or make, without ever really explaining what
ppm is (or that Indigo Perl exists and has its own package manager).

Matt
 
G

g3000

I usually use active states ppm3 but I couldnt find a .ppd file that
was for the latest version of File::Slurp.
Ill look again. The one active state has is from Nov 2001.
 
A

A. Sinan Unur

I usually use active states ppm3 but I couldnt find a .ppd file that
was for the latest version of File::Slurp.
Ill look again. The one active state has is from Nov 2001.

Then you are doing something wrong:

ppm> s slurp
Searching in Active Repositories
1. File-Slurp [9999.06] Efficient Reading/Writing of Complete Files
2. File-Slurp [2004.0904] Read and write files with a single command
3. File-Slurp [9999.01] Efficient Reading/Writing of Complete Files
4. File-Slurp [9999.02] Efficient Reading/Writing of Complete Files
5. File-Slurp [9999.04] Efficient Reading/Writing of Complete Files
6. File-Slurp [9999.06] Efficient Reading/Writing of Complete Files

ppm> rep
Repositories:
[1] ActiveState PPM2 Repository
[2] ActiveState Package Repository
[3] Autonamed 1


Sinan
 
G

g3000

This is what I get also....
ppm> describe File-Slurp
====================
Name: File-Slurp
Version: 9999.06
Author: Uri Guttman ([email protected])
Title: File-Slurp
Abstract: Efficient Reading/Writing of Complete Files
Location: ActiveState PPM2 Repository
Available Platforms:
1. MSWin32-x86-multi-thread-5.8
====================
ppm>
 
A

A. Sinan Unur

This is what I get also....

Please quote some context as to what you are replying to.

Also, what is your point?

You complained:

Now you say you have the latest version:
ppm> describe File-Slurp
====================
Name: File-Slurp
Version: 9999.06
Author: Uri Guttman ([email protected])
Title: File-Slurp
Abstract: Efficient Reading/Writing of Complete Files
Location: ActiveState PPM2 Repository
Available Platforms:
1. MSWin32-x86-multi-thread-5.8
====================
ppm>

I ask again, what was the point of your post?
 
G

g3000

point was is that it was installed but perl was saying it was not
there.

the problem is resolved now.
 
J

Joe Smith

g3000 said:
I thought that when I opened the file with my hash in it using
eval <'my file handle here'>
that it would bring %rep "into" my code?

No, it will not bring %rep into scope during the compile phase.
The eval stuff isn't parsed until later, but compilation stops
before that.

Either put
my(%rep,$lstBackupLoc,$bkupID);
in front of the eval, or replace the whole CONFREP thing with
use 'backupRepository.conf';

-Joe
 
G

g3000

thanks joe

I changed my code to this as Uri recommended
( this is when the config file already exists )
$configtime = localtime;
$currBackupFolder = makeFileSystem();
%rep = ParseConfig (-ConfigFile => "backupRepository.conf");
$rep{$backup_id} = {TIMESTAMP => $configtime,
SERVER => "SAMSDEV",
BACKUP_LOCATION => $currBackupFolder,
ORAHOME => $ORAHOME,
ORASID => $ORASID,
DBFILES => $dblocation
};
SaveConfig("backupRepository.conf",\%rep);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top