Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Think for yourself.

by zengargoyle (Deacon)
on Oct 06, 2003 at 05:43 UTC ( [id://296869]=note: print w/replies, xml ) Need Help??


in reply to Re: Think for yourself.
in thread is the use of map in a void context deprecated ?

my @L = map { fix($_->[4]); fix($_->[8]); [ @$_[0,2,3,6,4,8] ] } grep { @$_ == 10 and ($_->[7] eq 'IP') and ($_->[9] eq 'local') } map { [ split ] } <F>;

i think map in void context is just fine. if i decided to place my data in a hash for later lookup i just might do so at the end of the first map (instead of returning an array of arrays). i'm sure i wouldn't try and re-craft the code to use a for just to appease.

much in the same way i use the 'useless' cat in my shell pipelines.

$ cat foo.txt | fgrep blah

it's much easier to decide to add more files to the cat (try that with <file ). or to replace the cat with another command that generates the data. why on earth would i continuously rewrite my commands when i can up-arrow and add easily to the beginning?

$ fgrep blah <foo.txt | consolidate | dump $ preproc <foo.txt | fgrep blah | consolidate | dump $ additional <foo.txt | preproc | fgrep blah | consolidate | dump # vs $ cat foo.txt | fgrep blah | consolidate | dump $ cat foo.txt | preproc | fgrep blah | consolidate | dump $ cat foo.txt bar.txt | additional | preproc | fgrep blah | consolidat +e | dump $ real_stream | additional | preproc | fgrep blah | consolidate | dump

i'll keep my useless cat and my map in void context thank you much. they're my artifacts of iterative development.

Replies are listed 'Best First'.
Re: Re: Re: Think for yourself.
by MarkM (Curate) on Oct 06, 2003 at 05:47 UTC

    I don't get it. You haven't used map in void context. Also, I'm not convinced that you haven't purposefully written your code inefficiently just to prove that map is useful. Why do you have the intermediate grep when an if in the for loop would do just fine? Sure, copying lists around is *fairly* cheap, but we come to my original point: Did you actually take a step back before designing your code, to ensure that it works best? Or did you just string map and grep together until it worked the way you wanted it to?

      Iterative development is a style where you write something and then modify it in a series of small iterations until it does what you want.

      Which means that he did indeed string maps and greps together until it worked the way he wanted to. As part of a deliberate coding style.

      I respect that style because it sometimes is mine as well. I've seen it be particularly popular among people who believe in some or all of; test-first development, dynamic programming techniques, and rapid prototyping.

      Proponents will claim that it produces more robust code in less development time. They will not claim that it produces the fastest code in the world, but then again there is no need to optimize what is already fast enough...

Re^3: Think for yourself. (learn your tools (bash))
by Aristotle (Chancellor) on Oct 06, 2003 at 11:17 UTC
    $ fgrep blah <foo.txt | consolidate | dump $ preproc <foo.txt | fgrep blah | consolidate | dump $ additional <foo.txt | preproc | fgrep blah | consolidate | dump # vs $ cat foo.txt | fgrep blah | consolidate | dump $ cat foo.txt | preproc | fgrep blah | consolidate | dump $ cat foo.txt bar.txt | additional | preproc | fgrep blah | consolidat +e | dump $ real_stream | additional | preproc | fgrep blah | consolidate | dump
    First of all, you're using a shell that's not braindead. Take the time to absorb its expressiveness.
    $ < foo.txt fgrep blah | consolidate | dump $ < foo.txt preproc | fgrep blah | consolidate | dump $ < foo.txt additional | preproc | fgrep blah | consolidate | dump
    Yes, that's valid code, go ahead and try. And you still don't need to edit more than one place to add multiple files.
    $ < foo.txt fgrep blah | consolidate | dump $ < foo.txt preproc | fgrep blah | consolidate | dump $ <(cat foo.txt bar.txt) additional | preproc | fgrep blah | consolida +te | dump $ real_stream | additional | preproc | fgrep blah | consolidate | dump
    You don't need crutches in bash. If you need them, something is wrong with your tools.

    Makeshifts last the longest.

      i couldn't make your

      <(cat file ...)
      example to work, but i've seen the nice bash funcionality in the man pages...

      sadly i can rarely use it. most of my co-workers are stuck in csh hell not even willing to go to tcsh for tab-completion and arrow-history, much less bash despite my constant proselytization. we still have old Solaris boxes without bash that will never have bash (but have Perl 5.003 or so). so it's sh/csh compatible only for me...sigh

      that and the whole Linux vs Solaris with all of the different versions of commands that do slightly different things keeps me going to Perl for anything complex.

      when all our boxes are Solaris 9 with bash i promise to study it more.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found