User Control Panel
Advertisements

HELP US, HELP YOU!

Perl Splitting Tutorial

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Ideas
View unanswered posts
Author Message
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Tue Jun 14, 2005 2:28 pm    Post subject: Perl Splitting Tutorial Reply with quote

It seems that it is important for commands in bots, and this is a bot site. So why don't we have a tutorial on it?
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Tue Jun 14, 2005 2:39 pm    Post subject: Reply with quote

Maybe because it's a basic Perl function and you can pick it up from most any tutorial.

(@output) = split(/separator/, $variable, number-of-outputs);

i.e. a comma separated list for an address book:
"Cerone,Kirsle,name@domain.com,555 nowhere rd,555-555-5555,some comments that include, commas, inside of them"

Code:
my ($first,$last,$email,$address,$phone,$comments) = split(/\,/, $data, 6);


Since it only wanted 6 variable, $comments will still have commas in them. If the 6 was omitted, $comments would only have "some comments that include" and then to get the other info you'd have to go more variables in (some people handle this by putting an array as the last item).

Anyway, it's really not that hard.
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Tue Jun 14, 2005 3:52 pm    Post subject: Reply with quote

yeah but how would I handle splitting in a sense of turning an IM with Hello World into two variables. $hello having Hello in it, and $world having world in it. I think you would use splitting for that
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Tue Jun 14, 2005 4:27 pm    Post subject: Reply with quote

my $message = 'Hello World';
my ($hello, $word) = split(/ /, $message, 2);
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Tue Jun 14, 2005 4:29 pm    Post subject: Reply with quote

What if it was Hello:World is good

how would I put Hello into one variable and world is good into another?
The colon should NOT be in a varialbe
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Tue Jun 14, 2005 4:44 pm    Post subject: Reply with quote

The thing you want to split it with goes in the first arg:

my ($hello, $secondbit) = split(/:/, $message, 2);

Now, no more help. Read what Cer and I have said, and learn from it.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Tue Jun 14, 2005 4:45 pm    Post subject: Reply with quote

I won't need help on this topic anymore. But you can count on me having questions on other topics
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Ideas All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group