User Control Panel
Advertisements

HELP US, HELP YOU!

Weird gaps with data dumper.

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Tue Mar 08, 2005 9:21 pm    Post subject: Reply with quote

Code:
$save1 = {<br />           'general' => {<br />                          'botsname' => 'Evolution',<br />                          'brain' => 'blank',<br />                          'chatrooms' => {<br />                                           'top10' => {<br />                                                        'time' => 1110318122,<br />                                                        'category' => 'Hardware',<br />                                                        'answers' => {<br />                                                                       'mou' => 'Mouse<br />',<br />                                                                       'key' => 'Keyboard<br />',<br />                                                                       'spe' => 'Speakers<br />',<br />                                                                       'har' => 'Hardrive<br />',<br />                                                                       'fax' => 'Fax<br />',<br />                                                                       'mon' => 'Monitor<br />',<br />                                                                       'pri' => 'Printer<br />',<br />                                                                       'sca' => 'Scanner<br />',<br />                                                                       'flo' => 'Floppy',<br />                                                                       'joy' => 'Joystick<br />'<br />                                                                     }<br />                                                      },

Thats the result and i want it gone! It affects it when i send it back out but i don't understand whats causing it,I can't see no differnce in the text file (One word perl line, no leading spaces,lines)

Heres the code
Code:
sub start_top10{<br /> <br /> <br />   #Lets pick if its a bonus round or not, odds are 10::1<br />   my $roundno = int rand 10; <br />   my $round = "normal";<br />   if($roundno == 1){$round = "bonus";}<br /> <br />   #lets pick a random topic in our round.<br />   my @array = glob("./Stuff/top10/$round/*") if(defined $round);<br />        my $file = $array[int(rand(scalar @array))];<br /> <br />   #get the answers!<br />  open (ANS, "$file") if (defined $file) or warn("Could not open");<br />   my @content = <ANS>;<br /> <br />   my ($category) = $file =~ m/$round\/(.*?)\.txt/isg;<br />   $bot->{store}->{general}->{chatrooms}->{top10}->{category} = $category;<br />   delete $bot->{store}->{general}->{chatrooms}->{top10}->{answers};<br />   delete $bot->{store}->{general}->{chatrooms}->{top10}->{found};<br />   foreach $answer (@content){<br />  $letters = substr($answer,0,3);<br />  $letters = lc ($letters);<br />  $bot->{store}->{general}->{chatrooms}->{top10}->{answers}->{$letters} = $answer;<br />   }<br />   &chatAnnounce("New Top10 Round starting!\nThe topic is set to $category and it is a $round round...\n\nStart!","top10","660000") if (defined $file && defined $round);<br />   close ANS;<br />   &save;<br />}


And Heres an example of the text file that was used with that one ^^

QUOTE(Weathers.txt)
Sunny
Cloudy
Rain
Snow
Windy
Foggy
Hail
Thunder
Lightning
Stormy


i even tried removing all the white space before storing it with a tutorial on here but nothing seems to do the trick..

Hint : I dont think its the text files its self but the code because it happens once for every text file. But not in the same place so i cant see no pattern.

For erics sake...What can i do to stop this? Laughing
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Tue Mar 08, 2005 9:39 pm    Post subject: Reply with quote

You want to chomp your file. Also beware that if you are making the text file on windows, and transfering it to linux (or vice versa) then you will have file ending trouble.

Code:
<br />open (ANS, "$file") if (defined $file) or warn("Could not open");<br />my @content = <ANS>;<br />chomp(@content);<br />


That will remove the line ending of each line, probably fixing your issue.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Tue Mar 08, 2005 9:46 pm    Post subject: Reply with quote

With the .Txt files?

How else though? A different format. extension?
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 Mar 08, 2005 10:24 pm    Post subject: Reply with quote

Umm, the chomp will remove any "new lines" (\n) from a string, which is exactly what you want.
_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Tue Mar 08, 2005 11:37 pm    Post subject: Reply with quote

Noooo, i was refering to the bit about linux
Back to top
mat007
Almost An Agent
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Wed Mar 09, 2005 12:53 pm    Post subject: Reply with quote

Linux uses diffrent ways of viewing lines etc (\r\n i think) were as windows is just \n (I think?).

To view the files were lines are messed just open with WordPad wchich will fix the problem. Smile
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: Wed Mar 09, 2005 1:35 pm    Post subject: Reply with quote

QUOTE(Mat007 @ Mar 9 2005, 01:53 PM)
Linux uses diffrent ways of viewing lines etc (\r\n i think) were as windows is just \n (I think?).
[right][snapback]46669[/snapback][/right]


Other way round Smile

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


Joined: 06 Aug 2004
Posts: 156
Location: Belgium
Reputation: 24.5Reputation: 24.5

PostPosted: Wed Mar 09, 2005 3:29 pm    Post subject: Reply with quote

Believe me, it's even more difficult if you mix in some old MAC formatted textfiles... As i recall they use \n\r which complicates things even more.

Anyhow, here is some little tricks to port over various files to unix and back.

To convert dos texts to unix from commandline:

Code:
perl -pi -e 's/\r\n/\n/;' filename


(filename can be wildcarded to convert a directory)

To convert unix files to dos format:

Code:
perl -pi -e 's/\n/\r\n/;' filename



I hope this helps a bit.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl 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