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
Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

CanSpice posted:

If I have to go to my Programming Perl book to figure out what a special variable is for, I won't use it.

There are plenty of perfectly good arguments against just using special variables to golf, but does your system have neither perldoc nor google? perlvar is pretty readable and searchable

Adbot
ADBOT LOVES YOU

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
To be fair special variables are basically impossible to google for. The further explosion of punctuation is one reason I dislike Perl 6.

Fenderbender
Oct 10, 2003

You have the right to remain silent.
Just going to reask this:

Fenderbender posted:

On that note, how would I go about altering the delagations (handles) for an attribute. My idea is to call the fields method on a Rose::DB::Object subclass and then push that all to a specific attribute's delegations. Haven't been able to figure out how to do this yet but it will solve a lot of upcoming issues I'm going to have to slave over if I don't do this now.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Filburt Shellbach posted:

To be fair special variables are basically impossible to google for. The further explosion of punctuation is one reason I dislike Perl 6.

This is stupid. If you're within reach of Google, you're within reach of perlvar.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Triple Tech posted:

This is stupid. If you're within reach of Google, you're within reach of perlvar.

This is stupid. Google knows many orders of magnitude more about Perl than perldoc does.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Did I mention the flip flop operator is cool as heck lately? Scraping function signatures from manpages:
code:
my ($start_decl, $end_decl) = (qr/[\s\*]$func\([^\)]/ , qr/\)/);
for (@lines) {
    if (/SYNOPSIS/ .. /DESCRIPTION/) {
        if (/$start_decl/ .. /$end_decl/) {
            $sig .= $_;
        }
    }
}
This replaced a whole bunch of stupid mess, and preserves whitespace to boot

MolluskGoneBad
Feb 25, 2002
So I have a small project that needs to be distributed as a binary executable. It involves a lot of string manipulation.

It's been a few years since I programmed anything, I never did anything too complicated, and when I did it was C or C++. I was thinking I should use something friendlier for text than one of those, especially since the last developers of an analogous project used CPLAT and left an unmaintainable mess. Should I bother to learn Perl for this one, and is there an easy way to turn Perl scripts into binaries?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

MolluskGoneBad posted:

is there an easy way to turn Perl scripts into binaries?

As long as you only want to distribute as a single file for ease-of-use purposes, you're probably best off using PAR to package your script and all its dependencies as a single executable; it works very well and is just about as seamless as you can get for users.

If you're hoping to get some sort of security from compiling to a binary, you're pretty much out of luck. But Perl isn't really any different from any other language in this regard; binaries from any language are not particularly hard to decompile for a motivated hacker.

MolluskGoneBad
Feb 25, 2002

ShoulderDaemon posted:

As long as you only want to distribute as a single file for ease-of-use purposes, you're probably best off using PAR to package your script and all its dependencies as a single executable; it works very well and is just about as seamless as you can get for users.

If you're hoping to get some sort of security from compiling to a binary, you're pretty much out of luck. But Perl isn't really any different from any other language in this regard; binaries from any language are not particularly hard to decompile for a motivated hacker.
Ah perfect. Thanks.

Yeah, it's ease of use for our editors, some of whom require babysitting for anything trickier than "Click Here", some of whom would be wont to go and muck around with the scripts.

CanSpice
Jan 12, 2002

GO CANUCKS GO

Triple Tech posted:

This is stupid. If you're within reach of Google, you're within reach of perlvar.

I can get perlvar on my iPhone?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

CanSpice posted:

I can get perlvar on my iPhone?

You sho can, little boy! Just point yer Safaris to here!

Paradox
May 19, 2003
I have a script that calls tar in a call to system(). While the script was running I decided to kill it with control c. What it did wasn't what I expected. Instead of killing the script it just killed tar and went straight to the next line in the script.

What is the mechanism that is causing this behavior and how can I make the script die like I want it to?

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
http://perldoc.perl.org/perlfaq8.html#How-do-I-make-a-system()-exit-on-control-C%3f

Kidane
Dec 15, 2004

DANGER TO MANIFOLD
If I may be so bold: http://search.cpan.org/~bingos/Archive-Tar-1.54/lib/Archive/Tar.pm

For quick and dirty stuff system() and `` are fine, for anything I actually need to maintain I will find a module that does what I need (or write one). The one exception of course is ssh, I haven't been able to successfully install any pure-perl version of ssh on any system ever.

