#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Hi all,

    I am trying to chunk my files into strings.
    It's normally done by:

    open (FILE,'<filename');
    while (<FILE> )
    {
    }

    But this time I don't want to break line like that. My record may be on more than 1 line. At the end of each record I have a special string '~~REC~~' I want to break my file by this '~~REC~~' string. I read the Perl book, it mentions about the variable $:
    But I try to change it $:='~~REC~~', it doesn't work. The book says the default value is $:=' n-'

    Any suggestion please!

    Thank you very much for your help.
    Nam.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Southern California
    Posts
    73
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by NamHN:
    My record may be on more than 1 line. At the end of each record I have a special string '~~REC~~' I want to break my file by this '~~REC~~' string.[/quote]

    If I understand correctly, you want to break this file into individual records. If so, what you want to do is set the 'Input Record Separator', or $/ to '~~REC~~':

    $/ = '~~REC~~';

    open FILE, "<$file" or die "cannot open file $file: $!n";

    while (defined($rec = <FILE> )) {
    .
    .
    .

    Now $rec should hold the contents of a record. Hope this helps...



IMN logo majestic logo threadwatch logo seochat tools logo