#!/usr/bin/perl -w use strict; use Library::Schema; use Data::Dump qw(dump); # Connection parameters my $dsn = 'dbi:mysql:library'; my $usr = 'nelo'; my $psw = 'n'; # Create a database connection my $schema = Library::Schema->connect( $dsn, $usr, $psw ); # Insert a new person into table names (represented by class Names) my ( $artist, $cd ); do { # Provide a artist name print 'Enter artist name: '; chomp ( my $input_name = ); # Insert new and unique artists my $new_artist = $schema->resultset('Artist')->find_or_create( { name => $input_name, }, { key => 'artist_name' } ); # SELECT * FROM artist my $rs_artist = $schema->resultset('Artist')->search(); # Save artist { name => id } in a hash while ( my $artist_name = $rs_artist->next ) { $artist->{$artist_name->name} = $artist_name->artistid; } # Provide a cd name print 'Enter cd name: '; chomp ( my $input_cd = ); # Insert new and unique cds my $new_cd = $schema->resultset('Cd')->find_or_create( { title => $input_cd, artist => $artist->{$input_name}, # Retrieve the artist ids for the cd }, { key => 'cd_title' } ); # SELECT * FROM cd my $rs_cd = $schema->resultset('Cd')->search(); # Save cd { title => id } in a hash while ( my $cd_name = $rs_cd->next ) { $cd->{$cd_name->title} = $cd_name->cdid; } # Provide a cd name print 'Enter track name: '; chomp ( my $input_track = ); # Insert new and unique tracks my $new_track = $schema->resultset('Track')->find_or_create( { title => $input_track, cd => $cd->{$input_cd}, }, { key => 'track_title' } ); print 'done', "\n" if $new_track; } unless! ( $schema ); exit;