1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Software und Anwendungen
  3. Betriebssysteme

config variable für perl UND php an einer stelle definieren

    • Linux
  • davewood
  • 27. November 2006 um 13:12
  • Unerledigt
  • davewood
    17
    davewood
    Mitglied
    Reaktionen
    9
    Punkte
    3.204
    Beiträge
    536
    • 27. November 2006 um 13:12
    • #1

    Ich hab zwei Skripte, ein PERL und ein PHP Skript die beide die gleiche Variable verwenden sollen.

    Es handelt sich um ein file upload script und dafür muss ich einen Pfad sowie eine maximale Filegröße definieren.

    momentan sind diese Werte doppelt (einmal fuer php im php file einmal fuer perl im perl file) definiert und somit ist die Wartung kompliziert und fehleranfällig.

    Am liebsten hätte ich einfach eine Zeile in meinem eigenen php config file.

    Vielen Dank im Vorraus

    david

    I like Toast!

  • bimbo
    15
    bimbo
    Mitglied
    Reaktionen
    15
    Punkte
    2.320
    Beiträge
    390
    • 27. November 2006 um 14:03
    • #2

    Kannst du nicht das config-file als reines textfile belassen und dann per perl/php parsen?
    z.B.:
    1. Zeile Pfad
    2. Zeile größe
    schöner wäre natürlich ein xml.

    LVA Erfahrungsberichte: http://vowi.fsinf.at/

  • davewood
    17
    davewood
    Mitglied
    Reaktionen
    9
    Punkte
    3.204
    Beiträge
    536
    • 27. November 2006 um 17:44
    • #3

    Hallo & Danke

    Können vermutlich schon, aber für die PHP Applikation gibts nunmal ein config file wo alles drinsteht und dort will ich den Kram auch noch hineinschreiben.

    Werd mal schaun wie sich das mit Parsen erledigen lässt. womit parst es sich denn am besten? :)

    david

    ps:

    Zitat von http://www.linuxforums.org/programming/learn_perl_in_10_easy_lessons__lesson_4.html


    Parsing files

    There are many ways to parse a text file. In Perl, if the file has its data organized line by line with delimiters, it is very easy to parse it.

    Let's study a simple example. We have a set of employees in a file called employees.txt. In this file, each line represents an employee. The information relative to each employee is delimited with tabs, the first column is the name of the employee, the second column indicates his department and the third one his salary. Here is an overview of the file:

    Mr John Doe R&D 21000
    Miss Gloria Dunne HR 23000
    Mr Jack Stevens HR 45000
    Mrs Julie Fay R&D 30000
    Mr Patrick Reed R&D 33000

    In order to obtain some statistics, the HR department wants to establish a list of all male employees who work in the R&D department and which salary is more than 25000.

    To obtain this list, we design a simple Perl script, which:

    1.

    opens the employees.txt file
    2.

    loops through each line
    3.

    identifies the name, department and salary of the employee
    4.

    ignores and goes to the next line if the employee is female (the name does not start with Mr)
    5.

    ignores and goes to the next line if the salary is less or equal to 25000.
    6.

    ignores and goes to the next line if the department is not “R&D”.
    7.

    prints the name and the salary of the employee on the screen.

    To do this, we'll introduce two Perl functions:

    *

    “chomp” is used to remove the carriage return found in the end of the line. For instance chomp $variable removes all carriage returns in the variable.
    *

    “split” is used to cut the line in different parts where it finds a delimiter. For instance split /o/, “hello world” returns an array containing “hell”, “ w” and “rld”. In our example we'll split the lines with the tab delimiter, which in Perl is written “\t”.

    Here is the script which establishes the list of male employees from the R&D department with a salary greater than 25000. To make things a bit clearer, comments were introduced within the scripts (comments in Perl start with a # sign):

    #open the employees file
    open (EMPLOYEES, "employees.txt");

    #for each line
    while ($line = <EMPLOYEES>) {

    #remove the carriage return
    chomp $line;

    #split the line between tabs
    #and get the different elements
    ($name, $department, $salary) = split /\t/, $line;

    #go to the next line unless the name starts with "Mr "
    next unless $name =~ /^Mr /;

    #go to the next line unless the salary is more than 25000.
    next unless $salary > 25000;

    #go to the next line unless the department is R&D.
    next unless $department eq "R&D";

    #since all employees here are male,
    #remove the particle in front of their name
    $name =~ s/Mr //;

    print "$name\n";
    }
    close (EMPLOYEES);

    Alles anzeigen

    Ich hoff mal des is okay wenn ich das hier so poste, evt hilfts ja mal wem anderen. :)

    david

    I like Toast!

  • Maximilian Rupp 27. Dezember 2024 um 00:11

    Hat das Thema aus dem Forum Betriebssysteme nach Betriebssysteme verschoben.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!

Benutzerkonto erstellen Anmelden

Benutzer online in diesem Thema

  • 1 Besucher

Rechtliches

Impressum

Datenschutzerklärung