Paradox
May 19, 2003

Well, that's easy enough to fix. Thanks. But it's not clear to me why that has to be the case. Any thoughts?

Kidane posted:

If I may be so bold: http://search.cpan.org/~bingos/Archive-Tar-1.54/lib/Archive/Tar.pm

For quick and dirty stuff system() and `` are fine, for anything I actually need to maintain I will find a module that does what I need (or write one). The one exception of course is ssh, I haven't been able to successfully install any pure-perl version of ssh on any system ever.

I've seen this module before. I've never used it but I have looked it over. The problem with it is that I am dealing with many archives on the order of tens of gigabytes. By its own admission it is quite slow and I really don't want to have to spend more time taring and untaring than I have to. As it is this script will already be spending an hour or two in tar alone, per run. Plus, this script will always be running on a machine with tar installed. If that ever changes then I am willing to spend the time to move it over to Archive::Tar.

I'm curious about what problems you've encountered when trying to install Net::ssh::Perl. Usually installing perl modules is quite easy. What were the unique troubles with this one?

Kidane
Dec 15, 2004

DANGER TO MANIFOLD

Paradox posted:

I'm curious about what problems you've encountered when trying to install Net::ssh::Perl. Usually installing perl modules is quite easy. What were the unique troubles with this one?
It's a very complex pure perl implementation of SSH, it requires a ton of nonstandard math and encryption libraries which need to be manually downloaded from some website, yada yada. Apparently there's a debian package for it so that might actually work. Unfortunately when I had cause to use that module I was using a Redhat system and was unable to find a package for it via yum (there may be one now, I haven't dealt with this in over a year).

I ended up using Expect.pm, which worked great, but anything I ever write using Expect feels like a hack.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Dicking around on irc a lil earlier, something interesting was noted...
pre:
17:39 <@Sartak> .pl my %r = (a => 'b'); delete $r{a}; my $as_string = %r; "<$as_string>"
17:39 <+cheesebot> <0>
17:39 <@Sartak> .pl my %r = (a => 'b'); my $as_string = %r; "<$as_string>"
17:39 <+cheesebot> <1/8>
17:40 <@Sartak> oh ok cool
17:40 <@Sartak> so an empty hash in scalar context is probably always 0, good
17:40 <@Sartak> but a non-empty hash in scalar context has hilarious semantics
17:40 <@Sartak> 1/8 is buckets used/allocated

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Fix cheesebot already so I don't have to resort to <>, thanks.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?

Paradox posted:

Well, that's easy enough to fix. Thanks. But it's not clear to me why that has to be the case. Any thoughts?
It's because when you call system(), Perl does the equivalent of:
code:
$SIG{INT} = 'IGNORE';
So if you want your program to also catch those signals, you need to roll your own version of system() that doesn't fiddle with signal handlers.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Are there any initiatives to get Perl5 or Perl6 onto .NET? It seems like there used to be for Perl5, but I think it's dead now.

I use C# at work and I'm a junkie now, I love it. Perl6 looks good in the way Duke Nukem Forever looks good.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
There's been more progress with 6 and with Parrot in the last year or so to the point that the Rakudo people think they can have something generally usable as a beta out by April ('Rakudo Star')

I haven't seen any plans to get it onto .Net though :/

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I've been listening the FLOSS Weekly podcast and I heard about IronPython, Jython, and IronRuby, etc... It made me think, wow, this is almost as bad/crazy as Parrot!

And now I feel like making a chart... Here are all the VMs, .NET, JVM, Parrot, and here are all the languages on top of it... And you can have crazy permutations!

C# on Parrot
IronPerl
JPHP

Although I don't know any sane person that would want to redo the abortion that is PHP. :smug:

SynVisions
Jun 29, 2003

nevermind, got it

SynVisions fucked around with this message at 01:07 on Jan 21, 2010

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it
Quick question about nested data structures: I have a hash that contains a bunch of data in various formats. This one part is a little tricky to wrap my brain around and I want to be sure what I'm doing makes sense. I am generating a 2D array that is not keyed off of integer values, but rather specific floats that each line of the matrix is keyed off of. I just want to be sure that I am accessing each individual scalar correctly. Basically what I have is:

code:
#if for example &example_hash{y_direction_array} = [0.01, 0.03, 0.08, 0.15]
#and &example_hash{x_direction_array} = [10, 20, 40, 70, 90]


for($i = 0; $i <= $#example_hash{y_direction_array}; $i++){
     for($j = 0; $j <= $#example_hash{x_direction_array}; $j++){
          $example_hash{matrix}{$example_hash{y_direction_array}[$i]}[$j] = some_number;
     }
}
Does this make sense? Is there a better way to go about this?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
:psyduck: Just because you can jam everything on to one line doesn't mean you have to.

What's matrix?

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

Triple Tech posted:

:psyduck: Just because you can jam everything on to one line doesn't mean you have to.

What's matrix?

How would you set it up? I'm really not that experienced with perl so I'm not really sure about the best way to show what I'm doing. matrix is my name for the 2D array that I'm trying to set up.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Captain Frigate, could you describe the problem at a bit higher level of abstraction? I'm not quite sure what your goal is and I think we're having an x/y problem here ("I want to do x, y seems like a way to do x, I'll ask about y rather than x")

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
So... you want to set up a 2D array. Super, that's pretty straight forward. And I'm guessing "matrix" is a key. It should really be quoted to make it more clear. Keys for hashes should be quoted since they are strings/scalars.

If you're doing a 2D array, why would you need a hash? If it's a single value hash/dictionary, that doesn't really make sense. Why not start just at the 2D array?

A 2D array in Perl is not unlike the way it's done in other languages. It's literally an array of arrays. Except that Perl does not support typed or first class 2D arrays (where it isn't an array OF arrays but a native, 2-dimensional data structure with two indices).

Erasmus Darwin
Mar 6, 2001

Triple Tech posted:

If you're doing a 2D array, why would you need a hash?

I thought he explained that pretty clearly in his first post. One of the array indices is a float, not an integer.

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it
Well the issue for me is that the array would look like this:

code:
matrix      10        20         40         70         90
0.01      (value)  (value)     (value)    (value)    (value)
0.03      (value)  (value)     (value)    (value)    (value)
0.08      (value)  (value)     (value)    (value)    (value)
0.15      (value)  (value)     (value)    (value)    (value)
So I am trying to make it use hashes so that I can iterate through the column key values (0.01, 0.03, etc) and the row key values (10, 20, 40 etc.) in a loop, using two arrays that I have that are [0.01, 0.03, 0.08, 0.15] and [10, 20, 40, 70, 90]. I'm just not sure how best to organize it.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Well if both values aren't indices starting at zero, it's not really an array, is it? I mean, the storage mechanism could be anything (AoA) but accessing it is a whole different story.

Storing the 10th and 20th values of something results in what, a 20 element array or a 2 element array?

You want a hash of hashes, each key happening to be a number.

code:
$matrix{$x}{$y} = 3.14159
Unless these values are ordered in some significant way and you need easy access to these ordered slices...

Edit: Alternatively, you could have an x_lookup and a y_lookup and a 2D array for storing the values themselves. But that's three data structures instead of one monster one.

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

Triple Tech posted:

Well if both values aren't indices starting at zero, it's not really an array, is it? I mean, the storage mechanism could be anything (AoA) but accessing it is a whole different story.

Storing the 10th and 20th values of something results in what, a 20 element array or a 2 element array?

You want a hash of hashes, each key happening to be a number.

code:
$matrix{$x}{$y} = 3.14159
Unless these values are ordered in some significant way and you need easy access to these ordered slices...

Edit: Alternatively, you could have an x_lookup and a y_lookup and a 2D array for storing the values themselves. But that's three data structures instead of one monster one.

Well, they do have to be in ascending order, so what I have now are the two arrays, which give me the keys which happen to be numbers. I did it like that so I can iterate on them, making sure I get the numbers in the right order. So instead of directly iterating on the hash, I can iterate on the array, and use the value of the array as the key for the hash.

I'm also not sure what you mean by having an x_lookup and a y_lookup.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
If you value iterating over them cell by cell in order, then a 2D array is the way to go. What I meant by the lookups is that the array indices will have no semantic value to you. Hence the lookup table to provide a mapping between semantic index and array index.

code:
     10  20
.34   1   7
.72   2   5

Stored as

@matrix = [ [ 1, 7 ], [ 2, 5 ] ]

%x = { .34 => 0, .72 => 1 }
%y = {  10 => 0,  20 => 1 }

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

Triple Tech posted:

If you value iterating over them cell by cell in order, then a 2D array is the way to go. What I meant by the lookups is that the array indices will have no semantic value to you. Hence the lookup table to provide a mapping between semantic index and array index.

code:
     10  20
.34   1   7
.72   2   5

Stored as

@matrix = [ [ 1, 7 ], [ 2, 5 ] ]

%x = { .34 => 0, .72 => 1 }
%y = {  10 => 0,  20 => 1 }

Ok so what you have here is pretty much the opposite of what I have already as far as array vs hash goes, and I think I understand what you're doing, but how do you make sure to print out %x and %y in order?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I'm assuming you have you x keys and your y keys already in an ordered list (or some sort of source). If not, then you need to keep sorting them if you iterate over the keys in the lookup hash or keep a regular list of values in their significant order.

There are so many ways of tackling this problem and the answer is IT DEPENDS on your use case. Are you building this structure, are you reading it, does it need to be fast, how are you reading it, etc. All of these things matter and I have no idea what you want.

PS - If building and arbitrary reading are all important, consider making or finding a matrix class that provides ordered and random access, implementation be damned.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Captain Frigate posted:

Ok so what you have here is pretty much the opposite of what I have already as far as array vs hash goes, and I think I understand what you're doing, but how do you make sure to print out %x and %y in order?

I'll give you a hint based on how you do it with a one-dimensional hash:
code:
use warnings;
use strict;

my %foo = (0.01 => 'hello', 0.03 => 'how', 0.08 => 'are', 0.18 => 'you', 0.24 => 'doing');

print "$_ -> $foo{$_}\n" for keys %foo;
print "\n\n";
print "$_ -> $foo{$_}\n" for sort {$a <=> $b} keys %foo;
(see output: http://codepad.org/jMQq8eGq )

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it
Well I appreciate the help, and I think I was able to improve some bits of the code with your advice! But I have another smallish question: I am running a number of for-loops iterating through these kinds of constructs and I keep running into a syntax error and I'm not sure what to do with it. The code looks like:

code:
for($i = 0; $i <= $#array_of_hashes_of_arrays; $i++;){
     for($j = 0; $j <= $#array_of_hashes_of_arrays[$i]{some_array}; $j++;){
          print $#array_of_hashes_of_arrays[$i]{some_array}[$j];
     }
}
I gives me a syntax error on the second for-loop but not the first one. Any idea why?

Erasmus Darwin
Mar 6, 2001
You've got an extra semi-colon after $j++.

Edit: Actually, you've got an extra one after $i++, so that isn't the problem. It is unnecessary though. So it's probably the conditional clause that's causing trouble ("$j <= $#array_of_hashes_of_arrays[$i]{some_array}"). Let me do some testing.

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

Erasmus Darwin posted:

You've got an extra semi-colon after $j++.

Edit: Actually, you've got an extra one after $i++, so that isn't the problem. It is unnecessary though. So it's probably the conditional clause that's causing trouble ("$j <= $#array_of_hashes_of_arrays[$i]{some_array}"). Let me do some testing.

Actually the first semicolon was a typo. When I leave out the semicolon on the second one I get an error, and when I put one on the first one I get an error. The way I have it now is:

code:
for($i = 0; $i <= $#array_of_hashes_of_arrays; $i++){
     for($j = 0; $j <= $#array_of_hashes_of_arrays[$i]{some_array}; $j++;){
          print $#array_of_hashes_of_arrays[$i]{some_array}[$j];
     }
}
I get errors that specifically mention the conditional and not any other part of it.

Adbot
ADBOT LOVES YOU

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
You need to stop golfing your stuff so hard. Try it like this.
code:
my @array_of_hashes_of_arrays;

for my $i ( 0 .. $#array_of_hashes_of_arrays ){
    
    my $hash_ref = $array_of_hashes_of_arrays[$i];
    
    my $some_array_ref = $hash_ref->{some_array};
    my $last_index_of_some_array = $#{ $some_array_ref };
    
    for my $j ( 0 .. $last_index_of_some_array ){
        print $some_array_ref->[$j];
    }
}
I am in fact dumb. This is how you do it right:

code:
my @array_of_hashes_of_arrays;

for my $hash_ref ( @array_of_hashes_of_arrays ){
    
    my $some_array_ref = $hash_ref->{some_array};
    
    for my $value ( @{ $some_array_ref } ){
        print $value;
    }
}
Same thing as above, but actually readable.

Mithaldu fucked around with this message at 16:48 on Jan 22, 2010

  • Locked thread