Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
tef
May 30, 2004

-> some l-system crap ->

syphon^2 posted:

Basically, my question is, where do I go from here? ... I enjoy coding in Perl and want to learn more, even if that means going to Python or Ruby.

Learning other languages is a good idea, but you might want to get more confident in perl first. You will programming idioms you can bring to other languages, and ruby or python won't seem so much of a big step.

If you understand the web model, have you considered branching out somewhat? A simple web server would cover using file and network i/o, as well as simple parsing for http/1.0. It's up to you how far you go with using libraries, as you could avoid writing a lot of code, and get a working project quicker.

It will also allow you to gain a deeper understanding of the tools you use every day.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Triple Tech posted:

I feel like all the temporary variables we use pollute the namespace. Like, certain structures aren't used for anything but the derivation of the last data structure. So I figured, why not tuck it into one temporary scope.

Isn't that what my is for?

code:
my $main = "outer";
{
    my $temp = "yes";  # create a lexically scoped variable
    $main="inner";     # set the outer variable
    print "Inner: main=$main, temp=$temp\n";
}                      # temp is deallocated
print "Outer: main=$main, temp=$temp\n";
Inner: main=inner, temp=yes
Outer: main=inner, temp=


quote:

I have this new coding style I've adopted, and personally, I like it. But I'm pretty sure no one else is keen on it. What do you guys think?

Here is a simple metric to evaluate coding styles:

Does it make the code simpler?
Does it make the code more general?
Does it make the code clearer?

Yours doesn't make the code simpler, or clearer.

tef fucked around with this message at 20:59 on Oct 30, 2007

tef
May 30, 2004

-> some l-system crap ->

Triple Tech posted:

I don't understand what you're trying to say with this. By your logic, a stream of ones and zeros is perfect, because there's nothing left to take away. But that doesn't mean it's good for programming. Similarly, just because Perl 5 is pretty good on its own now doesn't mean it is immune from things to which it is insufficient in the future, like multi-methods and concurrency.

The original quote is "Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exuper

Or simply A perfect system is one with no unnecessary parts. It is often cited as an argument for minimalism and simplicity in design. You could also argue that a product with conceptual integrity has a small set of well chosen orthogonal features.

You could make the argument that while loops are unneccesary as we have for loops, if statements if we have conditional gotos - but it wouldn't be a very convincing argument. You could argue that brainfuck is perfection in terms of features removed, but not in terms of usable features left.

A similar quote might be "Make everything as simple as possible, but not simpler." -- Albert Einstein. Again we can see the theme of simplicity not being the bare minimum of what is needed, but also not having too much. Striking a balance is hard, and perl tends to err much more on the having too much (You could equally accuse other languages of being too simple).

I can't speak for him, but I guess his point is that Perl 6 might have too many features (or even featuritis). Perl has always been guilty of this in it's own polyglot way, though.

What other languages see as design choices, larry sees as developer choices:

Prototypes vs Class Based OO
Single vs Multiple Inheritance (and traits!)
Lazy vs Strict Evaluation
Static vs Dynamic Typing
And so on...

The problem here is that perl is becoming more of a series of dialects than a language itself. I often poked fun at people asking them if they coded basic in perl, c in perl or sh in perl - and it is becomming more true as more language paradigms are being embraced into perl 6.

Going back to the original quote: I think perl 6 would have had a better start if they removed features from perl 5 first before starting to add them. A lot of the changes (fixed sigils, simplified syntax) would have been possible to migrate into the existing code base.

The complete rewrite stalled all real progress until someone started to write it in haskell. I don't think larry was right to abandon the perl interpreter, and slowly but surely the perl5-porters are cleaning up the mess he left behind.

In summary: Minimalism and Simplicity are easy ways to maintain conceptual integrity in a product. Removing features can be more important than adding them. Perl 6 suffers from the second system effect.

tef
May 30, 2004

-> some l-system crap ->

Ninja Rope posted:

However, it seems like some things are being added gratuitously to Perl5 (and 6), like the "say" function. We've already got print and $\, and printf, and they're adding another builtin to do something similar?

I quite like say, I think it makes code more idiomatic and cleaner. It is not just about a few less characters, but making the code more obvious. You can see from the beginning if it is printing a new line or not.

Edit: $\ is not exactly a readable name. I imagine most people would use join(,) for adding record seperators. print "...\n" is really really common, and I don't think it is that bad to have a short hand.

Triple Tech posted:

And then verbosity gets into how people think in terms of chunks and lines of code, despite what language they're in... Terseness rules, Perl wins.

Remember: Code is much harder to Read than to Write. Perl excells at having short easy eays of writing idiomatic code, but it's a lot easier in perl to create things like this:

