Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^5: Murder of a Perl coder (announced)

by EdwardG (Vicar)
on Oct 15, 2004 at 18:03 UTC ( [id://399596]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Murder of a Perl coder (announced)
in thread Murder of a Perl coder (announced)

If you want to argue about C# being more verbose, you win!

But in your example %hash isn't defined (barring autoviv), so I didn't bother with hashLookup in mine. I wasn't trying to score points for brevity, if that's what matters to you.

 

  • Comment on Re^5: Murder of a Perl coder (announced)

Replies are listed 'Best First'.
Re^6: Murder of a Perl coder (announced)
by Jenda (Abbot) on Oct 15, 2004 at 18:30 UTC

    I did not ask you to define the hash/collection. I wanted you to show us how does the hashLookup() function look like. If you want a "complete" example so let's define a function that receives a template and a hash containing the values to insert into the template and returns the text with the values:

    sub fillTemplate { my ($text, $hash) = @_; $text =~ s/%(\w)%/$hash->{$1}/g; return $text; }

    How complex and twisted is the code in C#? Especialy considering the fact that the second parameter for Regex.Replace() is a delegate and that C# doesn't support unnames functions and closures? You have to define the hashLookup() as a fullblown method and you have to find a way to pass it the collection somewhere behind the scenes.

    Either it can be a static method and then you'll have a static field in the class that'll hold the reference to the collection. Or you can create a brand new class that'll contain just the hashLookup() method and the reference to the collection. Or do I miss anything?

    This is not the difference between Pascals begin-end and C's {}, there I would agree it's just an unimportant matter of verbosity. This is something so awkward, lengthy and unmaintainable that noone can be expected to use regexps. Except maybe for validations.

    Jenda
    We'd like to help you learn to help yourself
    Look around you, all you see are sympathetic eyes
    Stroll around the grounds until you feel at home
       -- P. Simon in Mrs. Robinson

      The hashLookup function would look something like this:

      string hashLookup ( Match m ) { return hash[m.Value]; }

      I might pick up your challenge to compare the C# version of sub fillTemplate in a new thread, if you don't mind, since it may have wider interest than here at Re^8.

       

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://399596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found