instance of class into sub?

G

gep

How can i put cgi instance into sub?
i have main cgi script:
#!/usr/bin/perl -w
use CGI;
use strict;
use makepage;
....
my $cg=new CGI;
....
makepage->printhead($cg);
....


In makepage.pm is:
printhead {
my $cg={};
bless $cg, "CGI";
... #it is nice, e.g. $cg->url is OK, but whenever i try $cg->param,
it is empty
}

Don't anybody know, what to do whit this, many thanx, J. Slaby.
 
P

Paul Lalli

How can i put cgi instance into sub?
i have main cgi script:
#!/usr/bin/perl -w
use CGI;
use strict;
use makepage;
...
my $cg=new CGI;
...
makepage->printhead($cg);
...


In makepage.pm is:
printhead {
my $cg={};
bless $cg, "CGI";
... #it is nice, e.g. $cg->url is OK, but whenever i try $cg->param,
it is empty
}

Don't anybody know, what to do whit this, many thanx, J. Slaby.

You need to read or re-read perldoc perlsub.

First, you didn't declare the subroutine correctly, in that you forgot the
keyword sub. From your statement that "it is nice", I have to assume you
have actual working code somewhere. Please read the posting guidelines
that are posted to this group once a week. They will tell you to post
complete but short scripts that illustrate your problem, and to copy and
paste your code, rather than retype it. That being said, let's move on.

Within your subroutine, you are declaring a new lexical variable $cg. You
are then making this new lexical variable a CGI object. This object has
absolutely nothing to do with the $cg that you passed into the subroutine.
What you want to do is access the variable that you passed in. This is
known as a subroutine argument. Subroutine arguments are passed in via
the @_ array. So within your function:

sub printhead {
my $newcg = $_[0];
my $text = $newcg->param('textfield'); #for example
#...
}

You could call this $newcg any name you want, including $cg. But it
doesn't have anything to do with the original $cg unless you assign it
back to the variable you passed in, as I did by assigning to $_[0].

Again, please make sure you read
perldoc perlsub
to understand more about how subroutine arguments work.

Hope this helps,
Paul Lalli
 
G

Gunnar Hjalmarsson

Paul Lalli wrote in comp.lang.perl.misc:
Please read the posting guidelines that are posted to this group
once a week. They will tell you to post complete but short scripts
that illustrate your problem, and to copy and paste your code,
rather than retype it.

And to not multi-post.
 
A

Anno Siegel

gep said:
I sent it to 2 different newsgroups, it's ok, i think. No, i know it.

No, you don't. It's not about the number of newsgroups (that is a
concern too, if they're many), it's about the way newsreaders treat
your posting.

Is there a reason why everybody who has read your posting in one of
the groups *must* also see it in the other? If not, multi-posting
is wrong and crossposting is right.

Anno
 
P

Paul Lalli

I sent it to 2 different newsgroups, it's ok, i think. No, i know it.

No one's complaining that you sent to 2 different newsgroups. They're
complaining about the *method* in which you did so. The method you used
is called "multi-posting". This means sending one message to one group,
and then sending a copy of that message to another group. This is
considered rude. The reason is that many people use mail readers which
download messages from multiple groups at a time. Because of what you
did, they saw your message twice for no reason.

The correct method is called "cross-posting". This means sending one
message to both groups. This is usually done by specifiying both groups
on the "Newsgrps:" header (analagous to To: in emails), separated by
commas. Using this method, your message will be sent to both groups, with
the same message id. Mail readers will recognize the same id, and only
download the message once. This saves time, bandwidth, and effort on all
concerned.

Please do a google search for "multipost crosspost" and you'll see several
references to the topic. Please also check out the posting guidelines I
mentioned previously.

Thank you,
Paul Lalli
 
E

Eric Bohlman

No one's complaining that you sent to 2 different newsgroups. They're
complaining about the *method* in which you did so. The method you
used is called "multi-posting". This means sending one message to one
group, and then sending a copy of that message to another group. This
is considered rude. The reason is that many people use mail readers
which download messages from multiple groups at a time. Because of
what you did, they saw your message twice for no reason.

Actually, that's one of the smaller parts of the reason. The biggest part
of the reason is that someone reading the followups to a multi-posted
message has to read several groups, not just one, in order to see them all.
If, say, a message is multi-posted to comp.lang.perl.misc and
comp.lang.perl.modules (as the original was), then someone reading
c.l.p.misc won't see any of the responses in c.l.p.modules, at least not
until he reads the latter group (if he in fact does).

Why is that rude? Because the person reading c.l.p.misc might very well
take the time to post a response and then, upon going to c.l.p.modules,
discover that someone else posted essentially the same response there. So
the first person has wasted his time answering a question that's already
been answered. If the message had been crossposted, he'd have quickly seen
that the question had already been answered and not bothered to post a
redundant response.

Multi-posting fragments threads that should be kept together, leading to
duplication of effort and in many cases inadequate peer review of
responses.
 
P

Paul Lalli

Actually, that's one of the smaller parts of the reason. The biggest part
of the reason is that someone reading the followups to a multi-posted
message has to read several groups, not just one, in order to see them all.
If, say, a message is multi-posted to comp.lang.perl.misc and
comp.lang.perl.modules (as the original was), then someone reading
c.l.p.misc won't see any of the responses in c.l.p.modules, at least not
until he reads the latter group (if he in fact does).

I stand better informed. Much obliged.

Paul Lalli
 
G

gep

Paul said:
No one's complaining that you sent to 2 different newsgroups. They're
complaining about the *method* in which you did so. The method you used
is called "multi-posting". This means sending one message to one group,
and then sending a copy of that message to another group. This is
considered rude. The reason is that many people use mail readers which
download messages from multiple groups at a time. Because of what you
^^^^^^^^^^^^^^^^^ and what? i do so too.
did, they saw your message twice for no reason.
But there was a reason. Not all the people read both newsgroups and
because i want to know more about it and receive answer fro mmore
people, i posted it into 2 diff groups (not 2, but 4 i think). If u
can't understand it, its only your problem, not mine.
 
G

gep

Eric said:
Actually, that's one of the smaller parts of the reason. The biggest part
of the reason is that someone reading the followups to a multi-posted
message has to read several groups, not just one, in order to see them all.
If, say, a message is multi-posted to comp.lang.perl.misc and
comp.lang.perl.modules (as the original was), then someone reading
c.l.p.misc won't see any of the responses in c.l.p.modules, at least not
until he reads the latter group (if he in fact does).

Why is that rude? Because the person reading c.l.p.misc might very well
take the time to post a response and then, upon going to c.l.p.modules,
discover that someone else posted essentially the same response there. So
the first person has wasted his time answering a question that's already
been answered. If the message had been crossposted, he'd have quickly seen
that the question had already been answered and not bothered to post a
redundant response.
I dont think so, because he will help people, who read only one of the
newsgs. The same situation could appear, when somebody writes sth. and
then he posts it and then he finds out, that the same answer is there
yet, because sb else...
 
T

Tore Aursand

But there was a reason. Not all the people read both newsgroups and
because i want to know more about it and receive answer fro mmore
people, i posted it into 2 diff groups (not 2, but 4 i think). If u
can't understand it, its only your problem, not mine.

Listen: It's _you_ who doesn't understand the important difference
between 'multiposting' and 'crossposting'. _Do_ you know the difference
or not?

Please read Paul's answer to understand the difference (quoted in this
post, as well).
 
