Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask


by premchai21 (Curate)
on Nov 15, 2002 at 06:01 UTC ( #213081=obfuscated: print w/replies, xml ) Need Help??

Certainly nowhere near the best around, but a converter I obfuscated after writing for a friend.
#!/usr/bin/perl use strict;no strict 'refs';use Getopt::Long;use subs qw/nil/; use vars qw/$__ @cards %opts %fields @fields $count %fieldXform/;$|++; srand 500;$__=rand;$__.=rand;$__=~s/0\.//g;%fieldXform = eval do{undef$/; <DATA>};*{$_="nil"}=sub{ %opts = (quiet => 0);GetOptions(\%opts,'quiet!'); $count=0;*nil=sub{};$/='';};eval; while (<>) { my %card; eval((qw[nil last next last])[(/^Copyright/?1:0)+(/^Card/?0:2)]); pos=(s/^(Card \#)([^:])/$1:$2/mg*0); while (m[\G^([A-Z][A-Za-z\ \#&/]+):[\ \t]+(.*?)\n (?=$|[A-Z][A-Za-z\ \#&/]+:)]xgsm) { my ($k,$v) = ($1,$2);{my $k =~ tr/A-Z/a-z/;#; $k =~ s/Card/num/g; $v =~ tr/a-z/a-z/c; ;$k =~ s/\#/num/g; $k =~ tr/A-Za-z/_/c; $k =~ s/_+/_/g;$k =~ s/^\s*//; $k =~ s/\s*$//; } $k = (exists $fieldXform{$k} ? $fieldXform{$k} : $k); $v =~ s/^\s*//; $v =~ s/\s*$//; $v =~ s/\s+/ /g; (($k eq 'Pow/Tou')?{my ($tou,$pow) = split /\//,$v; if ($v =~ m!^n/a$!i) {my$i=0;$_.=($i++?substr($v,1,2):substr($v,0,2)) for ($tou,$po +w);} @card{reverse qw{Tou Pow}} = reverse($pow,$tou); $fields{$_}=$k for(reverse qw(Tou Pow)); }:{$card{$fields{$_[0]}=$_[0]}=pop@_; })->($k,$v); } %card or next; push @cards,\%card; $count++; ($count%10) || (print STDERR "\r$count") unless $opts{quiet}; } @fields = keys %fields; ($\,$/)=split//,' |'; print join '|',map{index($_,'|')<0 or die$_;$_} @fields;{; } for my $card (@cards) { print join '|',map{defined($_) ? do{index($_,'|')<0 or die$_;$_} : + ''} @{$card}{@fields}; }print STDERR "" unless $opts{quiet};exit unless $opts{quiet}; __DATA__ ('Pow/Tgh' => 'Pow/Tou', 'Pow/Tough' => 'Pow/Tou', 'Pwr/Tgh' => 'Pow/Tou', 'Card Title' => 'Card Name', 'Color' => 'Card Color', 'Type' => 'Card Type', 'Cost' => 'Mana Cost', 'Casting Cost' => 'Mana Cost', 'Artrist' => 'Artist', 'Artists' => 'Artist', 'CardCard Type' => 'Card Type');

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://213081]
Approved by hiseldl
[shmem]: good for you. Is it a secret?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-02-19 16:24 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.