#!/usr/bin/perl -w use strict; use DBI; use DBD::RAM; my $dbh = DBI->connect('DBI:RAM:','usr','pwd',{RaiseError=>1}); $dbh->{f_dir} = '.'; # (default), or your path: '/path/to/files' $dbh->func([ [ 'items', 'PIPE', 'ramdata', {col_names => 'id,category,subcat,code,description,picture' } ], ],'catalog'); my $query = "select * from items where subcat='PEN' order by code"; my $sth = $dbh->prepare($query)|| die print $DBI::errstr; $sth->execute || die print $DBI::errstr; my @row; while ( @row = $sth->fetchrow_array ) { print join(" ",@row),"\n"; # or try this.. print "\n"; } # DBD::RAM lets you access a file with SQL. PIPE separated # is a built-in type which lets you read from one file and # write to another one without storing the whole thing in memory. # Headings can come from the top of the file if you have a line # containing them. # You don't need a separate database server, just DBI, DBD::RAM, # and SQL::Statement. It can access remote files, and # use different kinds of tables at the same time. #### #!/usr/bin/perl -w use strict; use IO::File; my %in; my %out; $in{b} = new IO::File; $out{b} = new IO::File; $in{b}->open("open(">ramdata2") || die $!; my $fi = $in{b}; my $fo = $out{b}; &v1; # &v2; # this also works close($in{b}); close($fo); sub v1 { # works while (<$fi>) { print $fo "-> $_"; } } sub v2 { # works my $x = $in{b}; while (<$x>) { print {$out{b}} "-> $_"; # sneak by print: treat as object } } sub nogoods { # these doesn't compile # while (<{$in{b}}>) { # no obj allowed in diamond # ... } # while (readline($in{b})) { # bad: storing obj not fh glob # ... } }