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