[ale] Fore (Was Re: [ale] Simple Perl Question)

Fletch fletch at phydeaux.org
Mon Feb 25 12:16:26 EST 2002


>>>>> "James" == James P Kinney, <James> writes:

    James> Fletch, You are clearly one of those people who have given
    James> perl the bad reputation of being an illegible language!

        Hey, I resemble that remark. :)

        But don't judge perl (or me :) by one liners alone.  That was
intentionally compressed since it was a command line hack.


        If you want readablility (and a fix so that the SQL actually
works correctly; I typo'd the string join'ing items):


#!/usr/bin/perl -w
use strict;
require v5.6;

die "usage: $0 input_file" unless @ARGV;
my $infile = shift;

open( my $fh, $infile ) or die "Can't open $infile: $!\n";

while( <$fh> ) {
  chomp;
  my @cols = ( split( /\|/, $_ ) )[ 0, 4, 6, 9 ];

  print qq{insert into foo values ( "},
        join( qq{", "}, @cols ),
        qq{" )\n};
}

exit 0;

__END__


        But that's a handful to type on the command line for what's
probably a one time throwaway incantation.


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
770 933-0600 x211(w)  |  scary questions." -- Jules                =(___)=
                      |                                               U

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list