1 2
if ($description !~/WYSIWYG/ig) {$description =~s/\n/<br>/g}; $itemSet{'item'}{'description'} = $description;
1
2
perl -wE '$description = qq(fooWYSIWYG\nbar); say $description !~/WYSIWYG/ig ? $description =~s/\n/<br>/gr : $description;'
perl -wE '$description = qq(fooWYSIWOG\nbar); say $description !~/WYSIWYG/ig ? $description =~s/\n/<br>/gr : $description;'
1
2
perl -wE '$description = qq(fooWYSIWYG\nbar); say $description !~/WYSIWYG/ig ? $description =~s/\n/<br>/gr : $description;'
perl -wE '$description = qq(fooWYSIWOG\nbar); say $description !~/WYSIWYG/ig ? $description =~s/\n/<br>/gr : $description;'
$itemSet{'item'}{'description'} = $description !~/WYSIWYG/ig ? $description =~s/\n/<br>/gr : $description;
use 5.010;
http://search.cpan.org/dist/perl-5.14.0/pod/perldelta.pod...
Non-destructive substitution
The substitution (s///) and transliteration (y///) operators now support an /r option that copies the input variable, carries out the substitution on the copy, and returns the result. The original remains unmodified.
my $old = "cat";
my $new = $old =~ s/cat/dog/r;
# $old is "cat" and $new is "dog"
This is particularly useful with map. See perlop for more examples.
1
2
3
$foo = "la\nle\nlu";
( $text ) = map { $_ !~ m/WYSIWYG/ig && s/\n/<br>/gr } $foo;
say "TEXT4: $text";
1
2
3
$foo = "la\nle\nlu";
( $text ) = map { $_ !~ m/WYSIWYG/ig && s/\n/<br>/g; $_ } $foo;
say "TEXT4: $text";
Guest Jankann man diese beiden Zeilen zu einer zusammenfassen?
1 2 3 4
$itemSet{'item'}{'description'} = $description !~/WYSIWYG/i ? do{ $description =~s/\n/<br>/g}; $description; } : $description;
1 2 3 4 5 6
$itemSet{'item'}{'description'} = do { $description =~ s{\n}{<br>}g if $description !~ m{WYSIWYG}i; $description; }; say "TEXT $text";
1 2 3 4 5 6 7 8 9 10
my $itemSet = bless{ item => {} }; sub desc{ my $self = shift; my $descr = shift; $descr =~ s{\n}{<br>}g if $descr !~ m{WYSIWYG}i; $self->{item}{description} = $descr; } $itemSet->desc("hier die Beschreibung mit einem WySi reingefummelt..\nneue Zeile");
2018-01-12T13:23:19 rostiMit einer bedingten Zuweisung (ternär Operator) kann man die Zeilen zusammenfassen
1 2 3
$description =~ s{\n}{<br>}g if $description !~ m{WYSIWYG}i; $itemSet{'item'}{'description'} = $description;
QuoteWarum willst Du das eigentlich zusammenfassen? Grundlegend ist das doch gut so.
Guest Jan– Nicht, ob wir das gut und schön finden.kann man diese beiden Zeilen zu einer zusammenfassen?