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
Rohaq
Aug 11, 2006
I found a much better way of doing things, no extra modules required: I'll post it when I'm back at work tomorrow :)

Adbot
ADBOT LOVES YOU

Rohaq
Aug 11, 2006
Okay, so my boss suggested redirecting the output to a file, then reading it back in, which seemed a bit sloppy, but I decided to try using the filehandle approach anyway, and used the following:

code:
my $GZCAT;
open my $FH, 'which gzcat 2>&1 |' or die "Failed to open pipe - $!\n";
while(<$FH>) { $GZCAT .= $_; }
close $FH;
chomp($GZCAT);
The output from the command is piped, then read into $GZCAT directly, then chomped to remove any leading linebreaks.

The command is run with STDERR redirected into STDOUT so that errors can be caught in the the while loop if required, and aren't displayed on the screen when the command is run in the script.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
which just iterates through bash's $PATH variable so why not cut out the middle-man and do it yourself?
code:
my ($path) = grep { -f "$_/gzcat" } split /:/, $ENV{PATH}
Also, IO::Uncompress::Gunzip is a core module, so you don't really need to use gzcat either:
code:
use IO::Uncompress::Gunzip qw/gunzip/;

# input and output can be filenames, file handles, scalar refs, array refs, or a glob
gunzip $input, $output;

SA Support Robot
Apr 20, 2007
I think you may want to consider checking $? rather than $!. The latter contains errors from C library calls, which do not necessarily indicate that the shell command you issued exited with an error. Use $? to check for a non-zero exit status and/or signal code from a subprocess.

I usually do something like this...

code:
my $GZCAT;
eval {
    $GZCAT = qx|/usr/bin/which gzcat 2>/dev/null|;
    die "gzcat not available" unless $? == 0;
    chomp $GZCAT;
};
die "fail: $@" if $@;
Also, the problem with dumping STDERR to STDOUT is that you can't reliably discern an error from expected output. That's why I null it above and check $? instead.

Rohaq
Aug 11, 2006

Mario Incandenza posted:

which just iterates through bash's $PATH variable so why not cut out the middle-man and do it yourself?
That's a good idea, thanks.

I needed to capture output from a load of other commands too though; the gunzip one was just one I was showing as an example.

Mario Incandenza posted:

IO::Uncompress::Gunzip is a core module, so you don't really need to use gzcat either:
Ah, I didn't know there was a core module that could handle it. Also very useful, thanks!

Rohaq fucked around with this message at 16:42 on Jul 22, 2010

Rohaq
Aug 11, 2006

 SA Support Robot posted:

I think you may want to consider checking $? rather than $!. The latter contains errors from C library calls, which do not necessarily indicate that the shell command you issued exited with an error. Use $? to check for a non-zero exit status and/or signal code from a subprocess.

I usually do something like this...

Also, the problem with dumping STDERR to STDOUT is that you can't reliably discern an error from expected output. That's why I null it above and check $? instead.
Aaah, also awesome and useful. I'm running the script through a test run right now, but I'll implement some of your suggestions afterwards.

Paradox
May 19, 2003
Anyone around here know much about Log4perl?

I have a batch processing application that processes thousands of jobs. I want have Log4perl handle all the logging aspects of it. However, since there are thousands of jobs going through it, I want to have a separate log file for each job. And, since groups of jobs can be related to each other, I would like to have the log files for related jobs in the same directory.

I was thinking I could accomplish this with categories. When creating the logger I could specify the category as something like 'Jobs.JobType.JobName' and then somewhere (ideally in the config file) go though the work of translating the category into a file path.

After pouring over the documentation I still haven't figured out a good way to accomplish this. At first I thought that I could use a perl hook on the filename parameter of the File Appender, but I can't seem to pass the category name into there.

I suppose one way to make this work is to manually create a new file appender with the correct filename after each call to get_logger. But it seems that there is a better way to do this I and just haven't found it yet.

Any ideas?

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

pmichaud posted:

On behalf of the Rakudo and Perl 6 development teams, I'm happy to announce the July 2010 release of "Rakudo Star", a useful and usable distribution of Perl 6. The tarball for the July 2010 release is available from http://github.com/rakudo/star/downloads.

From here.

Blotto Skorzany fucked around with this message at 20:47 on Jul 29, 2010

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

pmichaud posted:

Rakudo Star releases are created on a monthly cycle or as needed in response to important bug fixes or improvements. The next planned release of Rakudo Star will be on August 24, 2010.

This is the first I've heard of Rakudo Star being a regular thing. I thought it was a one-shot release, hyped up as something usable to encourage people to finally try Perl 6.

Cool, either way, though I wonder how it'll interact with existing monthly releases.

Rohaq
Aug 11, 2006
So I wrote a quick tool for character frequency analysis, but the characters are in unicode; any tips of getting special characters to display properly in STDOUT?

