> > This may work for you:
> >
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> > use Fcntl ':seek';
> >
> > @ARGV = 'somefile.csv';
> > $^I   = '.back';
> >
> > my @headers = map 1, split /,/, <>, -1;
> > my @keep = ( undef ) x @headers;
> >
> > while ( <> ) {
> >    chomp;
> >    my @fields = split /,/, $_, -1;
> >    for my $i ( 0 .. $#fields ) {
> >        $keep[ $i ] = $i if $fields[ $i ] ne '0.0e0';
> >        }
> >    last if @headers == grep defined, @keep;
> >
>
>  That would probably be more efficient as:
>
>       exit 0 if @headers == grep defined, @keep;
>
>
>
>
> >    }
> >
> > @keep = grep defined, @keep;
> >
> > seek ARGV, 0, SEEK_SET or die "Cannot seek on '$ARGV' $!";
> >
> > while ( <> ) {
> >    chomp;
> >    print join( ',', ( split /,/, $_, -1 )[ @keep ] ), "\n";
> >    }
> >
> > __END__
> >

I tried the original code above and received the following error:

seek() on closed filehandle ARGV at filename.pl line 24, <> line 52.
Cannot seek osn 'filename2.csv' Bad file descriptor at filename.pl
line 24, <> line 52

Since the file has 32 lines I was confused by the reference to 'line
52', so I deleted the empty line below _END_ and then repeated the
command:

perl filename.pl

Nothing happened except that the cursor in the command terminal moved
to the next line and remained, flashing without the [...] prefix. I
pressed crtl c and looked at the file using mc. The result was that my
csv file was totally emptied of content, i.e. became an empty file.

So I went to search for the text::csv module. I tried to check if this
was installed, with the resulting command terminal output:

 perl -MText::CSV e -1
Can't open perl script "e": No such file or directory
$ perl -e "print qq(@INC)"
/usr/lib/perl5/5.8.8/i386-linux /usr/lib/perl5/5.8.8
/usr/lib/perl5/site_perl/5.8.8/i386-linux
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .
$ perl -MText::CSV_XS e -1
Can't open perl script "e": No such file or directory

So now I have no idea how to even check whether the module is already installed.

Next I tried to see if there is any documentation: below is my command
terminal output:

ls /usr/share/doc/perl
perl-AppConfig/                 perl-IO-Socket-INET6/
perl-Archive-Cpio/              perl-IO-Socket-SSL/
perl-Archive-Tar/               perl-IO-Tty/
perl-Authen-SASL/               perl-IO-Zlib/
perl-Cairo/                     perl-IP-Country-2.23/
perl-CGI-3.29/                  perl-Libconf/
perl-Class-Singleton/           perl-libwww-perl/
perl-Compress-Raw-Zlib/         perl-Locale-gettext/
perl-Compress-Zlib/             perl-Mail-SPF/
perl-Config-IniFiles/           perl-Mail-SPF-Query/
perl-Crypt-SSLeay/              perl-MailTools/
perl-Curses/                    perl-MDK-Common/
perl-Curses-UI/                 perl-MDV-Distribconf/
perl-DateTime/                  perl-MDV-Packdrakeng/
perl-DateTime-Locale/           perl-MIME-Lite/
perl-DateTime-TimeZone/         perl-Net-CIDR-Lite/
perl-DBD-mysql/                 perl-Net-DBus/
perl-DB_File/                   perl-Net-DNS/
perl-DBI/                       perl-Net-Ident/
perl-Digest-HMAC/               perl-Net-IP/
perl-Digest-SHA1-2.11/          perl-Net-Jabber-2.0/
perl-Encode-Detect/             perl-Net_SSLeay.pm/
perl-Error/                     perl-Net-Telnet/
perl-Expect/                    perl-Net-XMPP/
perl-File-BaseDir/              perl-Params-Validate/
perl-File-DesktopEntry/         perl-RPM4/
perl-File-FnMatch-0.02/         perl-SOAP-Lite/
perl-File-MimeInfo/             perl-Socket6/
perl-Glib/                      perl-String-CRC32/
perl-Gnome2-Print/              perl-String-ShellQuote/
perl-Gnome2-Vte/                perl-SVN/
perl-Gtk2/                      perl-Sys-Hostname-Long/
perl-Gtk2-Html2/                perl-Term-ReadKey/
perl-Gtk2-NotificationBubble/   perl-TimeDate/
perl-Gtk2-SourceView-1.000/     perl-URI/
perl-Gtk2-TrayIcon/             perl-URPM/
perl-HTML-Parser/               perl-version/
perl-HTML-Tagset/               perl-XML-Parser/
perl-IO-Compress-Base/          perl-XML-Stream-1.22/
perl-IO-Compress-Zlib/          perl-Youri-Package-RPM-Updater/

No idea what this all means! I thought I would try and learn word by
word, so trying to find out what 'fcntl' means; no idea where to
start???

Totally bewildered!

Yours,
>
>
>  John
>  --
>  Perl isn't a toolbox, but a small machine shop where you
>  can special-order certain sorts of tools at low cost and
>  in short order.                            -- Larry Wall
>
>  --
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>  http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to