P

Paul Lalli

Eric Bohlman wrote:
I dont think so, because he will help people, who read only one of the
newsgs. The same situation could appear, when somebody writes sth. and
then he posts it and then he finds out, that the same answer is there
yet, because sb else...


You're still not getting this. Go read my original reply again. We're
not telling you not to post to more than one group. We're telling you to
send ONE message to BOTH groups, rather than TWO messages, one to EACH
group. Do you see the difference? Using the method we're telling you,
anyone who reads only one of the groups (like me) will still see the
message. And as Eric pointed out, when you use this method, I will be
able to see that the message was sent to both groups, even though I'm only
reading one. Therefore when I reply, my answer can go to both groups too,
rather than only one group. That way everyone can see it.

Do you understand yet?

Paul Lalli
 
P

Paul Lalli

^^^^^^^^^^^^^^^^^ and what? i do so too.
But there was a reason. Not all the people read both newsgroups and
because i want to know more about it and receive answer fro mmore
people, i posted it into 2 diff groups (not 2, but 4 i think). If u
can't understand it, its only your problem, not mine.

I very much disagree. This is your problem, because if you choose to
continue to ignore the rather polite requests you are receiving to behave
appropriately in a news group, very few people will be willing to help you
in the future. This is standard Usenet proticol. If you don't want to
follow it, that's your choice. But try to remember there is nothing
forcing anyone to help you or answer your questions. If you don't want to
play by the rules, why should we spend our time to help you?

Paul Lalli
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I dont think so, because he will help people, who read only one of the
newsgs. The same situation could appear, when somebody writes sth. and
then he posts it and then he finds out, that the same answer is there
yet, because sb else...

When you appropriately crosspost, everyone who reads *at least one*
of the newsgroups will see the message, and (crossposted) answers, exactly
once. When you multipost, everyone who reads n of the multiposted
newsgroups will see the message n times. That's fine for those whom
n==1, but increasinly irritating for those when n>1.

So, if you feel you must reach multiple newsgroups, crosspost. If you
don't know how to crosspost, *don't* multipost (making one post in one
group, then making the same or similar post in another). If you do
multipost, expect an exponentially decreasing amount of help from people
who read more than one of the groups to which you post.

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFA0fPChVcNCxZ5ID8RAv6lAJ9xFhLEa+U7SVqo7eOnRagO6uCINgCdEMoo
kXrIoXmAXLU5mGAAcW9s+Lg=
=qG7V
-----END PGP SIGNATURE-----
 
J

Joe Smith

gep said:
But there was a reason. Not all the people read both newsgroups and
because i want to know more about it and receive answer fro mmore
people, i posted it into 2 diff groups (not 2, but 4 i think). If u
can't understand it, its only your problem, not mine.

What you have described is a valid reason for posting a single message
that will show up in two or more groups. It's called "cross posting".

What you did was not cross posting. Instead, you posted two independent
messages to two different newsgroups. The proper thing to do is to
post one message to two (or four) newsgroups simulaneously.

Do you know how to post a single message to multiple groups simultaneously?
If you don't, you need to learn how.

Do you understand what I'm saying?
-Joe
 

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,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top