Farid Hajji: Perl - Einführung, Anwendungen, Referenz
2., aktualisierte und erweiterte Auflage
Addison-Wesley Longman, ISBN 3-8273-1535-2
stringparts2.pl
#!/usr/local/bin/perl -w
# stringparts2.pl -- unpack() und automatische Template-Erzeugung.
use vars qw (@listcat @listwh); # Unterdrueckt Warnungen.
# Der Eingabestring:
$input = "1234567" x 100; # 100mal "1234567" aneinandergehaengt.
# Verwendung des Konkatenationsoperators:
for ( 1 .. 100 ) { $template .= "a7 "; }
@listcat = unpack($template, $input);
# Verwendung des Wiederholungsoperators:
@listwhl = unpack("a7 " x 100, $input);
# $listcat[0] bis $listcat[99] enthalten alle den String "1234567"
# Dasselbe gilt fuer $listwhl[0] bis $listwhl[99], z.B:
print '$listcat[47]: >', $listcat[47], "<\n";
print '$listwhl[98]: >', $listwhl[98], "<\n";
# Ausgabe: $listcat[47]: >1234567<
# $listwhl[98]: >1234567<
[Prev] [Up] [Relevant Chapter] [Next]
[Alte Quelle]
| Last modified: $Date: 2006/05/18 12:56:06 $ FH. Search :: Sitemap :: Disclaimer :: Copyright :: Privacy |
|