Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   [xchat] fetching own text - $_[0] not a string? (http://www.velocityreviews.com/forums/t900123-xchat-fetching-own-text-_-0-not-a-string.html)

Vedran 09-30-2006 11:43 PM

[xchat] fetching own text - $_[0] not a string?
 
Hello,
I am writing an xchat script, here is the part of code making me problems:

IRC::add_command_handler("", "enc");
....
sub enc {
my $target = IRC::get_info(2);
my $input = $_[0];

# print "-$input-\n"; prints for eg. -bla-

but:
my $ciphertext = $cipher->encrypt($$input);
won't work

but if I write:
my $input = "bla";
my $ciphertext = $cipher->encrypt($$input);
then It works.

What is the difference betweek $input = $_[0] and $input = "bla" ?
Aren't those bot scalars?

How can I do the $_[0] to be the same type of other string?

Thanks Smile

PS. I've tried with $_[0][0] $$input and similar but they are all empty Sad

Paul Lalli 10-01-2006 01:19 AM

Re: fetching own text - $_[0] not a string?
 
Vedran wrote:
> Hello,
> I am writing an xchat script, here is the part of code making me problems:
>
> IRC::add_command_handler("", "enc");
> ...
> sub enc {
> my $target = IRC::get_info(2);
> my $input = $_[0];
>
> # print "-$input-\n"; prints for eg. -bla-
>
> but:
> my $ciphertext = $cipher->encrypt($$input);
> won't work


One would hope not. This is using a symbolic reference. You are
actually trying to pass the variable $bla into this method. Does such
a variable exist?

> but if I write:
> my $input = "bla";
> my $ciphertext = $cipher->encrypt($$input);
> then It works.


Then somewhere you defined a global variable $bla.

Please understand you should NOT be using symbolic references, and most
likely should not be using global variables either.

Please post a SHORT but COMPLETE script that demonstrates both the
"success" and "failure" cases, so that we can help you figure out how
to do your task correctly.

Paul Lalli


Bob Walton 10-01-2006 01:52 AM

Re: [xchat] fetching own text - $_[0] not a string?
 
Vedran wrote:
> Hello,
> I am writing an xchat script, here is the part of code making me problems:
>


You didn't show your complete script, but it is probable you didn't

use strict;
use warnings;

Let Perl give you all the help it can -- use these.

> IRC::add_command_handler("", "enc");
> ...
> sub enc {
> my $target = IRC::get_info(2);
> my $input = $_[0];
>
> # print "-$input-\n"; prints for eg. -bla-
>
> but:
> my $ciphertext = $cipher->encrypt($$input);

------------------------------------^^
This construction is known as a symbolic reference, and is generally a
BAD IDEA. That's why it won't work under use strict;, which you would
have found out if you had used it. Furthermore, symbolic references
only work with global variables, and will not function with lexical
variables. You fail to show whether $bla is global or lexical -- if
what you show "works", then $bla must be global.

> won't work


What exactly "won't work"? Does it generate an error? If so, what is
the error (exactly -- cut and paste it). What did you expect it to do,
and what exactly did it do? And why do you think that was wrong? Cite
the documentation that says it should do what you expected.

>
> but if I write:
> my $input = "bla";
> my $ciphertext = $cipher->encrypt($$input);
> then It works.


I'm not sure what you mean by "works". If everything else is the same,
it will give the same result regardless of how $input received the value
'bla'. Does $bla have the same value in both cases?

>
> What is the difference betweek $input = $_[0] and $input = "bla" ?
> Aren't those bot scalars?


There will be no difference if $_[0] has the string 'bla' as its value.

>
> How can I do the $_[0] to be the same type of other string?


Please rephrase -- that's gibberish.

>
> Thanks Smile
>
> PS. I've tried with $_[0][0] $$input and similar but they are all empty Sad


Don't just make stuff up. Read and understand the docs, use the debug
switch, etc.

If you show us a *complete* but *short and to-the-point* program that
illustrates your problem and that *anyone can copy/paste/run*, perhaps
someone could help. It would also be good if you stated what you are
really trying to accomplish. Why, for example, are attempting to use
symbolic references -- for what purpose -- any why wouldn't you use a
hash instead?

Have you read the posting guidelines for this newsgroup?

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

Vedran 10-01-2006 10:27 AM

Re: fetching own text - $_[0] not a string?
 
Thanks for helping me:
Ok, here is the complete script in the working and non working versions:

#===this will not work====
use strict;
use warnings;
use Crypt::CBC;
my $cipher = new Crypt::CBC('secret', 'DES');

IRC::print "Script loaded\n";
IRC::add_command_handler("", "crypt_all");

sub crypt_all
{
my $input = $_[0];
my $target = IRC::get_info(2);
IRC::print "To $target -$input-\n";
#-----^--- displays for eg. "To #tehend -bla-"

my $ciphertext = $cipher->encrypt($input);
#-------^--- fails with: Error in command callback input must be 8 bytes
long at C:/Perl/site/lib/Crypt/DES.pm line 57.

return 1;
}


#====the following will work=================
use strict;
use warnings;
use Crypt::CBC;
my $cipher = new Crypt::CBC('secret', 'DES');

IRC::print "Script loaded\n";
IRC::add_command_handler("", "crypt_all");

sub crypt_all
{
my $input = "bla";
my $target = IRC::get_info(2);
IRC::print "To $target -$input-\n";
#-----^--- displays "To #tehend -bla-"

my $ciphertext = $cipher->encrypt($input);
#-------^--- this time encrypt will work, I also tried to decrypt that
and works well :)

return 1;
}

Paul Lalli 10-01-2006 10:48 AM

Re: fetching own text - $_[0] not a string?
 
Vedran wrote:
> Thanks for helping me:


You can best show your appreciation by reading and following the
posting guidlines for this group. They are posted here twice a week.

Please stop top posting. Please start quoting a relevant portion of
the text to which you are replying to.

> Ok, here is the complete script in the working and non working versions:


That is a flat-out lie. These scripts are NOT complete. They do not
run on their own.

> #====the following will work=================


No, it will not.

> use strict;
> use warnings;
> use Crypt::CBC;
> my $cipher = new Crypt::CBC('secret', 'DES');
>
> IRC::print "Script loaded\n";
> IRC::add_command_handler("", "crypt_all");
>
> sub crypt_all
> {
> my $input = "bla";
> my $target = IRC::get_info(2);
> IRC::print "To $target -$input-\n";
> #-----^--- displays "To #tehend -bla-"
>
> my $ciphertext = $cipher->encrypt($input);
> #-------^--- this time encrypt will work, I also tried to decrypt that
> and works well :)
>
> return 1;
> }


String found where operator expected at clpm.pl line 6, near
"IRC::print "Script loaded\n""
(Do you need to predeclare IRC::print?)
String found where operator expected at clpm.pl line 14, near
"IRC::print "To $target -$input-\n""
(Do you need to predeclare IRC::print?)
syntax error at clpm.pl line 6, near "IRC::print "Script loaded\n""
syntax error at clpm.pl line 14, near "IRC::print "To $target
-$input-\n""
Execution of clpm.pl aborted due to compilation errors.

Which part of "complete" script was unclear to you?

Paul Lalli


Vedran 10-01-2006 10:58 AM

Re: fetching own text - $_[0] not a string?
 
Paul Lalli wrote:
> That is a flat-out lie. These scripts are NOT complete. They do not
> run on their own.

Of course, this is, as I mentioned in the subject of the first post, an
xchat perl script, you must run them from xchat to get it work :)

Paul Lalli 10-01-2006 11:02 AM

Re: fetching own text - $_[0] not a string?
 
Vedran wrote:
> Paul Lalli wrote:
> > That is a flat-out lie. These scripts are NOT complete. They do not
> > run on their own.

> Of course, this is, as I mentioned in the subject of the first post, an
> xchat perl script, you must run them from xchat to get it work :)


