Mailinglist Archive: opensuse (3666 mails)

< Previous Next >
Re: [SLE] How can I debug a PERL program ?
  • From: Allister <lists@xxxxxxxxxxxxx>
  • Date: Sat, 12 Mar 2005 21:03:58 +0000
  • Message-id: <200503122103.59014.lists@xxxxxxxxxxxxx>
On Saturday 12 March 2005 19:55, Maura Edelweiss Monville wrote:

> Other question: HOW can I tell PERL to sckip the initial blanks (spaces) ?
> I'm extracting some fields from a huge ascii file. all records start
> with 1 space preceding the fisrt numerical value.
> Fileds are separated by spaces. This situation seems to confuse the PERL
> buil-in function split. In fact the extracted fileds are messed up ..
> misaligned. But if I get rid of the head space (blank character) for
> any record in the file in advance of starting my PERL program .. then
> it works !
> I just wonder if I can avoid this file pre-processing and do everything
> by PERL ...
>
Try this (asciitest looks like this
" field1 field2 field3 field4 field5 field6 field7 field8 field9");

#!/usr/bin/perl -w
#

open "TEXT", "<asciitest";
while (<TEXT>) {
my @fields = split ;
foreach (@fields) {
print $_ . "\n"
};
}

This will produce output like this;
field1
field2
field3
field4
field5
field6
field7
field8
field9

This is because in this particular format split will split on whitespace and
leave out any leading empty/whitespace fields. Apparently you can get the
same thing to happen with the format:
split ' ' , $string;
but I didn't test that.
Hope this helps
Allister

--

Public Key to be found at www.keyserver.net.
Search for tag@ukfsn


< Previous Next >