code:
for(<>){($f{$n}+=()=$t=~/gently caress/g)if($n,$t)=(/.{8}([^>]+)..(.*)/)}
$p{$f{$_}}.=":$_"for(keys%f);
print"$_$p{$_}\n"for(sort{$a<=>$b}keys%p)
Which, even with spacing and indentation:
code:
for (<>) {
 ($f{$n}+=()=$t=~/gently caress/g) if ($n,$t)=(/.{8}([^>]+)..(.*)/);
}

$p{$f{$_}}.=":$_" for (keys %f);

print "$_$p{$_}\n" for (sort{$a <=> $b} keys %p);
Is still pretty ugly. Neither Verboseness or Terseness is the objective of a good program, simplicity and clarity are.

(edit: double negative).

tef fucked around with this message at 17:32 on Dec 9, 2007

tef
May 30, 2004

-> some l-system crap ->

Satan's Scallion posted:

If you spend most of your time writing classes, perl loses the terseness war pretty quickly.

Aside: if you write a lot of oo perl, you might be interested in Moose: http://search.cpan.org/~stevan/Moose/lib/Moose.pm

code:
  package Point;
  use Moose; # automatically turns on strict and warnings

  has 'x' => (is => 'rw', isa => 'Int');
  has 'y' => (is => 'rw', isa => 'Int');

  sub clear {
      my $self = shift;
      $self->x(0);
      $self->y(0);
  }

  package Point3D;
  use Moose;

  extends 'Point';

  has 'z' => (is => 'rw', isa => 'Int');

  after 'clear' => sub {
      my $self = shift;
      $self->z(0);
  };
Edit: Pythons oo stuff is much cleaner though, I wish I had picked that as an example of terseness.

Edit 2:

Have you seen the perldelta for 5.10 ? http://search.cpan.org/~rgarcia/perl-5.10.0-RC2/pod/perl5100delta.pod It looks neat!

tef fucked around with this message at 07:19 on Dec 9, 2007

tef
May 30, 2004

-> some l-system crap ->

Triple Tech posted:

I'm not saying that Perl is the end-all-be-all of terseness and that terseness is the One True Dimension by which one judges code. Of course not, that's silly.

A bit different from "Terseness rules, Perl wins.". I think I will repeat myself here:

"Neither Verboseness or Terseness is the objective of a good program, simplicity and clarity are." (I missed out generality from that list.)

Terseness is not a useful measure of program quality at all - Clarity is a significantly better measure.

In the same way being able to implement something in a short amount of lines is terse, you would be better arguing that (in general) shorter programs are clearer and easier to read (as well as write) than longer ones. It is possible to write something too short though, again finding a balance between terseness and verbosity is essential. Simple things should be terse, but often complex things have to be verbose.

With regards to the Paul Graham article: (Again) "Code is much harder to read than to write".

If you are under the illusion that we should optimise languages so it is fast to write rather than read, I hope I never have to maintain your code.

quote:

What is it that you can add to a programming language to say less, but still remain flexible.

Again, adding features is not the be all and end all of language design. It is important to ask what can you remove from a language and still remain flexible?

There is a lot of baggage in perl left over from perl 1 to 4. An example in this thread is Bareword filehandles.

Adding more features does not always make a language more powerful. It can make the language more unwieldy.

Here is a pictorial argument:

This is the *actual* swiss army knife:


This is what happens when you add features, even if each tool itself is distinct and useful:



Edit: If you're still interested in arguing I would suggest we take this to a different thread.

Edit: I guess my point is that there is a limit to how many features you can add to a language before they become more of a hindrance, and sometimes languages become more useful by removing features.

tef fucked around with this message at 18:06 on Dec 9, 2007

tef
May 30, 2004

-> some l-system crap ->

poofactory posted:

What do I add to the perl script to take care of this?

A developer.

You are handling credit card details, so if you don't know about CGI, form escaping or the difference between "$Amount" and "Amount" it is time to give up and find someone who can.

(Sorry for the turn about, I was willing to give you the benefit of the doubt in missing something obvious - but your later posts expose your inexperience fully)

tef
May 30, 2004

-> some l-system crap ->
Post your code?

tef fucked around with this message at 19:34 on Apr 7, 2008

tef
May 30, 2004

-> some l-system crap ->
(from irc)

Eval is not run in a sandbox:

code:
$ perl
$a = 10 ; $b = 'my $a = 11;' ; eval $b ; print $a ; print "\n";
10

$ perl
$a = 10 ; $b = '$a = 11;' ; eval $b ; print $a ; print "\n";
11
Welcome to the world of lexical scope :D

tef fucked around with this message at 19:50 on Apr 7, 2008

tef
May 30, 2004

-> some l-system crap ->

Khorne posted:

