Skip to content
Gentilhomme edited this page Jan 30, 2017 · 5 revisions

Filereader

A little class to manage output file (with robots or some debug informations).

use perluim::filereader; 

my $file = new perluim::filereader('robots.txt');
my ($rc,@rows) = $file->load();
if($rc) {
    foreach(@rows) {
        $Console->print("$_");
    }
}

my @Arr = ('s00v09930235','s00v09930236');
$file->save('superwoman.txt',\@Arr);

Variables

Name Type
fileName string
content string or array
How to use variables
$Console->print($file->{variableName});

API

load(fileName?: string)

Return array of string

Return all lines in a array. Put fileName argument if your class does'nt have a fileName like this :

my @Arr;
$Arr = new perluim::filereader()->load('file.txt');
# OR
$Arr = new perluim::filereader('file.txt')->load();

loadString(fileName?: string)

Return string

Return all lines as String (usefull if you want to load a SQL Request etc..).

my $SQL_Str = new perluim::filereader('createTable.sql')->loadString();

# .. DBI do($SQL_Str) 

save(output: string,array: refArray,ObjectKey?: string)

Dont forget to escape the array with \ (it's an arrayRef).

my @Arr = ('s00v09930235','s00v09930236');
file->save('serversList.txt',\@Arr);

if you want to echo robot name from an array of robot Object use the argument ObjectKey

my ($RC,@Robots) = $hub->arrayRobots(); 
if($RC == NIME_OK) {
    new perluim::filereader()->save('serversList.txt',\@Robots,'name');
}
Clone this wiki locally