Vanadium
Jan 8, 2005

Tell your terminal to do unicode?

Rohaq
Aug 11, 2006
Welp, I am retarded. I set my terminal to use unicode, but forgot to change the font to something that supported the characters :P

Still some not displaying correctly, but that's not surprising.

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

Rohaq posted:

Welp, I am retarded. I set my terminal to use unicode, but forgot to change the font to something that supported the characters :P

Still some not displaying correctly, but that's not surprising.

Still not as bad as the morass that is getting unicode to display properly through putty -> screen -> irssi :smithicide:

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I recently took up a new job in NYC in one of the city's like... five or so active Perl shops. It's like a vicious cycle! Anyway, I should be back on the Perl grind soon. :) I'm going to miss Visual Studio...

Fenderbender
Oct 10, 2003

You have the right to remain silent.

Triple Tech posted:

I recently took up a new job in NYC in one of the city's like... five or so active Perl shops. It's like a vicious cycle! Anyway, I should be back on the Perl grind soon. :) I'm going to miss Visual Studio...

Probably took my last job. ;X

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Fenderbender posted:

Probably took my last job. ;X

Where did you work and where do you work now?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Triple Tech posted:

Perl ... miss Visual Studio
You can have both with Komodo IDE. :)

TiMBuS
Sep 25, 2007

LOL WUT?

Filburt Shellbach posted:

This is the first I've heard of Rakudo Star being a regular thing. I thought it was a one-shot release, hyped up as something usable to encourage people to finally try Perl 6.

Cool, either way, though I wonder how it'll interact with existing monthly releases.

Star will eventually peter out to something like quarterly or half yearly releases as it gets more stable and usable, apparently. Monthlies will still be monthlies.
I'll just continue to `git pull` regardless

SA Support Robot
Apr 20, 2007

TiMBuS posted:

Star will eventually peter out to something like quarterly or half yearly releases as it gets more stable and usable, apparently. Monthlies will still be monthlies.
I'll just continue to `git pull` regardless

Just curious, what is everyone's opinion here of the Perl6 situation? Anyone have any real expectations to move major applications to it?

I wrote off Perl6 long ago. I believe it was an enormous mistake to basically set Perl adrift to chase down the whole Parrot project. I won't even consider using Perl6 until there are stable packages in enterprise Linux distros, and even then I'll hold off until I see reputable reports of its stability/performance in business-critical production scenarios.

While many interpreted languages were evolving and embraced the rise of web applications, Perl's developers veered off into the weeds. They all but destroyed Perl as a product. It will take a lot to win me over again.

Fenderbender
Oct 10, 2003

You have the right to remain silent.
I think Perl6 itself won't be making any converts in business, but once a web framework project gets to a stable level and a few evangelists and success stories get out there, there will probably be a slow shift to it.

magimix
Dec 31, 2003

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

Nap Ghost

SA Support Robot posted:

Just curious, what is everyone's opinion here of the Perl6 situation? Anyone have any real expectations to move major applications to it?

I wrote off Perl6 long ago. I believe it was an enormous mistake to basically set Perl adrift to chase down the whole Parrot project. I won't even consider using Perl6 until there are stable packages in enterprise Linux distros, and even then I'll hold off until I see reputable reports of its stability/performance in business-critical production scenarios.

While many interpreted languages were evolving and embraced the rise of web applications, Perl's developers veered off into the weeds. They all but destroyed Perl as a product. It will take a lot to win me over again.

I'm kind of with you on this one. While Perl6 has been slowly (slowly) gestating, everything else has moved forward relentlessly, usually in an iterative, steadily-improving manner.

Much of what we might want from it is now served to us from competing technologies that we've elected to make use of in the meantime. We still actively use Perl5 (and will for the foreseeable future), and develop new systems with it, but we'd absolutely not go to Perl6 (in my opinion, though I'm not the person that'd be making that sort of decision) 'just because'.

Any changes we make to our infrastructure go through as much analysis, review, and testing as developmental changes, and with a massive legacy codebase we'd probably be hard pushed to justify shunting to Perl6 runtime.

And for new-build? Well where Perl in general fits, Perl5 already fits, and for other cases, we already have an established use of alternate technologies (with their own extant codebases, system of support, processes, etc, etc).

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
I think 6 will be pretty popular eventually, but I don't think it will be pulling the majority of its users from the current Perl userbase, much of which has moved on to Ruby or become skeptical of 6 and decided to reinvigorate Perl 5 instead (cf. backported 6 features in 5.10 and 5.12, the move to a faster and regular release schedule instead of the insane time gap between 5.8 and 5.10, myriad cultural shifts, the rise of Moose (itself a mixture of cultural elements and poo poo robbed from 6, CLOS and everything else that wasn't nailed down), etc). In retrospect I think a cleanup and regularization of Perl 5 would have been a great Perl 6 in 2003 or 2004, with the current supercalifragilisticexpialidocious spec being a great Perl 7 or 8.

