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
German Joey
Dec 18, 2004

Sartak posted:

It'll be my first YAPC, so I can't say for sure. But I am very excited about it. There are so many talks I want to see and people I want to meet. You should definitely come by. It's only $100. I think you'll get your money's worth.

i noticed that they still have a few Perl6 sessions in the program. i mean, for christs sake, who the gently caress still cares about it? its been 8 years now!

Adbot
ADBOT LOVES YOU

TiMBuS
Sep 25, 2007

LOL WUT?

YAPC looks freaking amazing I wish I could attend it.

German Joey posted:

i noticed that they still have a few Perl6 sessions in the program. i mean, for christs sake, who the gently caress still cares about it? its been 8 years now!

:(
One day it'll be out.

Actually, it seems perl 6 is really picking up these days. They've gotten a nice donation that should help get things done faster, and apparently theres more people interested in sinking some money into it.
I'm also considering helping develop perl6 (if I even can), I'm just having trouble wrapping my head around it. I guess that happens when you try to join a gigantic half-finished project.

Zombywuf
Mar 29, 2008

TiMBuS posted:

One day it'll be out.

/me lights a candle at his alter of Larry and chants the sacred runes

$@%*
$@&*
$@%*
...

ashgromnies
Jun 19, 2004

German Joey posted:

i noticed that they still have a few Perl6 sessions in the program. i mean, for christs sake, who the gently caress still cares about it? its been 8 years now!

One of my coworkers was on the original Topaz Perl 6 project and said that development changed a lot since then - they were making good progress and had a team that fit well together, but other influences changed things and I guess they scrapped a lot of work.

I unfortunately don't know any specifics.

Cheesus
Oct 17, 2002

Let us retract the foreskin of ignorance and apply the wirebrush of enlightenment.
Yam Slacker
I'm using perl 5.8.8 and want to pull data from the capture buffer using variable variables. Like this:
code:
my %pos_fields{
  onefield=>1,
  twofield=>2,
  threefield=>3,
  fourfield=>4
};

my $variable = "What the hell, son?";
$variable =~ m/([^\s+]+)\s+([^\s+]+)\s+([^\s+]+)\s+([^\s+]+)/;
my $find = ${$pos_fields{fourfield}};
The problem is that when I do this, I get the following Perl error:
code:
Can't use string ("4") as a SCALAR ref while "strict refs" in use at...
I've verified that if you force a number it works as expected. The following returns the same:
code:
my $find = $4;
my $find = ${4};
But not with a non-numeric value. I've spent the afternoon trying various solutions (trying to force the value to be scalar, adding 0, etc), the best solution I can come up with is to turn off strict references and re-enabling around the code block but it seems like a retarded solution.

Am I missing something fundamental?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Cheesus posted:

Am I missing something fundamental?

If you can find a way to do what you're trying to do without turning off strict refs for that block, then it's a bug and you should file a report. This is exactly what strict refs is supposed to prevent.

You are aware that if you do @foo = $bar =~ m/(abc)def(ghi)/ then you get @foo = ('abc', 'ghi'), right? That would let you do this with array indexes instead of soft references.

Cheesus
Oct 17, 2002

Let us retract the foreskin of ignorance and apply the wirebrush of enlightenment.
Yam Slacker
Jesus, that's just what I wanted. Thanks.

Even looking at the perlre page again I can't see where they say this works.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Look for something like the regexp operator that starts with an m returns the captured matches in list context.

Also, what is it that you're trying to do? Your regexp smells funny.

http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators

"If the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern"

Triple Tech fucked around with this message at 02:54 on Jun 4, 2008

TiMBuS
Sep 25, 2007

LOL WUT?

ashgromnies posted:

One of my coworkers was on the original Topaz Perl 6 project and said that development changed a lot since then - they were making good progress and had a team that fit well together, but other influences changed things and I guess they scrapped a lot of work.

I unfortunately don't know any specifics.

Topaz perl was around before Larry began the perl 6 spec, so it didn't have much going for it.

German Joey
Dec 18, 2004

ashgromnies posted:

One of my coworkers was on the original Topaz Perl 6 project and said that development changed a lot since then - they were making good progress and had a team that fit well together, but other influences changed things and I guess they scrapped a lot of work.

I unfortunately don't know any specifics.

oh man, topaz, i remember that. that was chip salzenburg's thing, wasn't it? last i heard he was locked up in jail or somesuch. i guess the bigshots in perl community have never had much luck with the law.

if i remember right, topaz was just a rewrite of the perl 5 core in C++. the motivation was that new language features were too hard to implement due to the immense complexity of the perl 5 core. i just looked it up and that was NINE years ago. yeesh! i was just talking about the rewrite done with parrot. topaz was scrapped for parrot because larry and the community wanted a language rewrite in addition to an implementation rewrite. i remember working quite a bit on the first implementation of perl 6 on parrot for a few years - the one written in perl 5 that started after a half a dozen apocalypses or so had come out. it, unfortunately, collapsed due to its immense weight and the lack of developers holding it together. oh well.

i also remember this book: Perl 6 and Parrot Essentials. i tech-reviewed both editions. i remember being so excited when it first came out! i thought that the book would drum up enough excitement and momentum in the community to finish the project within two years!

the second edition came out four years ago. :(

Ninja Rope
Oct 22, 2005

Wee.

ShoulderDaemon posted:

You are aware that if you do @foo = $bar =~ m/(abc)def(ghi)/ then you get @foo = ('abc', 'ghi'), right? That would let you do this with array indexes instead of soft references.

This is a good solution. You could define constants and access your resulting array with them similar to how POE works (eg, $blah=$matched[MATCHED_NAME]). You can also do ( $match1, $match2 ) = $bar =~ m/(abc)def(ghi)/ to directly set the variables (just like anything else that returns an array), or even ( $hash{blah}, $hash{blah2} ) = $bar =~ m/(abc)def(ghi)/ if you really want to use a hash.

Div
May 27, 2001

I have a question about mod_perl persistence.

I'm working with some (horrible but readable) legacy code and at the core we have this main module that handles database connection and templating, etc.

So we have this "core.pm" and inside there is a subroutine called "get_logo_data" which checks the (shared) file server for the existence of a logo and if so, returns the filename. The way this has been made effecient is to have this a variable the top of the Core package:

our %logo_data;

and then inside the subroutine to fetch logo data store the result of the request into %logo_data. The idea being that for the duration of the process this variable will act as a cache between page requests. The senior guy here just ran me through a simple test to show that it definitely remembers the contents of the variable through multiple page requests and explained on our high traffic environment this could be saving anything from 10 to 20% of file server hits.

The idea of this "our" variable having that kind of benefit seems retarded to me. Not only that, I'm trying to move this code in a more OOP direction, and I need to at least try and replicate this idea of cache. I'm not allowed to modify the publishing system to just set a database value of "has_logo" or anything sensible like that so for now I need to deal with hitting the file server and trying to cache this somehow.

I hope I explained that right, because frankly the entire thing just seems retarded to me. Can anyone who's had to deal with this in the past point me in the direction of a better way to cache those file server hits?

Erasmus Darwin
Mar 6, 2001

Div posted:

I hope I explained that right, because frankly the entire thing just seems retarded to me. Can anyone who's had to deal with this in the past point me in the direction of a better way to cache those file server hits?

While it's not the greatest, I'm not sure what your problem is with the scheme beyond it being "retarded". Are you having problems with logo updates not propagating quickly enough since cache persistence is arbitrarily tied to the life of the mod_perl process? Is there so much logo data being cached that it's causing problems with the size of the mod_perl and/or the system memory?

Edit: One more proper way would be to use Memoize to memoize the logo look-up function. However, at its core, Memoize would be doing the same thing that your code already does with just a lot of extra packaging and unnecessary flexibility.

Erasmus Darwin fucked around with this message at 16:16 on Jun 6, 2008

KillerTwinkie
Sep 11, 2003
I swear it wasn't me...

TiMBuS posted:

YAPC looks freaking amazing I wish I could attend it.


:(
One day it'll be out.

Actually, it seems perl 6 is really picking up these days. They've gotten a nice donation that should help get things done faster, and apparently theres more people interested in sinking some money into it.
I'm also considering helping develop perl6 (if I even can), I'm just having trouble wrapping my head around it. I guess that happens when you try to join a gigantic half-finished project.

Slight derail.

The one thing I'm looking forward to the most is the complete revamp of the Regular Expression syntax, which is radically different in a lot of ways than the current Perl 5 Regular Expression syntax: http://dev.perl.org/perl6/doc/design/apo/A05.html. For example, '(...)' still denotes a capturing group, however, '[...]' is for non-capturing instead of the ungainly '(?:...)'. This change means that character classes are a completely different beast altogether. :)

German Joey
Dec 18, 2004

KillerTwinkie posted:

Slight derail.

The one thing I'm looking forward to the most is the complete revamp of the Regular Expression syntax, which is radically different in a lot of ways than the current Perl 5 Regular Expression syntax: http://dev.perl.org/perl6/doc/design/apo/A05.html. For example, '(...)' still denotes a capturing group, however, '[...]' is for non-capturing instead of the ungainly '(?:...)'. This change means that character classes are a completely different beast altogether. :)

the new regular expressions were definitely one of my favorite planned features of Perl 6 too. but minor syntactical changes aren't even the half of it! the best feature by far were "rules", which allow the programmer to build up complicated expressions in an object oriented way (inspired by Parse::RecDescent of course).

i wrote up an article about em a few weeks after Apocalypse 5 came out (i.e. 6 years ago, LOL) that compares perl5 to perl6 in an example of parsing javascript code, if you're interested in learning more. http://www.perlmonks.org/?node_id=179555

NotShadowStar
Sep 20, 2000
So I inherited this Perl program where the designer has done everything possible wrong, including obscure syntax rules and complicated global data structures that all sub-functions modify directly. I'm rewriting it to make things sane for me, but I can't decipher some of it. For instance, can someone help me unwind these kinds of variables into english or less code noise?

${$$g_mapTransform{$frame}}[0]
${$$xaPlate[$iRow][$iCol]}{'gt'}

Also, what.
return (@g_errors == 0);

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

NotShadowStar posted:

So I inherited this Perl program where the designer has done everything possible wrong, including obscure syntax rules and complicated global data structures that all sub-functions modify directly. I'm rewriting it to make things sane for me, but I can't decipher some of it. For instance, can someone help me unwind these kinds of variables into english or less code noise?

${$$g_mapTransform{$frame}}[0]
${$$xaPlate[$iRow][$iCol]}{'gt'}

Also, what.
return (@g_errors == 0);

perl -MO=Deparse let's you input a phrase (or use a script as an argument) and it will give you back a rough (not 100% perfect) mechanical equivalent to what you typed out, with more parenthesis and what not, making the underlying intentions more clear. The first part I'm not sure of but the second part is "return true if the number of errors (given by the length of the stack) is zero" or "return good if no errors".

NotShadowStar
Sep 20, 2000
Interesting idea but

code:
perl -MO=Deparse
${$$g_mapTransform{$frame}}[0]
${$$g_mapTransform{$frame};}[0];
- syntax OK
:(

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

NotShadowStar posted:

${$$g_mapTransform{$frame}}[0]
${$$xaPlate[$iRow][$iCol]}{'gt'}

$$g_mapTransform{$frame} is an array ref.
$g_mapTransform is a hash ref.

$$xaPlate[$iRow][$iCol] is a hash ref.
$xaPlate[$iRow] is an array ref.
$xaPlate is an array ref (an abstracted two dimensional array).

You can also use print Data::Dumper $structure.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
You basically have to look at this like an onion. The first sigils have braces and a lookup, which is nice, so you know that first structure, so you can drop them. The next outer sigil is attached to the next outer lookup. It helps if you put braces between that sigil and the lookup. So...

$$apple[lookup] becomes ${$apple}[lookup] where the first sigil denotes context, the middle part denotes complex scalar name, and the last part is the lookup paired with the first sigil.

So from this, we can infer that $apple is being treated like an index lookup of an array which is written in scalar context. So, removing the context sigil and the lookup, the natural state of the variable is @$apple making it an array ref.

Blah.

Ninja Rope
Oct 22, 2005

Wee.

NotShadowStar posted:

So I inherited this Perl program where the designer has done everything possible wrong, including obscure syntax rules and complicated global data structures that all sub-functions modify directly. I'm rewriting it to make things sane for me, but I can't decipher some of it. For instance, can someone help me unwind these kinds of variables into english or less code noise?

${$$g_mapTransform{$frame}}[0]
${$$xaPlate[$iRow][$iCol]}{'gt'}

Also, what.
return (@g_errors == 0);

As for how to rewrite those to be more "clear", I would rewrite this: "${$$g_mapTransform{$frame}}[0]" as this: "$g_mapTransform->{$frame}->[0]" and "${$$xaPlate[$iRow][$iCol]}{'gt'}" as "$xaPlate->[$iRow]->[$iCol]->{'gt'}".

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
After the first deref, you don't need subsequent derefers.

$a->{lookup}->[lookup] == $a->{lookup}[lookup]

fansipans
Nov 20, 2005

Internets. Serious Business.

Triple Tech posted:

You can also use print Data::Dumper $structure.

Triple Tech nailed it on the head: Data::Dumper is your super number 1 friend:

code:
use Data::[b][/b]Dumper;

# blah blah blah code
# deep in the bowels of your lovely app:

print Dumper($g_mapTransform);

NotShadowStar
Sep 20, 2000
Thanks for the advice, but the app is old-school CGI based, another circle of hell. Since the thing is so incredibly monolithic, I did hack in some debugging and logging support to files when changing minor things, but the whole app is references to references to references to GLOBAL data structures called upon by different subroutines at different times, depending on the CGI entry point. I know what goes in and what's supposed to come out so I don't really care about how it's doing most of it, I'm redoing it all in my own way, but there are a few instances where I need to see how some variables are referenced or where they may possibly be coming from so I can figure out the math behind it.

Ninja Rope
Oct 22, 2005

Wee.

Triple Tech posted:

After the first deref, you don't need subsequent derefers.

$a->{lookup}->[lookup] == $a->{lookup}[lookup]

Sure, they might not be necessary, but I like keeping them, stylistically. I try to keep everything consistent, so if I use -> for dereferencing in one place I should use it everywhere in a particular file or project. Also, I remember old versions of ActivePerl didn't like hash references more than two or three levels deep, unless you used arrows, so that's how I got in the habit. Still, you're right, it's just a matter of preference.

magimix
Dec 31, 2003

MY FAT WAIFU!!! :love:
She's fetish efficient :3:

Nap Ghost

Triple Tech posted:

After the first deref, you don't need subsequent derefers.

$a->{lookup}->[lookup] == $a->{lookup}[lookup]

That's just a syntactic nicety. Same with how you usually don't need to include the quotes around a literal hash-key (e.g. $test->{'key'} vs $test->{key}). However, I've always preferred to keep dereferences 'explicit' by using '->'. I like the arrows :3:

Edit: How the gently caress did I not spot I'd been 100%, thoroughly beaten?! Ninja Rope :argh:

German Joey
Dec 18, 2004

magimix posted:

That's just a syntactic nicety. Same with how you usually don't need to include the quotes around a literal hash-key (e.g. $test->{'key'} vs $test->{key}). However, I've always preferred to keep dereferences 'explicit' by using '->'. I like the arrows :3:

Edit: How the gently caress did I not spot I'd been 100%, thoroughly beaten?! Ninja Rope :argh:

syntactic niceties go a long way to keep your code from looking like line noise, especially when you're working with a structure thats more than a few levels deep.

magimix
Dec 31, 2003

MY FAT WAIFU!!! :love:
She's fetish efficient :3:

Nap Ghost

German Joey posted:

syntactic niceties go a long way to keep your code from looking like line noise, especially when you're working with a structure thats more than a few levels deep.

Sounds like we've got a new doctrinal conflict on our hands! I was getting bored of tabs-vs-spaces, braces-on-same-line-vs-on-new-line, and suchlike anyway.

:can: :neckbeard:

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I think I grossly misunderstood one of MJD's slides where he said "less punctuation". I've been a diehard fan of that mantra ever since, you know, I misunderstood it. =) Where possible, at the sacrifice of possibly performance but never clarity (does the reader know all of the operator precedence without looking?), nearly all my code aims for less punctuation.

Put succinctly, as previously mentioned, less punctuationi helps fight against that "line noise" stigma that Perl has. I'm thoroughly happy at how my new code has turned out with this mantra.

6174
Dec 4, 2004
I'm having a problem with Perl. I've got a script using Archive::Zip. RedHat Issued a patch today for RHEL 4 (yes it is old, but it is what I've got to work with). http://rhn.redhat.com/errata/RHSA-2008-0522.html

After the upgrade a script that worked now fails.

code:
$ ../prepare_sondes_mssftp.pl source/ dest
 is only avaliable with the XS version at /usr/lib/perl5/site_perl/5.8.5/Compress/Zlib.pm line 9
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/Compress/Zlib.pm line 9.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.5/Archive/Zip.pm line 11.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/Archive/Zip.pm line 11.
Compilation failed in require at ../prepare_sondes_mssftp.pl line 6.
BEGIN failed--compilation aborted at ../prepare_sondes_mssftp.pl line 6.
$ head ../prepare_sondes_mssftp.pl
#!/usr/bin/perl

use strict;
use warnings;

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use File::Spec;

sub process_dir
{
$ 
Line 6 is "use Archive....". When I googled around, the only help I got was some people saying that Scalar::Util is somehow screwed up and the answer is to reinstall the module in CPAN.

So within CPAN I first upgraded CPAN, then did "test Archive::Zip" and all the related packages I could find (Scalar::Util, IO::Compress::Base, Compress::Raw::Zlib). CPAN now says all the things tested successfully, but the script is still not working. Anyone got any ideas on what to try/look for?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
How about a straight up use? perl -MArchive::Zip -e 1

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

6174 posted:

Scalar::Util is somehow screwed up and the answer is to reinstall the module in CPAN

I'll expand on this, because it's a lovely problem that's worth knowing about.

Some vendors (notably, RedHat, though maybe they've since fixed this) ship a broken Scalar::Util. In particular, weaken just does not work. This sucks because weaken is absolutely necessary for working with circular data structures.

Module authors: depend on Task::Weaken. It will test weaken support explicitly and do whatever it can to help the situation, including letting the user that his Scalar::Util is broken.

Thankfully it's not as big a deal nowadays as Scalar::Util is in the core distribution as of 5.8.

Filburt Shellbach fucked around with this message at 01:22 on Jun 12, 2008

6174
Dec 4, 2004

Triple Tech posted:

How about a straight up use? perl -MArchive::Zip -e 1

code:
$ perl -MArchive::Zip -e 1
 is only avaliable with the XS version at /usr/lib/perl5/site_perl/5.8.5/Compress/Zlib.pm line 9
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/Compress/Zlib.pm line 9.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.5/Archive/Zip.pm line 11.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/Archive/Zip.pm line 11.
Compilation failed in require.
BEGIN failed--compilation aborted.
$ 

Sartak posted:

More reasons why I'm frustrated with RHEL

I do have 5.8.5 on the box. Is the answer then to not let RedHat manage Perl? (ie remove the rpm and grab Perl and do a standard make; make install; )

Cheesus
Oct 17, 2002

Let us retract the foreskin of ignorance and apply the wirebrush of enlightenment.
Yam Slacker
I'm working on a project to break logfile data into various archival formats. My co-worker is convinced that regular expressions are too slow and is convinced there's a way to break such entries down using a BNF-like syntax into either an array or hash. Without using regular expressions.

Is there such a CPAN module to do this? I've tried searching for "BNF" and also things like Yacc/Lex but I'm pretty ignorant about how those actually work. The few modules I've come across talk about generating C++ code which isn't what I want.

Or is there something else I should be looking for?

Ninja Rope
Oct 22, 2005

Wee.
Look at Parse::RecDescent on CPAN.

6174
Dec 4, 2004

6174 posted:

I do have 5.8.5 on the box. Is the answer then to not let RedHat manage Perl? (ie remove the rpm and grab Perl and do a standard make; make install; )

I just finished manually compiling and installing 5.8.8 and everything works again. Stupid RedHat.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Cheesus posted:

My co-worker is convinced that regular expressions are too slow

Are they really? Are you sure you aren't wasting development time by looking this up? Are regexps really the bottleneck in your process?

If you've said Yes to any of these questions, call now! by all means, go ahead. I just worry maybe it's worrying prematurely.

Also, if the data is fixed width, consider unpack?

Diocenes
Jul 18, 2003
Bad Drummer

6174 posted:

I just finished manually compiling and installing 5.8.8 and everything works again. Stupid RedHat.

This... on a production server that SOMEHOW had up2date running with Perl not excluded. :smith:

Plus ~20 minutes of frantic perl -cw / CPAN sessions.

Cheesus
Oct 17, 2002

Let us retract the foreskin of ignorance and apply the wirebrush of enlightenment.
Yam Slacker

Triple Tech posted:

Are they really? Are you sure you aren't wasting development time by looking this up? Are regexps really the bottleneck in your process?
I don't share his sentiment.

In fact, I'm suspicious and will be evalating the performance against some of these modules. The module that Ninja Rope mentions itself mentions performance concerns in the reviews (however one of them mentioned modifying another package to act nearly the same and possibly with better performance).

Adbot
ADBOT LOVES YOU

German Joey
Dec 18, 2004

Cheesus posted:

I don't share his sentiment.

In fact, I'm suspicious and will be evalating the performance against some of these modules. The module that Ninja Rope mentions itself mentions performance concerns in the reviews (however one of them mentioned modifying another package to act nearly the same and possibly with better performance).

i've used Parse::RecDescent for a few projects in the past and it certainly is true that it is has significant performance drawbacks. as a good example: the grammar we used for the perl6 prototype involved a 1000-line BNF grammar that needed plenty of embedded code. when using it to compile a program there was a 30 second startup delay penalty during which Parse::RecDescent converted the BNF into an executable format (that internally used regexes to tokenize the input). that was reasonable for us since our prototype was not aimed at performance but at greatly simplifying the process of parsing a phenomally complex input files. for simple files, such as a logfile, you should be fine using more ordinary methods. BNF parsing will be, in general, much slower than a regular expression (which will be in turn much slower than unpack). the more complicated a parsing method can handle, the slower it'll be.

the main question i have for your coworker then is: why do you need something more powerful than a regex for parsing a loving log file? and why do you need something more efficient? how big is this file, in the gigabytes?

  • Locked thread