mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PrimeNet (https://www.mersenneforum.org/forumdisplay.php?f=11)
-   -   Quick Question about assignments (https://www.mersenneforum.org/showthread.php?t=16104)

Mr. P-1 2011-11-17 05:38

[QUOTE=chalsall;278687]You are correct. Although my script was only 12 lines vs. your 22, mine contained 299 characters while yours contained 302 (with indentation removed from both scripts). Basically, identical.[/QUOTE]

Mine contained a whole statement:

[code] ORS="\r\n"[/code]

taken from dublow's original, which as far as I can see is an adaptation to a Windows environment. It's not necessary in *nix. You also used a shorter variable name: "$To" versus "bita".

I could have merged the two tests. Instead of

[code]$5 in bita {
if (bita[$5] > $8) bita[$5] = $8
if (bitb[$5] < $11) bitb[$5] = $11
next
}

$5 ~ /[0-9]+/ {
bita[$5] = $8
bitb[$5] = $11
}[/code]

I could have written

[code]$5 ~ /[0-9]+/ {
if (! ($5 in bita) || bita[$5] > $8) bita[$5] = $8
if (! ($5 in bitb) || bitb[$5] < $11) bitb[$5] = $11
}[/code]

LaurV 2011-11-17 05:49

[QUOTE=Mr. P-1;278849]The ideal computer language has just one statement:

"Do what I want".[/QUOTE]
That is implemented already. The computers do what you told them to do, and not what you intended to tell them to do. :smile: (or what you believe that you told them to do).

Dubslow 2011-11-17 06:42

Indeed, it is for Winblows. I was wondering about the regex, but what it output worked just fine, seeing as the only numbers to be parsed are the ones we need.

Christenson 2011-11-17 06:47

:blush:Perhaps it is time I learned awk...but what I would say of perl is:
1) It is a GENERAL tool. I'd argue that unless the user has a lot of work to do that the specific tool is really good at, the general tool is better. This is not the case here; this is a one-off that will soon be forgotten when the task is over.
2) Perl is designed as a conscious attempt to minimise the amount of programming effort for one-off problems.
3) If sed can do it, perl has a "sed" mode.

Now, let's fight!!!:boxer::rant::furious::glare::cmd::squash::deadhorse::raman::fight::dnftt::tank::ouch:
Anyone know what I should look at on the net besides "man awk"?

Dubslow 2011-11-17 06:48

[url]http://www.grymoire.com/Unix/Awk.html[/url] is what I used to crap together my not-a-program.

Mr. P-1 2011-11-17 11:50

[QUOTE=Christenson;278871]:blush:Perhaps it is time I learned awk...but what I would say of perl is:
1) It is a GENERAL tool. I'd argue that unless the user has a lot of work to do that the specific tool is really good at, the general tool is better. This is not the case here; this is a one-off that will soon be forgotten when the task is over.[/quote]

If you have both tools, and are equally adept at using both, then you would naturally choose to tool best suited for the job at hand, regardless of whether you have a lot of similar work or not.

If you only have the general tool, it might be worth acquiring the specific tool if you did have a lot of work that it's really good at. If you only have the specific tool, it might be worth acquiring the general tool if you had even a little work the specific tool was not good at.

[quote]2) Perl is designed as a conscious attempt to minimise the amount of programming effort for one-off problems.[/quote]

Indeed. Larry Wall [url=http://dev.perl.org/perl6/talks/2000/als/larry-als.txt]said[/url] there was a subset of perl that looks like AWK.

[quote]3) If sed can do it, perl has a "sed" mode.[/quote]

I use sed for simple substitutions. I know it can do more than that, but I've never bothered to learn.

[quote]Anyone know what I should look at on the net besides "man awk"?[/QUOTE]

dunno. I just use GAWK info.


All times are UTC. The time now is 11:18.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.