Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat inlist.pl
- #!/usr/bin/perl
- use strict;
- use warnings;
- use IO::File;
- use Data::Dumper;
- my ( $filename ) = @ARGV;
- defined $filename
- or die "usage: inlist.pl listfile";
- my $fh = IO::File->new( $filename )
- or die "can't open $filename: $!";
- local $/;
- undef $/;
- my @items = split ' ', <$fh>;
- warn "Genenerate in-list from perl array.\n";
- my @quotitems = map { qq/'$_'/ } @items;
- printf "in (\n\t%s\n)\n", join ",\n\t", @quotitems;
- warn "Generate insert values from perl array with quoted identifiers and serially numbered bind variables.\n";
- my @dquotitems = map { qq/"$_"/ } @items;
- my $bindex = 1;
- my @binds = map { sprintf ":b%s", $bindex++ } @items;
- printf "( %s ) values ( %s )\n", ( join ", ", @dquotitems ), ( join ", ", @binds );
- $ ./inlist.pl itemlist.txt
- Genenerate in-list from perl array.
- in (
- 'Sherlock',
- 'Watson',
- 'Moriarty',
- 'Moran'
- )
- Generate insert values from perl array with quoted identifiers and serially numbered bind variables.
- ( "Sherlock", "Watson", "Moriarty", "Moran" ) values ( :b1, :b2, :b3, :b4 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement