variables problem

M

mike

I need to have some global variables and am having some trouble getting
them defined correctly.

key parts of my pgm looks like:

use strict:

my %files = ();

&do_something

#display the contents of the hash
foreach my $key ( sort keys %files )
{
print "$files{$key}{uid} $file_cand{$key}{fileid}\n";
}

sub do_something
{
$files{'frank'} = {uid=>'frank',fileid=>'12345'};
$files{'mark'} = {uid=>'mark',fileid=>'23456'};
}

In the sub do_something it is telling me I have to explicitly define
at:
$files{'frank'} = {uid=>'frank',fileid=>'12345'};

Isn't that defined when I defined the hash?

Mike
 
A

A. Sinan Unur

I need to have some global variables and am having some trouble
getting them defined correctly.

key parts of my pgm looks like:

What is the point of writing 'pgm' rather than 'program'?

I very much doubt key parts of your program look like, say,
use strict:

this.

Also,

use warnings;

missing.
my %files = ();

&do_something

Why are you using an ampersand here?

Where is the semi-colon?
#display the contents of the hash
foreach my $key ( sort keys %files )

Do you really need to sort the keys?
{
print "$files{$key}{uid} $file_cand{$key}{fileid}\n";
}

%file_cand is not defined.
sub do_something
{
$files{'frank'} = {uid=>'frank',fileid=>'12345'};
$files{'mark'} = {uid=>'mark',fileid=>'23456'};
}

In the sub do_something it is telling me I have to explicitly define
at:

What is telling you? Did perl give you an error or warning message?
$files{'frank'} = {uid=>'frank',fileid=>'12345'};

Isn't that defined when I defined the hash?

Huh?

Please post a short but *complete* script that still exhibits the
problem you are encountering. Instructions for how to put together an
inteligent post can be found in the posting guidelines for this group.

Sinan
 
P

Paul Lalli

mike said:
I need to have some global variables

Why? What makes you think you need globals? And furthermore, if your
question is about global variables, why are there no global variables
anywhere in your example script?
and am having some trouble getting them defined correctly.

key parts of my pgm looks like:

Please do not use lazy spelling. Not everyone here is a native English
speaker. I promise you won't get carpal-tunnel from typing the extra
r, o, r, and a.
use strict:

That's a syntax error. Please do not re-type your code. Copy and
paste it.

You are forgetting 'use warnings;'
my %files = ();

&do_something

That's a syntax error. Please do not re-type your code. Copy and
paste it.

Why are you using an ampersand there? Do you know what that does? If
not, remove it, and use
do_something();
instead.
#display the contents of the hash
foreach my $key ( sort keys %files )
{
print "$files{$key}{uid} $file_cand{$key}{fileid}\n";

That's a syntax error. Please do not re-type your code. Copy and
paste it.
}

sub do_something
{
$files{'frank'} = {uid=>'frank',fileid=>'12345'};
$files{'mark'} = {uid=>'mark',fileid=>'23456'};
}

In the sub do_something it is telling me I have to explicitly define
at:

Don't paraphrase warning and error messages. They are important. Copy
and paste the exact text of the error message.
$files{'frank'} = {uid=>'frank',fileid=>'12345'};

Isn't that defined when I defined the hash?

Perhaps one or more of the syntax errors noted above is the root cause
of your program. Without seeing the exact text of the message you
claim to have received, we cannot know for sure.

Correct all three errors, re-run your program, and copy & paste the
code AND error message if you still want assistance.

.... on second thought, before you do any of that, read the Posting
Guidelines for this group. They're posted here twice a week. Just
search for "Posting Guidelines".

Paul Lalli
 
M

mike

Perl Gurl ... Thank you very much.

In the past many of your forum experts ( so called ) always told me to
"use strict". If I didn't they cried.

It's probably those same experts that always "complain" about how a
post is made, or how stupid the poster must be, or they didn't dot the
i or cross the t.

Biggest bunch of babies I've ever seen.

What I was really trying to do is:
1) using strict define a global hash variable,
2) then update that hash in a subroutine,
3) print the contents of that hash when I return from the subroutine,
4) then calling another different subroutine and iterate over the hash
and do something else.

Thanks again. It's been awhile since I've been to this forum and now I
can remember why.

Mike
 
B

Brad Baxter

mike said:
Perl Gurl ... Thank you very much.

In my not so humble opinion, are you sure that
you are thanking the right person? Would you
rather have someone be nice and give you bad
advice, or be short (from your perspective) and
give you good advice?
In the past many of your forum experts ( so called ) always told me to
"use strict". If I didn't they cried.

I don't think you'll find anyone calling himself
a forum expert here. Except perhaps Ms. Gurl.
It's probably those same experts that always "complain" about how a
post is made, or how stupid the poster must be, or they didn't dot the
i or cross the t.

Biggest bunch of babies I've ever seen.

Not worth responding to. Even though I did. :)
What I was really trying to do is:
1) using strict define a global hash variable,
2) then update that hash in a subroutine,
3) print the contents of that hash when I return from the subroutine,
4) then calling another different subroutine and iterate over the hash
and do something else.

And did you not get a response?
Thanks again. It's been awhile since I've been to this forum and now I
can remember why.

Buck up. You can take it.

Regards,

Brad
 
A

A. Sinan Unur

Perl Gurl ... Thank you very much.

In the past many of your forum experts ( so called ) always told me to
"use strict". If I didn't they cried.

It's probably those same experts that always "complain" about how a
post is made, or how stupid the poster must be, or they didn't dot the
i or cross the t.

Biggest bunch of babies I've ever seen.

Enjoy your private dialog with PG.

*PLONK*

Sinan
 
S

Sherm Pendley

mike said:
Perl Gurl ... Thank you very much.

In the past many of your forum experts ( so called ) always told me to
"use strict". If I didn't they cried.

Oh, so you'd rather have warm fuzzies than accurate guidance?

OK, then, I guess I won't be helping you.

*plonk*

sherm--
 
E

Eric J. Roode

mike wrote:

(snipped)


Your code contains fatal syntax errors. Do not post fatally flawed code.


There is no need to use strict for such a simple script.

That may be true, but I'd wager that the OP needs all the help he can get
:)

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 

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
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top