$File->Read (File_ModeLine)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

$File->Read (File_ModeLine)

Ke Carlton
designke.com - Personalised design and development, London based.Hello,

Am having problems getting reading a line of a text file cast as a file
object. Instead of reading a line number it reads a character count as if in
character mod. I've also tried specifying an -FileEndOfLine with '\r\n' and
'\r' and '\n' but to no avail.

The code's fairly simple - if some can see a error or help that would be
great.

The server is OSX and lasso is version 8.

<?lassoscript
Var:'File'=(File: '/emailexport.txt', File_OpenRead, File_ModeLine);
     loop:10;
          var:'lc'=loop_count;
          var:'insert'=$File->(Read:$lc);
          output:$insert'<BR>',-encodenone;
     /loop;
?>


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: $File->Read (File_ModeLine)

Marc Vos-3
Hi Ke,

From the Manual:
--------------------
[File->Read]  Reads data from a file. Requires the integer number of  bytes
(characters) to read as a parameter. Outputs the  file data as bytes.

So in your example, the first read would read 1 byte from the file, the
second iteration 2 bytes, the third 3 bytes.... until 10 bytes.

Use $insert = file_readline($file); instead.

[File_ReadLine]  Reads a single line from a file. Accepts two parameters,
the name of the file to be read and -FileLineNumber  specifying which line
of the file to read. An optional  keyword/value parameter -FileEndOfLine
specifies what  character represents the end of lines within the file.

-Marc Vos
* * * * * * * * * * * * * * * * * * * * * * * *
Goodyear Dunlop Tires Germany GmbH
Private:  http://marc.vos.net/
* * * * * * * * * * * * * * * * * * * * * * * *



On 01-06-2005 10:40, "Ke Carlton" <[hidden email]> wrote:

> designke.com - Personalised design and development, London based.Hello,
>
> Am having problems getting reading a line of a text file cast as a file
> object. Instead of reading a line number it reads a character count as if in
> character mod. I've also tried specifying an -FileEndOfLine with '\r\n' and
> '\r' and '\n' but to no avail.
>
> The code's fairly simple - if some can see a error or help that would be
> great.
>
> The server is OSX and lasso is version 8.
>
> <?lassoscript
> Var:'File'=(File: '/emailexport.txt', File_OpenRead, File_ModeLine);
>      loop:10;
>           var:'lc'=loop_count;
>           var:'insert'=$File->(Read:$lc);
>           output:$insert'<BR>',-encodenone;
>      /loop;
> ?>
>



--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: $File->Read (File_ModeLine)

Ke Carlton
In reply to this post by Ke Carlton
Thanks for your response, this is what i'm doing now.

I was hoping to be able to work with the file in memory for performance
sake. I'm working with a 1.8mb file (50,000 lines) that needs to be
processed and imported into sql. I had though that using file_read would
cause a lot of disk access - and slow things majorly.

Seems to chew through it easily enough.  :)


----- Original Message -----
From: "Marc Vos" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, June 01, 2005 10:10 AM
Subject: Re: $File->Read (File_ModeLine)


> Hi Ke,
>
> From the Manual:
> --------------------
> [File->Read]  Reads data from a file. Requires the integer number of
bytes

> (characters) to read as a parameter. Outputs the  file data as bytes.
>
> So in your example, the first read would read 1 byte from the file, the
> second iteration 2 bytes, the third 3 bytes.... until 10 bytes.
>
> Use $insert = file_readline($file); instead.
>
> [File_ReadLine]  Reads a single line from a file. Accepts two parameters,
> the name of the file to be read and -FileLineNumber  specifying which line
> of the file to read. An optional  keyword/value parameter -FileEndOfLine
> specifies what  character represents the end of lines within the file.
>
> -Marc Vos
> * * * * * * * * * * * * * * * * * * * * * * * *
> Goodyear Dunlop Tires Germany GmbH
> Private:  http://marc.vos.net/
> * * * * * * * * * * * * * * * * * * * * * * * *
>
>
>
> On 01-06-2005 10:40, "Ke Carlton" <[hidden email]> wrote:
>
> > designke.com - Personalised design and development, London based.Hello,
> >
> > Am having problems getting reading a line of a text file cast as a file
> > object. Instead of reading a line number it reads a character count as
if in
> > character mod. I've also tried specifying an -FileEndOfLine with '\r\n'
and

