Thread externes File laden & variable ersetzen (17 answers)
Opened by ack at 2008-05-20 09:30

renee
 2008-05-20 11:31
#109965 #109965
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Wenn $foo global ist, dann geht's:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl

use strict;
use warnings;

my $content = do{ local $/; <DATA> };
our $foo = 'hallo';

no strict;
$content =~ s/\$(\w+)/${$1}/eg;
print $content;

__END__
text text $foo text $foo text 


Code: (dl )
1
2
C:\>perl test.pl
text text hallo text hallo text


Während mit "my":

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl

use strict;
use warnings;

my $content = do{ local $/; <DATA> };
my $foo = 'hallo';

no strict;
$content =~ s/\$(\w+)/${$1}/eg;
print $content;

__END__
text text $foo text $foo text


Code: (dl )
1
2
3
4
C:\>perl test.pl
Use of uninitialized value in substitution iterator at test.pl line 10, <DATA> line 1.
Use of uninitialized value in substitution iterator at test.pl line 10, <DATA> line 1.
text text text text
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/

View full thread externes File laden & variable ersetzen