Wiggins d'Anconia wrote:
> 
> Konrad Foerstner wrote:
> > Hi folks,
> >
> > an new question about the mystery of regexs:
> >
> > I want to store some parts of a file wich are separetet by "#". Each each
> > part should become an entry of an array. example:
> >
> > "
> > # foobar
> > nothing important
> > nothing interesting
> > # bar foot
> > lululul
> > lalala
> > lalala
> > # foobar2
> > Rumba-Samba-Tango
> > "
> >
> > (okay it stop before the example becomes to silly :) )
> >
> 
> To late. ;-)
> 
> > $array[0] should contain:
> > "
> > # foobar
> > nothing important
> > nothing interesting
> > "
> >
> > Well, my code looks like this:
> >
> > open(INPUT,$input_file);
> >     while (<INPUT>) {
> >       if (/#/ .. /\n#/) {
> >         push @array, $_;
> >       }
> >     }
> >
> 
> Your use of the range won't work in this context, because you only have
> access to 1 line. How aobut something like:
> 
> while (<INPUT>) {
>    if (/^#/) {
>      # start new array element
>      push @array, $_;
>    }
>    else {
>      # append to last array element
>      $array[$#array] .= $_;
>    }
> }
> 
> --Untested--
> 
> The other option would be to slurp the file into a single string by
> nulling the record separator and then splitting on #, but that breaks
> down for large files and if a particular entry can contain a #, but I
> assume not since you weren't explicitly looking for # at the beginning
> of a line (^) or should you have been?
> 
> HTH,
> 
> http://danconia.org
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
Hi All,
        One more tip for this problem.

#Code Starts here

open("FILE1","/usr/tmp/inputfile");
$line = <FILE1>;
@array = split('#',$line);
foreach $val(@array)
{
   print "$val \n";

}

## Code ended here.

-- 
Thanks,
Pons.

---------------------------------------------------------------
    /\      M.A Ponnambalam
   \\ \     Member Technical Staff
  \ \\ /    Sun Microsystems 
 / \/ / /   Off Langford Road
/ /   \//\  Bangalore - India 560 025
\//\   / / 
 / / /\ /   Phone:                     91.80.2298989 X 87252
  / \\ \    Email:                     [EMAIL PROTECTED]
   \ \\     
    \/
---------------------------------------------------------------

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to