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
Beardless Woman
May 5, 2004

M for Mysterious

Voltaire posted:

I already got the job buddy! :rock:

These are just practice exercises i'm going through

I haven't tested this but it should work and looks more like perl.

code:
#!/usr/bin/perl

use strict;
use warnings;

my @numbers;

print "Please enter a number, -1 to end: ";

while (<STDIN>) {
    chomp;
    last if ($_ == -1);
    push @numbers, $_;
}

unless (scalar @numbers) {
    print "Hope you get fired!\n";
    exit;
}

print "Here are the numbers you entered: " . join(", ", @numbers) . "\n";

@numbers = sort @numbers;

print "Ascending: " . join(", ", @numbers) . "\n";
print "Descending: " . join(", ", reverse @numbers) . "\n";
print "Smallest and Largest: " . $numbers[0] . ", " . $numbers[-1] . "\n";
Stupid [ code ] is putting spaces where there aren't any.

Beardless Woman fucked around with this message at 06:36 on Nov 26, 2008

Adbot
ADBOT LOVES YOU

Beardless Woman
May 5, 2004

M for Mysterious
Having silly issues with map and can't seem to get it to work the way I want. I'm sure there's a way but it's escaping me.

I've got this code
code:
return map { $_->servdef => $_->description } $self->load_all;
Works just fine. But I only want to return the hash that matches $_->enabled.

So I try
code:
return map { $_->servdef => $_->description if ($_->enabled) } $self->load_all;
And that not only doesn't work, it destroys the structure of my hash.

I can get it to work right using

code:
   foreach ($self->load_all) {
      if ($_->enabled) {
         $available_addons{$_->servdef} = $_->description;
      }
   }

   return %available_addons;
But I'd much rather use map for the one-linerness of it all. Is this possible with map?

EDIT:

Turns out this works. Why it doesn't work without an else statement, I have no idea.
code:
map { if ( $_->enabled ) { $_->servdef => $_->description } else {} } $self->load_all;

Beardless Woman fucked around with this message at 04:02 on Dec 17, 2008

Beardless Woman
May 5, 2004

M for Mysterious

Sartak posted:

working code

Thanks Sartak. You're right about returning the empty string. I wound up just using a foreach loop. I shouldn't try to get too clever.

EDIT: After playing around with it, turns out you simply have to have an else inside map if you're using if.

Beardless Woman fucked around with this message at 12:12 on Dec 17, 2008

Beardless Woman
May 5, 2004

M for Mysterious
Use Data:: Dumper to dump out the contents of $xml->{localLogDirectory} to see why it's coming up as a Hash.

Beardless Woman
May 5, 2004

M for Mysterious
I don't have a Windows box, so I don't have any way of testing it out, but it looks like you may be able to achieve what you're looking for through the use of WMI with the DBD::WMI module.

The Win32_ProcessStartTrace and Win32_ProcessStopTrace classes/tables are probably going to have what you're looking for.

Checking for starting processes should be as easy as a query like
code:
SELECT * FROM Win32_ProcessStartTrace
And checking for stopping processes should work with something like
code:
SELECT * FROM Win32_ProcessStopTrace

  • Locked thread