On 7/11/07, jeniffer <[EMAIL PROTECTED]> wrote:
I have a file of the format
action arg1 \
          arg2 \
          arg3 \

action2 arg1 \
          arg2 \
          arg3 \

I read this by :-
foreach $line (@lines)
{
        ($action , @argument_list) = split(/\s+/,$line);

This would work fine if the file is of the
format
action arg1           arg2           arg3

not my original file...
Please help me!

It appears as if your record separator is a blank line.  If this is
the case (and you have no embedded blank lines in your record) you can
say

local $/ = "\n\n";
while (<>) {
   s/\\//g; #this may be the wrong thing to do
   my @rec = split ' ';
   #do stuff with @rec
}

If don't always have a blank line between records then you will have
to do something like this

my $rec = '';
while (<>) {
   if (/\\$/) { #if line is a continuation
       chop; #remove the continuation character
       $rec .= $_;
       next;
   }
   my @rec = split ' ', $rec;
   $rec = '';
   #do stuff with @rec
}

A third option would be to use Parse::RecDescent* to define the file
format and have it parse the file for you.  If this is not a one-off
piece of code I would suggest this method as it more clearly defines
the expected input and provides modularity if the input changes later.

* http://search.cpan.org/~dconway/Parse-RecDescent-1.94/lib/Parse/RecDescent.pod

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


Reply via email to