Blotto Skorzany fucked around with this message at 20:05 on Aug 2, 2010

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

SA Support Robot posted:

Just curious, what is everyone's opinion here of the Perl6 situation? Anyone have any real expectations to move major applications to it?

I wrote off Perl6 long ago. I believe it was an enormous mistake to basically set Perl adrift to chase down the whole Parrot project. I won't even consider using Perl6 until there are stable packages in enterprise Linux distros, and even then I'll hold off until I see reputable reports of its stability/performance in business-critical production scenarios.

While many interpreted languages were evolving and embraced the rise of web applications, Perl's developers veered off into the weeds. They all but destroyed Perl as a product. It will take a lot to win me over again.

If you haven't yet, I suggest you try reading this, starting at introduction and working your way down the links on the left: http://perlgeek.de/blog-en/perl-5-to-6/00-intro.writeback

I am still sceptical about Perl6 myself, and even some of the changes (since it's getting a LOT more line-noisy), but with what it offers, i also find myself wanting a ton of that poo poo in Perl5. As such, i think that Perl6 has a good chance to be a hella popular language in 20 years.

What i find myself wondering though is whether there's an actual chance that this timeframe might be shortened by making a decisive push to port the large parts that make Perl5 useful (CPAN, DBI, just to mention two).

Doug
Feb 27, 2006

This station is
non-operational.
I'm working through trying to teach myself perl because it seems without it I have absolutely no hope of ever getting a position in *nix administration. Anyway, I've got a tutorial/book I've been following and I'm working on an exercise where it asks me to make a program to take a number less than 256 and convert it to binary. The hint it gives suggests using the bitwise AND 8 times.

What I have so far is:
code:
print "$dec in binary is: ", $dec&1, $dec&2, $dec&4, "\n";
I haven't fleshed it all the way out but that is enough to test. It seems like it's doing what I want, but instead of reporting a 1 it reports the number I'm comparing against. So if I wanted to convert 5 to binary it would spit back 104 instead of 101. What am I missing here?

Vanadium
Jan 8, 2005

4 & 4 is still 4, it is not a boolean operation, it is a bitwise operation! You probably want to do something like !!($dec & 4) or maybe ($dec >> 2) & 1, I am not sure how/if exactly those work.

Doug
Feb 27, 2006

This station is
non-operational.

Vanadium posted:

4 & 4 is still 4, it is not a boolean operation, it is a bitwise operation! You probably want to do something like !!($dec & 4) or maybe ($dec >> 2) & 1, I am not sure how/if exactly those work.

Well, I managed to figure it out in the ugliest way possible. I'm now doing ($dec&4)/4 which gives me the correct answer but I feel like there's got to be a better way.

edit: The tutorial mentioned >> but I can't imagine that would be the solution because it wasn't fulled explained. In the first one are you basically saying (not)(not)($dec&4) or is !! somehow different?

Doug fucked around with this message at 23:49 on Aug 2, 2010

Vanadium
Jan 8, 2005

Yeah, not not.

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

Doug posted:

Well, I managed to figure it out in the ugliest way possible. I'm now doing ($dec&4)/4 which gives me the correct answer but I feel like there's got to be a better way.

edit: The tutorial mentioned >> but I can't imagine that would be the solution because it wasn't fulled explained. In the first one are you basically saying (not)(not)($dec&4) or is !! somehow different?

This is more a bitwise arithmetic question than a perl question; iirc this is an exercise that dates all the way back to K&R's The C Programming Language, so googling for answers should be pretty fruitful if you need to (C has the same bitwise operators as Perl, indeed it's where Perl got them from).

SA Support Robot
Apr 20, 2007

Otto Skorzeny posted:

This is more a bitwise arithmetic question than a perl question; iirc this is an exercise that dates all the way back to K&R's The C Programming Language, so googling for answers should be pretty fruitful if you need to (C has the same bitwise operators as Perl, indeed it's where Perl got them from).

This. Also you might want to build the string in a loop.

And here are a few examples of how you might get your "1" or "0":

$s .= (1 == 2) ? "1" : "0";
$s .= sprintf("%u", (1 != 3));
$s .= 0 + (1 == 5);


These statements make good Perl exercises on their own, since they will make you think about how Perl scalars behave in various contexts.

Erasmus Darwin
Mar 6, 2001
If you want to get fancy, you can also use pack and unpack.

print unpack('B*', pack('C', $dec)), "\n";

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I'm not exactly sure what features Perl6 even has, but it's poised in my head as "The Jesus Language". Whatever killer feature other languages have, Perl6 needs to have. Or, if Perl6 already has it, people just need to be educated about it. The only killer things I can think of are...

