Schrift
[thread]8283[/thread]

Addition



<< >> 4 Einträge, 1 Seite
Gast Gast
 2006-08-30 16:09
#69433 #69433
Hallo,
wie kann ich eine Addition durchführen, wo die erste(n) Zahl(en) eine 0 ist?

Bsp:

$Inhalt = 03.01.0000.0001;

my @array=split(/\./,$Inhalt);
#print $array[3];

$Inhalt2 = $array[3];

print $Inhalt2 + 1;

--> Jetzt sollte die Variable $Inhalt2 0002 sein...

danke schon mal
vayu
 2006-08-30 16:26
#69434 #69434
User since
2005-01-13
782 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl

use strict;
use warnings;

my $Inhalt = "03.01.0000.0001";

my @array=split(/\./,$Inhalt);

my $Inhalt2 = $array[3] + 1;

$Inhalt2 = sprintf("%04d", $Inhalt2);

print $Inhalt2;


für ein split solltest du die variable $Inhalt auch als String angeben. du hast bei dir keine hochkommas um die Zahl herum gesetzt.\n\n

<!--EDIT|vayu|1156941047-->
renee
 2006-08-30 16:31
#69435 #69435
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Da musst Du mit sprintf arbeiten...

Code: (dl )
print sprintf("%04d",$Inhalt2 + 1)
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
cytrics
 2006-08-30 16:38
#69436 #69436
User since
2006-08-30
8 Artikel
BenutzerIn
[default_avatar]
Wow, cool, danke...
<< >> 4 Einträge, 1 Seite



View all threads created 2006-08-30 16:09.