[Gllug] Poor scripting?!
Andrew Farnsworth
farnsaw at stonedoor.com
Tue Mar 11 18:43:42 UTC 2008
Andrew Black - lists wrote:
> Andrew Farnsworth wrote:
>
>> Henrik,
>> This won't work, mainly because the perl string operator 'eq' does not
>> recognize wild cards (i.e. the * character). You will need to do a
>> regex match to determine if ($_ =~ /cerprod$/) which will match the
>> string 'cerprod' at the end of the string contained within the $_ variable.
>>
>
> Which can more succinctly be written as
> if ( /cerprod$/ )
>
You are correct, however, I NEVER use this form as it confuses non-perl
programmers where ($_ =~ /cerprod$/) may confuse them but it gives them
something to work with and things (like $_) to search for to get help.
I write code in a land where the people who will be maintaining my code
are mostly Java and/or Javascript people.
> This is because $_ is the default operand to a match.
>
>
> > $regexp = shift @ARGV
> Would normally be written
> $regexp = shift
>
> It is a usage that is (IMHO) so common in Perl that I wouldn't stop to
> think that it is looking at @ARGV
>
Again, I would explicitly define my variables and breakup @ARGV into them.
my ($arg1, arg2, arg3) = @ARGV;
Though there are cases where you need to deal with variable number of
parameters in which case this doesn't cut it. But remember, that I am
writing for non-perl programmers to maintain it.
Andrew
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list