How do I convert an a4 value in perl (DWORD) to a string, or at least a decimal/hexadecimal number that I can pad some how?

I'm not sure what you need to do, but it sounds like you need :

http://perldoc.perl.org/functions/unpack.html

http://perldoc.perl.org/functions/pack.html

tef
May 30, 2004

-> some l-system crap ->

GregNorc posted:

Any ideas how to fix this? I even looked in the appendix for the answer, and still no luck.

For a start: turn on warnings and use strict; Avoid the use of $_, and be a little bit more explicit about what you're trying to do rather than relying on perl.


code:
#!/usr/bin/perl -w

use strict;

sub total {
        my $sum;
        foreach my $num (@_) {
                $sum += $num;
        }
        return $sum;
}

my @fred = qw{ 1 3 5 7 9};
my $fred_total = &total(@fred);

print "The total of \@fred is $fred_total.\n";

print "Enter some numbers on seperate lines: \n";

my $user_total = &total(<STDIN>);

print "The total of those numbers is $user_total.\n";
And like the poster above me I've had no problems running the code.

tef
May 30, 2004

-> some l-system crap ->

mister_gosh posted:

How can I NOT store the path for the files I put in a zip archive?

Your code doesn't run for me, but there is a second parameter to addFiles which can specify the name of the zip in the file.

I.e do $zip->addFile( $file,$file_name_without_directories )

http://search.cpan.org/dist/Archive-Zip/lib/Archive/Zip.pm#Zip_Archive_Member_Operations

tef
May 30, 2004

-> some l-system crap ->
You could just do this:

code:
#!/usr/bin/perl
use strict;

#ThreeDigitMost loops through the stripped numbers, then stores 
#which ones came up the most often in a hash. 
#This hash is then sorted and printed.

my %ThreeHash;  
while (<>) {
        chomp; 
        $ThreeHash{$_}++;
}
foreach my $key (sort {$ThreeHash{$a} <=>$ThreeHash{$b}} (keys(%ThreeHash))) {
        print "$key appeared $ThreeHash{key} times\n";
}
The idiom you might like is the: http://en.wikipedia.org/wiki/Schwartzian_transform

code:
#!/usr/bin/perl
use strict;

my %ThreeHash;  

while (<>) {
        chomp; 
        $ThreeHash{$_}++;
}

@sorted = map  { $_->[0] }
          sort { $a->[1] cmp $b->[1] }
          map  { [$_, $ThreeHash($_)] }
          keys(%ThreeHash);

foreach my $key (@sorted) {
        print "$key appeared $ThreeHash{key} times\n";
}
Alternatively: cat numbers.txt | sort -n | uniq -c

tef fucked around with this message at 02:19 on Jul 23, 2008

tef
May 30, 2004

-> some l-system crap ->

Triple Tech posted:

Am I not as good as I think I am?

Yes.

I would expect the top 1% of perl hackers to understand lexical scope.

tef
May 30, 2004

-> some l-system crap ->

Sartak posted:

That sort of thing is called dynamic scope. It was popular before (the much saner) lexical scope was invented. Perl supports it with the local operator.

It was popular with interpreted languages as it simple to implement.

tef
May 30, 2004

-> some l-system crap ->

dagard posted:

It's been a while, but I seem to recall that, by default, you can't anonymously bind to the AD server

I recently got some python code to talk to AD, and yes I had to use an existing account to bind to AD first.

Bugzilla uses Net::LDAP, and I've used it to talk to ActiveDirectory. You might be able to fish a working example out of the code base.

tef
May 30, 2004

-> some l-system crap ->
If speed is important why don't you do it in parallel ?

tef
May 30, 2004

-> some l-system crap ->

Mithaldu posted:

In fact, i have this on my "to read" list: http://gigamonkeys.com/book/

Higher order perl by mjd is well worth a read too.

tef
May 30, 2004

-> some l-system crap ->
Aside, the string "0 but true" does what it says, and doesn't throw a warning when you use it as a number.


$ perl -we "0+'0 foo'"
Argument "0 foo" isn't numeric in addition (+) at -e line 1.
$ perl -we "0+'0 but true'"
$

tef
May 30, 2004

-> some l-system crap ->
You can also use "0e0" as a true value without raising warnings.

tef
May 30, 2004

-> some l-system crap ->
aside:

sort in a void context is optimized out, and never executes.

I had a friend who would do sort {$a+=$b} @a

tef
May 30, 2004

-> some l-system crap ->
:toot: http://hop.perl.plover.com/book/ :toot:

Higher order perl is available online.

tef
May 30, 2004

-> some l-system crap ->

Captain Frigate posted:

Wow, worked like a charm! What does that actually do? The differing end-of-line conventions wouldn't really matter in this situation, would they?

