Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
what's wrong here.. Posted by jgr on 21 Feb 2004 at 2:44 PM
Hi, what's wrong with this code ?



while (1) {

while (<SOCK>) {

if (/jgr/) {

@data= split (/ /, $_);

$data[3]=~ s/^\://g;
$data[3]=~ s/\=//g;

print ($data[3]--), "\n";

# I do ($data[3]--), beacuse $data[3] is with '\n' .
# And in data[3] is now '!help'

open (CONF, "mowa.conf") or die "Missing mowa.conf !!! \n";

# In mowa.conf is:
# !help:bleble
# !ble:hehe

@datafile= <CONF>;

foreach $num (0 .. scalar (@datafile)) {

@compare = split (/\:/, $datafile[$num]);

# $compare[0] now is !help or !ble

if (($compare[0] cmp ($data[3]--)) == 0) {
print "YEAH !";
}
# This compare is not work, I mean at stdout it's show nothing, why is
# that ? :))
}
}
}
}

At last, sorry for my english :)
Report
Re: what's wrong here.. Posted by Jonathan on 21 Feb 2004 at 4:14 PM
: Hi, what's wrong with this code ?
:
OK, I'm tired, have been at a party, and my brain isn't really working. But anyhow...

: while (1) {
:
: while (<SOCK>) {
:
: if (/jgr/) {
:
: @data= split (/ /, $_);
:
: $data[3]=~ s/^\://g;
: $data[3]=~ s/\=//g;
:
: print ($data[3]--), "\n";
:
: # I do ($data[3]--), beacuse $data[3] is with '\n' .
: # And in data[3] is now '!help'
:
: open (CONF, "mowa.conf") or die "Missing mowa.conf !!! \n";
:
: # In mowa.conf is:
: # !help:bleble
: # !ble:hehe
:
: @datafile= <CONF>;
:
: foreach $num (0 .. scalar (@datafile)) {
:
: @compare = split (/\:/, $datafile[$num]);
:
: # $compare[0] now is !help or !ble
:
: if (($compare[0] cmp ($data[3]--)) == 0) {
: print "YEAH !";
: }
: # This compare is not work, I mean at stdout it's show nothing, why is
: # that ? :))
: }
: }
: }
: }
:
: At last, sorry for my english :)
:
I'm pretty sure your $data[3]-- is the problem. If you want to remove the \n, you should use:-

chomp $data[3];
print $data[3];

Also note you actually end up executing $data[3]-- twice, which I expect is not what you want it to do. So, get rid of the --'s and do chomp $data[3];
Before the print statement.

Hope this helps,

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: what's wrong here.. Posted by jgr on 22 Feb 2004 at 4:07 AM
: I'm pretty sure your $data[3]-- is the problem. If you want to remove the \n, you should use:-
:
: chomp $data[3];
: print $data[3];
:

Hmm, when I use chomp $data[3], and I do print $data[3]; then print "show" nothing.. :/

: Also note you actually end up executing $data[3]-- twice, which I expect is not what you want it to do. So, get rid of the --'s and do chomp $data[3];

I use ($data[3]--) beacuse, I use many combination with this.. beacuse
I don't have ideas, why this code not work correctly..
In that code, I do lentgh ($data[3]), and length ($compare[0]), and He show is len $data[3] = 7, and len $compare[0] = 5, but
$data[3] = !help so 7 also with '\n', not 6 ? ee ? why ?
$compare[0] = !help <- 5

So any other ideas ? :))

Report
Re: what's wrong here.. Posted by Jonathan on 22 Feb 2004 at 6:26 AM
: : I'm pretty sure your $data[3]-- is the problem. If you want to remove the \n, you should use:-
: :
: : chomp $data[3];
: : print $data[3];
: :
:
: Hmm, when I use chomp $data[3], and I do print $data[3]; then print "show" nothing.. :/
:
: : Also note you actually end up executing $data[3]-- twice, which I expect is not what you want it to do. So, get rid of the --'s and do chomp $data[3];
:
: I use ($data[3]--) beacuse, I use many combination with this.. beacuse
: I don't have ideas, why this code not work correctly..
Yes, but -- is for decrementing numbers.

$a = 3;
$a--;
print $a; # Prints 2

You seem to want to remove characters from a string using it. No, that's not what it's for. Your code won't work if that's what you're trying to do.

: In that code, I do lentgh ($data[3]), and length ($compare[0]), and He show is len $data[3] = 7, and len $compare[0] = 5, but
: $data[3] = !help so 7 also with '\n', not 6 ? ee ? why ?
: $compare[0] = !help <- 5
:
I would guess it is 7 because some platforms have \r and \n, e.g. two end of line characters. You may need to use chomp twice, or altenatively do:-

$data[3] =~ s/\r|\n//g;

But two chomps are more efficient. Either are better than --, which is just...well...wrong.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: what's wrong here.. Posted by jgr on 22 Feb 2004 at 7:38 AM
: I would guess it is 7 because some platforms have \r and \n, e.g. two end of line characters. You may need to use chomp twice, or altenatively do:-

Yes, you have right. :)

: $data[3] =~ s/\r|\n//g;
:
: But two chomps are more efficient. Either are better than --, which is just...well...wrong.

ok, I do that what i want. Here code:

while (1) {
while (<SOCK>) {

if (/jgr/) {

open (CONF, "mowa.conf") or die "Missing mowa.conf !!! \n";

@plik = <CONF>;

foreach $num (0 .. scalar @plik) {

@porownaj = split (/\:/, $plik[$num]);
@data= split (/ /, $_);

$data[3] =~ s/^\:|\r|\n|\=//g;

if (($porownaj[0] cmp $data[3]) == 0) {

print "YEAH !!! \n";

}

}
}
}
}

close FILE;

Thanks Jonathan for help, you help me second time ;) thanks doode ;)

jgr

Report
Re: what's wrong here.. Posted by Jonathan on 22 Feb 2004 at 12:10 PM
: : I would guess it is 7 because some platforms have \r and \n, e.g. two end of line characters. You may need to use chomp twice, or altenatively do:-
:
: Yes, you have right. :)
:
: : $data[3] =~ s/\r|\n//g;
: :
: : But two chomps are more efficient. Either are better than --, which is just...well...wrong.
:
: ok, I do that what i want. Here code:
:
: while (1) {
: while (<SOCK>) {
:
: if (/jgr/) {
:
: open (CONF, "mowa.conf") or die "Missing mowa.conf !!! \n";
:
: @plik = <CONF>;
:
: foreach $num (0 .. scalar @plik) {
:
: @porownaj = split (/\:/, $plik[$num]);
: @data= split (/ /, $_);
:
: $data[3] =~ s/^\:|\r|\n|\=//g;
:
: if (($porownaj[0] cmp $data[3]) == 0) {
:
: print "YEAH !!! \n";
:
: }
:
: }
: }
: }
: }
:
: close FILE;
:
: Thanks Jonathan for help, you help me second time ;) thanks doode ;)
:
You're welcome. Sorry for confusion, but just to check - it works now, right?

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.