HEREDOC tricks, etc.
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Sun, 28 Oct 2007 22:13:50 +0100
# does Perl need a qs-operator?
perl -wle '
my $s = join $", qw<
ab
cde
f
ghijk
>;
print $s;
'
ab cde f ghijk
# bash -HEREDOC alike:
perl -wle'
(my $s = <<EOS) =~ s/(^\s+|\s+$)//mg;
ab
cde
f
ghijk
EOS
print $s;
'
ab
cde
f
ghijk
# qw-emulation
perl -wle'
my @s = split " ", <<EOS;
ab
cde
f
ghijk
EOS
print "<$_>" for @s;
'
<ab>
<cde>
<f>
<ghijk>
(the above occurences of <<EOS should better be written as <<'EOS' in
production code)
--
Affijn, Ruud
"Gewoon is een tijger."
.
- Prev by Date: FAQ 8.5 How do I read just one key without waiting for a return key?
- Next by Date: Re: configurable variables in own file?
- Previous by thread: FAQ 8.5 How do I read just one key without waiting for a return key?
- Next by thread: problems building perl modules, path question
- Index(es):