NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
you could also inline it (Score:1)
#!/usr/bin/perl
use strict;
use warnings;
my @a = (
1,
@{[map {()} warn "in here\n"]},
2,
3
);
print map { "$_\n" } @a;
Re: (Score:1)
or the slightly less stupid (I don't know why I threw it in an arrayref to start with):
#!/usr/bin/perl
use strict;
use warnings;
my @a = (
1,
(map {()} warn "in here\n"),
2,
3
);
print map { "$_\n" } @a;
Re: (Score:1)
An even shorter way to write that is this:
However, I prefer to take a page from Javascript, by defining the following amusing function:
I can then write the code in this much nicer way:
This is far nicer than Ovid’s approach as well, IMO.
Re: (Score:2)
Ah, that is a nicer solution, thanks.
return(); (Score:1)
return()with no arguments (which is what you're doing) does the "right thing" in both scalar and list contexts. It returns either an empty list or undefined value.Thus you could also have written:
return;for the same effect. I'm sure you know this already, but from your commentary and style it did look like you were trying to explicitly return an empty list.
Re: (Score:2)
Yes, I normally just use a bare return (and get annoyed when people use 'return 0' for false), but I honestly didn't think about that here because I originally had this:
That showed the annoying __LINE__ problem and I decided to be explicit about the return when I added the $line variable. Normally about the only time -- aside from this example -- I return an explicit empty list is when I do this:
Re: (Score:2)
Oh, and what I didn't say, but should have, in my first reply was "thanks". The bare return is (IMHO) a cleaner solution.
Re: (Score:1)
For less trickery with subs and call stacks and line numbers, remember your old friend 'do'!
$ perl -le'print join " ", (1, do { warn 2; () }, 3)'
2 at -e line 1.
1 3