> > '\r' and '\n' but to no avail.
> >
> > The code's fairly simple - if some can see a error or help that would be
> > great.
> >
> > The server is OSX and lasso is version 8.
> >
> > <?lassoscript
> > Var:'File'=(File: '/emailexport.txt', File_OpenRead, File_ModeLine);
> >      loop:10;
> >           var:'lc'=loop_count;
> >           var:'insert'=$File->(Read:$lc);
> >           output:$insert'<BR>',-encodenone;
> >      /loop;
> > ?>
> >
>
>
>
> --
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:
> http://www.listsearch.com/lassotalk.lasso?manage


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: $File->Read (File_ModeLine)

Marc Vos-3
In reply to this post by Ke Carlton
Well, file_read reads the file completely in memory while file_readline only
reads records. After a $data = file_read($file); you can do $array =
$data->split('\n'); and then process each array element in $array as if it
were a record from the file.

-Marc Vos


On 01-06-2005 11:57, "Ke Carlton" <[hidden email]> wrote:

> Thanks for your response, this is what i'm doing now.
>
> I was hoping to be able to work with the file in memory for performance
> sake. I'm working with a 1.8mb file (50,000 lines) that needs to be
> processed and imported into sql. I had though that using file_read would
> cause a lot of disk access - and slow things majorly.
>
> Seems to chew through it easily enough.  :)
>
>
> ----- Original Message -----
> From: "Marc Vos" <[hidden email]>
> To: <[hidden email]>
> Sent: Wednesday, June 01, 2005 10:10 AM
> Subject: Re: $File->Read (File_ModeLine)
>
>
>> Hi Ke,
>>
>> From the Manual:
>> --------------------
>> [File->Read]  Reads data from a file. Requires the integer number of
> bytes
>> (characters) to read as a parameter. Outputs the  file data as bytes.
>>
>> So in your example, the first read would read 1 byte from the file, the
>> second iteration 2 bytes, the third 3 bytes.... until 10 bytes.
>>
>> Use $insert = file_readline($file); instead.
>>
>> [File_ReadLine]  Reads a single line from a file. Accepts two parameters,
>> the name of the file to be read and -FileLineNumber  specifying which line
>> of the file to read. An optional  keyword/value parameter -FileEndOfLine
>> specifies what  character represents the end of lines within the file.
>>
>> -Marc Vos
>> * * * * * * * * * * * * * * * * * * * * * * * *
>> Goodyear Dunlop Tires Germany GmbH
>> Private:  http://marc.vos.net/
>> * * * * * * * * * * * * * * * * * * * * * * * *
>>
>>
>>
>> On 01-06-2005 10:40, "Ke Carlton" <[hidden email]> wrote:
>>
>>> designke.com - Personalised design and development, London based.Hello,
>>>
>>> Am having problems getting reading a line of a text file cast as a file
>>> object. Instead of reading a line number it reads a character count as
> if in
>>> character mod. I've also tried specifying an -FileEndOfLine with '\r\n'
> and
>>> '\r' and '\n' but to no avail.
>>>
>>> The code's fairly simple - if some can see a error or help that would be
>>> great.
>>>
>>> The server is OSX and lasso is version 8.
>>>
>>> <?lassoscript
>>> Var:'File'=(File: '/emailexport.txt', File_OpenRead, File_ModeLine);
>>>      loop:10;
>>>           var:'lc'=loop_count;
>>>           var:'insert'=$File->(Read:$lc);
>>>           output:$insert'<BR>',-encodenone;
>>>      /loop;
>>> ?>
>>>
>>
>>
>>
>> --
>> ------------------------------
>> Lasso Support: http://support.omnipilot.com/
>> Search the list archives: http://www.listsearch.com/lassotalk.lasso
>> Manage your list subscription:
>> http://www.listsearch.com/lassotalk.lasso?manage
>



--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage