8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Links laden
##############
my ( @data, @links, @texts );
if (! -f $file ) {
&create_linklist;
}
else {
open ( F, '<', $file ) || die "Could not open $file. $!";
@data = grep { /^[^#]/ } <F>;
close F;
$i = $k = 0;
foreach ( @data ) {
chomp ( $_ );
if ( $_ =~ /^LINK:\s/ ) {
$_ =~ s/^LINK:\s//;
$links[$i] = $_;
$i++;
}
else {
$_ =~ s/^TEXT:\s//;
$texts[$k] = $_;
$k++;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Links laden
##############
my ( @data, @links, @texts );
unless (-f $file) {
&create_linklist;
} else {
open ( F, '<', $file ) || die "Could not open $file. $!";
@data = grep { /^[^#]/ } <F>;
close F;
foreach ( @data ) {
chomp;
s/^([LINK|TEXT]:)(.+)/$2/;
if ($1 eq 'LINK') { push @links }
else { push @texts }
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my $file = "....";
my (@links, @texts);
unless (-f $file) {
# &create_linklist ohne klammern bedeutet &create_linklist(@_) !!!
&create_linklist();
}
else {
open (my $FH, "<", $file ) or die "Error: couldn't read '$file': $!\n";
my @data = grep { not /^\s*\#/ } <$FH>;
close( $FH );
chomp( @data );
my @links = ();
foreach my $line (@data) {
if ( $line =~ s/^LINK:\s*/ ) { push (@links, $line) }
elsif( $line =~ s/^TEXT:\s*/ ) { push (@texts, $line) }
else { print "invalid: $line\n" }
} # foreach
} # else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
#open ( F, '<', $file ) || die "Could not open $file. $!";
my %lut;
/^(LINK|TEXT):(.*)$/ and push @{$lut{$1}}, $2 while (<DATA>);
die Dumper \%lut;
#close F;
_ _DATA_ _
#wgongwog
LINK:http://www.perl-community.de
#1324wgongwog
#
LINK:http://www.example.com
TEXT:there is more than one way to do it
LUI:bla
#
8 Einträge, 1 Seite |