[WHY not HOW] Re: [Israel.pm] Quickie - Perl syntax
omerz at actcom.co.il
Wed Oct 6 04:04:59 PDT 2004
On Wed, 6 Oct 2004, Madani, Srikanth, VF-DE wrote:
> Hi all,
> I have these statements:
> $line =~ s/\s*//g; #Remove whitespace from $line. BTW, $line is "targetDir =M:\VDD\Bin32 "
> my @tdir_val = split /=/,$line;
> a) How do I combine these two statements into one line?
> b) Is there someway I can do it in one line _without_ modifying $line?
I'm leaving the "How" to people, who are more experienced in Perl than me.
However, I am intrigued by the "Why".
Given that you already wrote the code in question, "WHY" do you need to
combine those statements into one line? (Besides the intellectual
challenge of playing Perl Golf on this code snippet - in which case people
normally try to solve the problem by themselves rather than ask in mailing
- If you need the statements just in one place in the code, then I see no
need to shorten the code snippet once you have already written it.
- If you need to copy&paste the code essentially unchanged in several
places, it can be put inside a procedure.
- Even if the general pattern stays the same and the details change from
place to place, you can still copy&paste and it does not really matter
if you are copying&pasting one line or two lines.
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html
More information about the Perl