I have no idea what "xchat" is, nor do I care. This is a Perl
newsgroup. Post a SHORT but COMPLETE *Perl* scirpt which demonstrates
your error. Pare your script down to the shortest possible script
which still gives you an error. This should be a standard step you
take in ANY attempt at debugging.

Paul Lalli


Paul Lalli 10-01-2006 10:53 PM

Re: fetching own text - $_[0] not a string?
 
Mumia W. (reading news) wrote:
> On 10/01/2006 06:02 AM, Paul Lalli wrote:
> > Vedran wrote:
> >> Paul Lalli wrote:
> >>> That is a flat-out lie. These scripts are NOT complete. They do not
> >>> run on their own.

>
> They probably do run in the OP's environment.


..... which makes them not standalone complete scripts.

> Paul Lalli, I've valued your posts because you do know something about
> Perl, and you do help people. But you are constantly and needlessly
> obnoxious to people.


I like to think I'm obnoxious and rude only after a poster shows a
complete disregard for anything in my post that attempts to help him
help us help him. But I will take your opinion under consideration.

> *You* changed the subject line--removing the context of the OP's
> original post.


For what it's worth, not intentionally or manually. Google Groups
seems to have done that all on its own. Not sure why, and I didn't
even notice until you mentioned it. That doesn't remove my
responsibility for noticing, of course.

