Hello world,
As a big fan of the Magic the Gathering game I was trying to build a card database so I can search for specific cards.
I want to load all the cards from the spoilerlists into a mysql database.
The original text file is:
I already cut out the lines that aren't of any interest.
I want to know everything about every card so I can put it into the database. So I have to analyze every card.
This is the script I tried to use:
#!/usr/bin/perl -w
open (FH1,"le_spoiler_en.txt"
;
undef $/;
@cards = split(/\/145/, <FH1>, -1);
$/ = "\n";
for( $i = 0; $i < scalar (@cards);$i++ )
{
$card= shift;
$card=$cards[$i];
$cardname= shift;
$cardname=$card;
$cardname=~ s/Card Name:\s+//gs;
$cardname=~ s/Card Color:.*Card \#:.*\d+//sg;
$cardname=~ s/\n//g;
$cardname=~ s/\t//sg;
$cardcolor=$card;
$cardcolor=~ s/Card Name:.*//g;
$cardcolor=~ s/Card Color:\s+//gs;
$cardcolor=~ s/Mana Cost:.*Card \#:.*\d+//sg;
$cardcolor=~ s/\n//sg;
$cardcolor=~ s/\t//sg;
print "$cardname is of the color $cardcolor\n";
}
This should tell me the name of the cards and what color it is. It only just doesn't work as expected.
The output looks like:
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
This can't be right, right?
What am I doing wrong? I just don't see it.
As a big fan of the Magic the Gathering game I was trying to build a card database so I can search for specific cards.
I want to load all the cards from the spoilerlists into a mysql database.
The original text file is:
I already cut out the lines that aren't of any interest.
I want to know everything about every card so I can put it into the database. So I have to analyze every card.
This is the script I tried to use:
#!/usr/bin/perl -w
open (FH1,"le_spoiler_en.txt"
undef $/;
@cards = split(/\/145/, <FH1>, -1);
$/ = "\n";
for( $i = 0; $i < scalar (@cards);$i++ )
{
$card= shift;
$card=$cards[$i];
$cardname= shift;
$cardname=$card;
$cardname=~ s/Card Name:\s+//gs;
$cardname=~ s/Card Color:.*Card \#:.*\d+//sg;
$cardname=~ s/\n//g;
$cardname=~ s/\t//sg;
$cardcolor=$card;
$cardcolor=~ s/Card Name:.*//g;
$cardcolor=~ s/Card Color:\s+//gs;
$cardcolor=~ s/Mana Cost:.*Card \#:.*\d+//sg;
$cardcolor=~ s/\n//sg;
$cardcolor=~ s/\t//sg;
print "$cardname is of the color $cardcolor\n";
}
This should tell me the name of the cards and what color it is. It only just doesn't work as expected.
The output looks like:
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
Gis of the color er
This can't be right, right?
What am I doing wrong? I just don't see it.