http://perldoc.perl.org/functions/binmode.html

quote:

if you don't use binmode() on these systems, \cM\cJ sequences on disk will be converted to \n on input, and any \n in your program will be converted back to \cM\cJ on output. This is what you want for text files, but it can be disastrous for binary files.

tef
May 30, 2004

-> some l-system crap ->
I would assume this line is mangling them:

my ($who, $body) = $self->charset_encode($who, $body);

tef
May 30, 2004

-> some l-system crap ->
shorter columns are easier to read :eng101:

(especially when everyone's got a big screen now, with content sprawling over it)

that said I don't think the redesign is somehow 'modern' or nice either :argh:

tef
May 30, 2004

-> some l-system crap ->

Triple Tech posted:

Wow, you guys know nothing. That facelift is yards better than the design before it. And yes, that gluey top bar is executed oddly.

I can't recall what it looked like before, but it now looks like 'if slashdot did man pages'



p.s. a little bit more whitespace would be nice too :3:

tef
May 30, 2004

-> some l-system crap ->

Otto Skorzeny posted:

e: (i should mention i'm on a 1400x1050 laptop screen so there's way more empty space when i load the page than in tef's screenshot (im too lazy to take a screenshot of my own (i'm not sure i have a screenshot program installed atm and i forget the hotkey (nil ))))

I cropped it, I'm on a 1920x1200 display.

tef
May 30, 2004

-> some l-system crap ->

Sabacc posted:

Explanation, anyone?

Your working directory is not what you think it is? If the only way you can access the files is absolute and not relative, perhaps your script *isn't* running with the cwd you expect.

:confused:

tef
May 30, 2004

-> some l-system crap ->
$$ is a variable, the pid of the process iirc.

You want "\$" for a literal $

tef
May 30, 2004

-> some l-system crap ->
Have you seen larry wall?

tef
May 30, 2004

-> some l-system crap ->

qntm posted:

Why doesn't this print the letter "K"?

Standard out is line buffered. Either terminate strings with \n, or flush the buffer:

The $| variable sets 'autoflush' in perl

tef
May 30, 2004

-> some l-system crap ->
http://search.cpan.org/~sisyphus/Inline-0.47/C/C.pod :2bong:

tef
May 30, 2004

-> some l-system crap ->

baquerd posted:

There are character sets where this is not true?

unicode



also it is locale dependent

tef
May 30, 2004

-> some l-system crap ->
The same sort of people who frown own sort {$a+=$b} @foo

tef
May 30, 2004

-> some l-system crap ->

OriginalPseudonym posted:

:psyduck:

Maybe I'm misunderstanding the construct, but wouldn't that always return that $a is larger than $b, unless $b was a sufficiently large negative number to return 0 or less?

I get the feeling there's a side effect I'm missing.

sort in a void context is a no-op :eng101:

code:
shamhat:~ tef$ cat foo.pl
my @foo = (1,2,3,4,5);
sort {$a+=$b} @foo;
print "@foo\n";


shamhat:~ tef$ perl foo.pl
1 2 3 4 5
shamhat:~ tef$ 
I learned this from an intercal programmer.

tef
May 30, 2004

-> some l-system crap ->

Winkle-Daddy posted:

Anyone else have better ideas? This seems like it would be an incredibly slow job for Perl...especially since we serve content for about 2 million accounts.

keep backups, run a (trained) spam filter over the diffs :v:

more seriously, it looks like you are trying to write a virus scanner for php.

tef
May 30, 2004

-> some l-system crap ->

Winkle-Daddy posted:

Eh, more like a way to determine the probability that certain strings are base64 encoded without looking through all of the files I'm searching manually.

Which you are doing for the purposes of finding malicious code.

tef
May 30, 2004

-> some l-system crap ->
I've also heard of http://search.cpan.org/~mirod/XML-Twig-3.39/Twig.pm Xml::Twig

tef
May 30, 2004

-> some l-system crap ->

Centripetal Horse posted:

It's kind of cool to see that PERL (sorry, Perl... looks like it isn't all caps, these days) is still alive and kicking. I don't care what anyone says, I like Perl, and I loved coding in it. It's been ten years since I logged into my PerlMonks account, but I've still probably written more lines of PERL than any other single language I've used.

Who can tell what this does without cheating via Google or executing it?

s>>sp>;s>..|>\u$&ace>g;print;

the perl shibboleths I use are less :pwn:

code:
%foo = {};
code:
%bar = reverse %bar;
code:
sort {print $a+=$b} @butts;

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

het posted:

Oh, I did but I was just doing one-liners on the command line, that's funny

I learned about sort in a void context from a crazed intercal programmer.

  • Locked thread