> His context was [xchat]. And /inside/ the OP's message,
> he specified that he was using a Perl-Xchat script, and that is a sign
> that people who are not using xchat need not respond.


I completely disagree with that assesment. The number of posts in this
group that claim their problem lays in one field when it really doesn't
upon reading the post is staggering.

> You could've either not responded or pointed him to the xchat newsgroup.


Again, never heard of xchat before, so I didn't realize it was anything
relevant to the user's post. Again, didn't see the word "xchat" in the
subject, because the idiotic news reader I'm using decided to strip it.

> But you had to be rude in your traditional way. I do have respect for
> you because you contribute a lot to the group, but I'm tired of the
> attitude. Goodbye.


I'm truly sorry you feel that way. Fare thee well.

Paul Lalli


Paul Lalli 10-01-2006 10:54 PM

Re: fetching own text - $_[0] not a string?
 
Mumia W. (reading news) wrote:
> On 10/01/2006 06:02 AM, Paul Lalli wrote:
> > Vedran wrote:
> >> Paul Lalli wrote:
> >>> That is a flat-out lie. These scripts are NOT complete. They do not
> >>> run on their own.

>
> They probably do run in the OP's environment.


..... which makes them not standalone complete scripts.

> Paul Lalli, I've valued your posts because you do know something about
> Perl, and you do help people. But you are constantly and needlessly
> obnoxious to people.


I like to think I'm obnoxious and rude only after a poster shows a
complete disregard for anything in my post that attempts to help him
help us help him. But I will take your opinion under consideration.

> *You* changed the subject line--removing the context of the OP's
> original post.


For what it's worth, not intentionally or manually. Google Groups
seems to have done that all on its own. Not sure why, and I didn't
even notice until you mentioned it. That doesn't remove my
responsibility for noticing, of course.

> His context was [xchat]. And /inside/ the OP's message,
> he specified that he was using a Perl-Xchat script, and that is a sign
> that people who are not using xchat need not respond.


I completely disagree with that assesment. The number of posts in this
group that claim their problem lays in one field when it really doesn't
upon reading the post is staggering.

> You could've either not responded or pointed him to the xchat newsgroup.


Again, never heard of xchat before, so I didn't realize it was anything
relevant to the user's post. Again, didn't see the word "xchat" in the
subject, because the idiotic news reader I'm using decided to strip it.

> But you had to be rude in your traditional way. I do have respect for
> you because you contribute a lot to the group, but I'm tired of the
> attitude. Goodbye.


I'm truly sorry you feel that way. Fare thee well.

Paul Lalli


Paul Lalli 10-01-2006 11:04 PM

Re: fetching own text - $_[0] not a string?
 
Mumia W. (reading news) wrote:
> On 10/01/2006 06:02 AM, Paul Lalli wrote:
> > Vedran wrote:
> >> Paul Lalli wrote:
> >>> That is a flat-out lie. These scripts are NOT complete. They do not
> >>> run on their own.

>
> They probably do run in the OP's environment.


..... which makes them not standalone complete scripts.

> Paul Lalli, I've valued your posts because you do know something about
> Perl, and you do help people. But you are constantly and needlessly
> obnoxious to people.


I like to think I'm obnoxious and rude only after a poster shows a
complete disregard for anything in my post that attempts to help him
help us help him. But I will take your opinion under consideration.

> *You* changed the subject line--removing the context of the OP's
> original post.


For what it's worth, not intentionally or manually. Google Groups
seems to have done that all on its own. Not sure why, and I didn't
even notice until you mentioned it. That doesn't remove my
responsibility for noticing, of course.

> His context was [xchat]. And /inside/ the OP's message,
> he specified that he was using a Perl-Xchat script, and that is a sign
> that people who are not using xchat need not respond.


I completely disagree with that assesment. The number of posts in this
group that claim their problem lays in one field when it really doesn't
upon reading the post is staggering.

> You could've either not responded or pointed him to the xchat newsgroup.


Again, never heard of xchat before, so I didn't realize it was anything
relevant to the user's post. Again, didn't see the word "xchat" in the
subject, because the idiotic news reader I'm using decided to strip it.

> But you had to be rude in your traditional way. I do have respect for
> you because you contribute a lot to the group, but I'm tired of the
> attitude. Goodbye.


I'm truly sorry you feel that way. Fare thee well.

Paul Lalli



All times are GMT. The time now is 02:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.