* Low barrier parallelization (threads, cores, etc)
* ORM
* Client-side collection querying (like LINQ)
* Web MVC framework (yawn)

Once those spaces have matured (for any language, really), I'm not really sure what's left to do.

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
One of the big Perl 6 features people have been talking about recently is Rules, composable elements by which one can make a legitimate parser for a grammar about as easily as one can halfass it with a regex in Perl 5. Taking off my skeptic's hat for a moment, there really are a million cool things that you can :google: around for if you have a free hour or so.

SA Support Robot
Apr 20, 2007

Triple Tech posted:

* ORM
* Client-side collection querying (like LINQ)
* Web MVC framework (yawn)

These all should be completely separate from Perl. If Perl6 ever included such things or even advocated them as best practice, that would be the point for me where Perl became too pushy. It's already bad enough that Perl6 looks like Damion Conway ejaculated all over it.

slipped
Jul 12, 2001

SA Support Robot posted:

It's already bad enough that Perl6 looks like Damion Conway ejaculated all over it.
That's a bad thing?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
I conflated Perl6 core with its ecosystem. I agree ORM and MVC needn't be core, but client-side querying and parallelization would get a huge boost if they were much closer to the native constructs of the language. Otherwise it'd be another Moose-type project and who needs that. Just make it core.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

SA Support Robot posted:

Just curious, what is everyone's opinion here of the Perl6 situation? Anyone have any real expectations to move major applications to it?

I wrote off Perl6 long ago. I believe it was an enormous mistake to basically set Perl adrift to chase down the whole Parrot project. I won't even consider using Perl6 until there are stable packages in enterprise Linux distros, and even then I'll hold off until I see reputable reports of its stability/performance in business-critical production scenarios.

While many interpreted languages were evolving and embraced the rise of web applications, Perl's developers veered off into the weeds. They all but destroyed Perl as a product. It will take a lot to win me over again.
When I first saw the Perl 6 apocalypses years ago I thought Perl 6 would be the great new thing. I don't know what exactly I was looking at but the language looked so much better. My first experiences with the pre-releases was that it had the same crud going on. I think what I'm looking for now is something like Python with curly braces, smart boxing/unboxing, and the ability to explicitly type things.

Parrot could also be a drat cool thing but the support from other languages isn't quite there. The way I saw it was that it was a CLR like .NET, where Perl 6 would be the C# that pushes it along. Fine and dandy, except that took waaay too long. They were prototyping Perl 6 using Haskell because Parrot couldn't keep up.

My fantasy with Parrot that didn't pan out was that I could link it in to a program written in, say, C++, and incorporate Parrot as it's scripting engine. Then people could use in whatever scripting language they felt like, so long as it compiled to Parrot's byte code. Except that the compilers for the more interesting languages aren't there.

That being said, everybody's got their own little VM prototype thingie for Parrot. I guess it's a fun project for people that like to toy with VMs and creating their own toy languages. More power to them--maybe I'll make one called "Python with curly braces and data types."



I am trying to love array references but it's an abusive relationship. I try to pass arrays in as an argument to some subroutines for processing, and it's one argument of many, so I send it in as a reference. My rule of thumb has been to shift it into a temporary variable like "$directories_ref" then cast to "@directories" using @{ $directories_ref } so that I can then treat it like something sane. Is there something notationally clean that avoids those steps?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Rocko Bonaparte posted:

They were prototyping Perl 6 using Haskell because Parrot couldn't keep up.
From reading stuff about that part of Perl 6 history that is not what happened. It was more that a certain hacker just picked it up *because* and managed to generate a shitton of momentum because of her own personality and work style. Then when she went away it collapsed, proving further that Haskell was irrelevant and it was about her.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
You can consume it directly or use more concise notation.

code:
say for @$things;

my @real_things = @$things;

say $things->[1];

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

Mithaldu posted:

From reading stuff about that part of Perl 6 history that is not what happened. It was more that a certain hacker just picked it up *because* and managed to generate a shitton of momentum because of her own personality and work style. Then when she went away it collapsed, proving further that Haskell was irrelevant and it was about her.

That's not quite how Pugs went down, but yeah it was developed at breakneck speed because audreyt is basically a human tornado, and when she got ill for a while none of the other lambdacamels were able to pick it up since they lacked the whirlwind nature. Haskell was a pretty awesome choice for implementation language though.

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Mithaldu posted:

From reading stuff about that part of Perl 6 history that is not what happened. It was more that a certain hacker just picked it up *because* and managed to generate a shitton of momentum because of her own personality and work style. Then when she went away it collapsed, proving further that Haskell was irrelevant and it was about her.
It doesn't necessarily change what I was trying to say. I know that Pugs was a superhuman effort but Parrot wasn't very complete at the time either. Pugs did allow them to screw around with parts of the language though.

  • Locked thread