daily pastebin goal
25%
SHARE
TWEET

lists of quoted items in perl

ExaGridDba Aug 2nd, 2016 88 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. $ cat inlist.pl
  2. #!/usr/bin/perl
  3.  
  4. use strict;
  5. use warnings;
  6. use IO::File;
  7. use Data::Dumper;
  8.  
  9. my ( $filename ) = @ARGV;
  10.  
  11. defined $filename
  12.         or die "usage: inlist.pl listfile";
  13.  
  14. my $fh = IO::File->new( $filename )
  15.         or die "can't open $filename: $!";
  16.  
  17. local $/;
  18. undef $/;
  19.  
  20. my @items = split ' ', <$fh>;
  21.  
  22. warn "Genenerate in-list from perl array.\n";
  23. my @quotitems = map { qq/'$_'/ } @items;
  24. printf "in (\n\t%s\n)\n", join ",\n\t", @quotitems;
  25.  
  26. warn "Generate insert values from perl array with quoted identifiers and serially numbered bind variables.\n";
  27. my @dquotitems = map { qq/"$_"/ } @items;
  28.  
  29. my $bindex = 1;
  30. my @binds = map { sprintf ":b%s", $bindex++ } @items;
  31. printf "( %s ) values ( %s )\n", ( join ", ", @dquotitems ), ( join ", ", @binds );
  32. $ ./inlist.pl itemlist.txt
  33. Genenerate in-list from perl array.
  34. in (
  35.         'Sherlock',
  36.         'Watson',
  37.         'Moriarty',
  38.         'Moran'
  39. )
  40. Generate insert values from perl array with quoted identifiers and serially numbered bind variables.
  41. ( "Sherlock", "Watson", "Moriarty", "Moran" ) values ( :b1, :b2, :b3, :b4 )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top