Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Perl] Besseres Konstrukt hierfür?

Empfohlene Antworten

Veröffentlicht

Hallo...

Also, ich kann mir gut vorstellen, daß diese Frage recht banal ist, aber kann mir jemand eine bessere Lösung für dieses Konstrukt zeigen:


$time = localtime();

(@Zeit)=split(/ /,$time);


if (@Zeit[1] eq 'Jan') {@Zeit[1] =  1;}

if (@Zeit[1] eq 'Feb') {@Zeit[1] =  2;}

if (@Zeit[1] eq 'Mar') {@Zeit[1] =  3;}

if (@Zeit[1] eq 'Apr') {@Zeit[1] =  4;}

if (@Zeit[1] eq 'May') {@Zeit[1] =  5;}

if (@Zeit[1] eq 'Jun') {@Zeit[1] =  6;}

if (@Zeit[1] eq 'Jul') {@Zeit[1] =  7;}

if (@Zeit[1] eq 'Aug') {@Zeit[1] =  8;}

if (@Zeit[1] eq 'Sep') {@Zeit[1] =  9;}

if (@Zeit[1] eq 'Oct') {@Zeit[1] = 10;}

if (@Zeit[1] eq 'Nov') {@Zeit[1] = 11;}

if (@Zeit[1] eq 'Dec') {@Zeit[1] = 12;}


$Datum = "@Zeit[3].@Zeit[1].@Zeit[5]";

Danke für eure Hilfe :-)))

Jestertales

  • 3 Wochen später...

Hallo,

hier ist das was du suchst.

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$year += 1900; # da Jahr 1900 = Jahr 0 in Perl-Zeit ist

$mon += 1; # da Index 0-11

Wenn du auch noch die Datumsausgabe formatieren willst, dann hilft dir printf/sprintf.

cya

alligator

Original geschrieben von Jestertales

Also, ich kann mir gut vorstellen, daß diese Frage recht banal ist, aber kann mir jemand eine bessere Lösung für dieses Konstrukt zeigen:

Wenn es nur um das Konstrukt geht, ist es besser ein assoziatives Array zu nehmen.

%monate = ("Jan" => 1,"Feb" => 2,"Mar" => 3);

@Zeit[1] =$monate{@Zeit[1]}; // ungetestet, kann sein das in die geschweiften Klammern noch Hochkommata oder so müssen.

Direkt ne Datumsfunktion zu nutzen, ist aber falls möglich die beste Lösung.

Gruß Jaraz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.