Leser: 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl -w use strict; use LWP::Simple; use Encode; print fetch_room_list(); sub fetch_room_list { my $self = shift; #my $content = get ('URL'); my $content = '[["PromillePunk","0","1","1","200","2","",""],["BoMbEnLeGeR-Family","0","1","1","200","1","",""],["meck-pomm","700","1","11","83","5","Chatraum f\u00fcr Mecklenburg-Vorpommern.","http://example.org/"],["te\\\\\u00fc\\\\te","0","1","1","200","1","",""]]'; my @room_list; if ($content) { $content =~ /\[(.*)\]/; my $rooms = $1; $rooms = encode('ISO-8859-15', $rooms); #unicode handling my %chars = ( 'Ä' => '\u00C4', 'ä' => '\u00E4', 'Ü' => '\u00DC', 'ü' => '\u00FC', 'Ö' => '\u00D6', 'ö' => '\u00F6', 'ß' => '\u00DF', ); for my $key (keys %chars) { $rooms =~ s|(?<!\\)\Q$chars{$key}\E|$key|gi; } $rooms =~ s|(\\\\)|\\|g; # get rid of escaped backslahes $rooms =~ s|(\\")|"|g; # get rid of escaped " #get data for single rooms while ($rooms =~ s|\["(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)"\]||) { push @room_list, [$1, $2, $4, $5, $6, $7, $8]; print "room: $1\t\t\t"; } } else { print "Cannot fetch URL.\n”"; } return \@room_list; }
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl use strict; use warnings; my $str1 = 'This is \\ simple test\n'; print "1) $str1" ."\n"; my $str2; eval '$str2="$str1"'; print "2) $str2" ."\n";
QuoteWie man sieht kommen in den Daten Unicode und Escape-sequenzen vor, gibt es da ein Modul, um die obrigen Daten einzulesen und zu interpolieren?
1 2 3 4
use JSON; my $content = '[["PromillePunk","0","1","1","200","2","",""],["BoMbEnLeGeR-Family","0","1","1","200","1","",""],["meck-pomm","700","1","11","83","5","Chatraum f\u00fcr Mecklenburg-Vorpommern.","http://example.org/"],["te\\\\\u00fc\\\\te","0","1","1","200","1","",""]]' my $data = from_json($content);
2009-12-29T11:11:17 styx-ccMein versuch oben funktioniert zwar schon ganz gut, allerdings gibt es immer wieder Probleme mit z.B. Zeichenfolgen wie diesen:
"te\\\\\u00fc\\\\te"
2009-12-29T12:16:40 styx-ccAber wie gesagt, JSON macht das bis dahin ganz gut gut!