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
slipped
Jul 12, 2001

Rohaq posted:

Just a note for the future, a better way to write out regex questions in my mind is to do the following:

This is the data I'm parsing:
code:
			SECTION 12345

			SOMETHING SOMETHING

** Blah blah blah blah blah blah.

PART 1  SOMETHING
1.1  SOMETHING SOMETHING
     A. Something

PART 2  SOMETHING
2.1  SOMETHING SOMETHING
     A. Something

			END OF SECTION
And this is what I want to turn it into:
code:
[
  '12345',
  'SOMETHING SOMETHING',
  'Blah blah blah blah blah blah.',
  [
    'PART 1  SOMETHING',
    '1.1  SOMETHING SOMETHING',
    'A. Something'
  ],
  [
    'PART 2  SOMETHING',
    '2.1  SOMETHING SOMETHING',
    'A. Something'
  ]
]
Basically give us the example data, and give us an idea of what you want the final data structure to look with your example data. Having a regex that long, especially one that doesn't quite do what you want, makes it difficult to discern how you want to parse the data, and how you want it to end up.

I'm also more of a fan of a hash as storage when it comes to parsing out multiple values of data from raw text; it's far easier to pull out the data values you want from a hash than trying to remember the array position for the particular text you wanted, especially if your regex falls over with some data, and ends up populating the array incorrectly with odd data that caused an accidental match in your regex: It makes it far easier to spot in Perl's debugger when you can see that $regex_results['section_num'] contains incorrect data, rather than remembering what $regex_results[5] is for.

http://search.cpan.org/dist/Parse-RecDescent/lib/Parse/RecDescent.pm

or ... http://search.cpan.org/~dconway/Regexp-Grammars-1.012/lib/Regexp/Grammars.pm

Adbot
ADBOT LOVES YOU

anagramarye
Jan 2, 2008

Array Age Man

Excuse me a few moments while I go cry about not finding either those before spending ages getting it all worked out myself.

Edit: Not that I can figure out any idea of how to use either one from the linked documentation pages, but oh well.

Edit edit: If anybody'd happen to have a primer around for Regex::Grammars or a sample pattern or something that would roughly fit that structure I posted, that would be really cool. The whole auto-grammaring idea seems pretty spiffy, but I just can't wrap my head around how it's all setup.

anagramarye fucked around with this message at 11:43 on Dec 31, 2010

EVGA Longoria
Dec 25, 2005

Let's go exploring!

What are some modules for zipping in Perl? Specifically Perl 5.8.4 - Archive::Zip and IO::Compress don't exist.

I can't install anything else without a huge hassle, so if there's anything I'm missing, please let me know.

Edit: gently caress it, just going to use the system's zip command.

EVGA Longoria fucked around with this message at 16:20 on Jan 5, 2011

Clanpot Shake
Aug 10, 2006
shake shake!

I'd like to write a perl script that calls several executable jar files in sequence and appends all of their output (standard and err) to a log file.

I've googled and tried several variations, all similar to this:
pre:
open ($log, '>>', "Publish.log") or die "could not open file: $!#";

@cmd = `java -jar thingy.jar 2>&1`;

foreach (@cmd)
{print $log $_;}
but I'm not capturing all of the program's output. Can someone show me an example of how to do this? I couldn't quite wrap my head around open3.

pram
Jun 10, 2001

Clanpot Shake posted:

I'd like to write a perl script that calls several executable jar files in sequence and appends all of their output (standard and err) to a log file.

I've googled and tried several variations, all similar to this:
pre:
open ($log, '>>', "Publish.log") or die "could not open file: $!#";

@cmd = `java -jar thingy.jar 2>&1`;

foreach (@cmd)
{print $log $_;}
but I'm not capturing all of the program's output. Can someone show me an example of how to do this? I couldn't quite wrap my head around open3.
Wouldn't this work:
code:
open (STDOUT, "| tee -ai ~/Publish.log");

exec = `java -jar thingy.jar 2>&1`;

close (STDOUT);

Nevergirls
Jul 4, 2004

It's not right living this way, not letting others know what's true and what's false.

Clanpot Shake posted:

I'd like to write a perl script that calls several executable jar files in sequence and appends all of their output (standard and err) to a log file.

I've googled and tried several variations, all similar to this:
pre:
open ($log, '>>', "Publish.log") or die "could not open file: $!#";

@cmd = `java -jar thingy.jar 2>&1`;

foreach (@cmd)
{print $log $_;}
but I'm not capturing all of the program's output. Can someone show me an example of how to do this? I couldn't quite wrap my head around open3.

Try IPC::Run, specifically something like

code:
use IPC::Run qw(run);

my @jars = qw(thingy.jar thingy2.jar onemanone.jar);

for my $jar (@jars) {
  run ['java', '-jar', $jar], '<', \undef, '>>', "out.txt", '2>>', "err.txt";
}
ought to work.

Backticks are of the Devil. Avoid them at every opportunity.

syphon
Jan 1, 2001

wntd posted:

Backticks are of the Devil. Avoid them at every opportunity.
Why? I use them extensively to call external programs in Win32 platforms (where it's much more useful to parse the output than it is to catch the return code). I've never really run into a problem with them... but that certainly doesn't mean that one doesn't exist!

Nevergirls
Jul 4, 2004

It's not right living this way, not letting others know what's true and what's false.

syphon posted:

Why? I use them extensively to call external programs in Win32 platforms (where it's much more useful to parse the output than it is to catch the return code). I've never really run into a problem with them... but that certainly doesn't mean that one doesn't exist!

As soon as you do it, you've stopped writing perl and started writing shell. (Admittedly, this may not be as much of a concern on Windows.) On top of being inflexible, it introduces things you shouldn't have to think about. E.g., to capture stderr, you have to do something like
code:
my @output = `$cmd @args >/dev/null 2>&1`;
You have to do shell things like quote metacharacters in @args (or $cmd), especially if they're user-supplied, plus you have to get the redirection syntax right (the above isn't). And you can't get separate STDOUT and STDERR, you either have to pick one or the other or intermingle them or send them to files and read them back in. That's just gross.

Modules like IPC::Run or IPC::System::Simple are easier to use and more secure than deferring to the shell. I mean, there's a reason why you're doing this in perl in the first place, right?

Fenderbender
Oct 10, 2003

You have the right to remain silent.
yeah you should immediately have red flags going off for backticks the same as when you see eval()

Fenderbender fucked around with this message at 21:50 on Jan 8, 2011

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

Fenderbender posted:

yeah you should immediately have red flags going off for backticks the same as when you see eval()

NB. block eval != string eval

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Otto Skorzeny posted:

NB. block eval != string eval

Yeah, but even when you're tempted to use block eval, Try::Tiny is in most cases the proper solution.

Fenderbender
Oct 10, 2003

You have the right to remain silent.

Otto Skorzeny posted:

NB. block eval != string eval

I thought about editing that to make myself more clear, but was too lazy. Thanks for clarifying.

Clanpot Shake
Aug 10, 2006
shake shake!

wntd posted:

Try IPC::Run, specifically something like

code:
use IPC::Run qw(run);

my @jars = qw(thingy.jar thingy2.jar onemanone.jar);

for my $jar (@jars) {
  run ['java', '-jar', $jar], '<', \undef, '>>', "out.txt", '2>>', "err.txt";
}
ought to work.

Backticks are of the Devil. Avoid them at every opportunity.
In this example it writes to 2 different files, one for STDERR and one for STDOUT. I need to route both to the same file (a couple of the methods I tried ran into concurrency problems).

For context, This is running on a windows server and doesn't take user input.

Roseo
Jun 1, 2000
Forum Veteran
Anyone know how to edit the state of an initialized Log::Log4perl? There's not much documentation on it that I can find. I'm making a Moose role for internal libraries that takes a optional logger name and config file parameter, and pushes the configuration in the passed config onto the Log::Log4perl initialization at runtime.

Since because different libraries get run as different users and I don't want every app getting append access rights to every logfile on the system, I need to do it like this as the monolithic config file that Log::Log4perl is based on requires anything consuming it to be able to initialize every logger.

Wheelchair Stunts
Dec 17, 2005

Roseo posted:

Anyone know how to edit the state of an initialized Log::Log4perl? There's not much documentation on it that I can find. I'm making a Moose role for internal libraries that takes a optional logger name and config file parameter, and pushes the configuration in the passed config onto the Log::Log4perl initialization at runtime.

Since because different libraries get run as different users and I don't want every app getting append access rights to every logfile on the system, I need to do it like this as the monolithic config file that Log::Log4perl is based on requires anything consuming it to be able to initialize every logger.

I'm not sure if this is helpful but there is a system-wide threshold that can be set which overwrites category levels and such. It's in the Log4perl FAQ

Roseo
Jun 1, 2000
Forum Veteran

Wheelchair Stunts posted:

I'm not sure if this is helpful but there is a system-wide threshold that can be set which overwrites category levels and such. It's in the Log4perl FAQ

Not really. I'm trying to init it from multiple config files, so I can have a config per library that gets composed into the configuration at runtime and only opens up writes into the needed files instead of every logfile on the system.

syphon
Jan 1, 2001
I'm writing a script using Win32::OLE to modify a setting on an IIS6 site. Here's the script:
code:
#!perl
use strict;
use Win32::OLE;

#first create the ADSI object
my $websvc = Win32::OLE->GetObject("IIS://localhost/W3SVC/1")
	or die "Error creating ADSI object\n$!\n";

#now change its ServerComment (description)
$websvc->Put("ServerComment","new site name");

#commit the change
$websvc->SetInfo();
This script works fine as is. It successfully modifies the 'ServerComment' attribute of my IIS site. The problem is, I want to know if either the Put() or SetInfo() methods fail... so I change them to say this:
code:
#now change its ServerComment (description)
$websvc->Put("ServerComment","new site name")
	or die "Error setting value!\n$!\n";

#commit the change
$websvc->SetInfo()
	or die "Error committing change!\n$!\n";
Now, when I run it, the script outputs "Error setting value! Bad file descriptor" Even though the script worked perfectly fine without the 'or' conditional, As soon as I added it, it seems to be causing the script to die.

My immediate assumption is that the Put() method must return a positive value by default, but it seems to return null (when it succeeds). Any idea why my script is failing when I add in the 'or' conditionals? Note that the 'or' conditional doesn't cause any problems on the object instantiation, only with the Put() or SetInfo() methods.

syphon fucked around with this message at 20:03 on Jan 28, 2011

welcome to hell
Jun 9, 2006
The value the Put and SetInfo methods return for success depends on the implementation of the OLE object, and in this case doesn't correspond to Perl's idea of true and false. They return the constant S_OK for success, which has a value of 0.

syphon
Jan 1, 2001
I figured it was an issue of ADSI and Perl talking to each other in the same language. How can I check for errors in these methods?

pram
Jun 10, 2001
Is there an easy way to show yesterdays date using the POSIX module? (or another)

You can just do `date -d yesterday` on the command line and it will work but every solution I've seen online for perl is some massive block of code:

code:
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;

sub spGetYesterdaysDate;
print spGetYesterdaysDate;

sub spGetYesterdaysDate {
my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
my $yesterday_midday=timelocal(0,0,12,$mday,$mon,$year) - 24*60*60;
($sec, $min, $hour, $mday, $mon, $year) = localtime($yesterday_midday);
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $YesterdaysDate = sprintf "%s %02d %4d", $abbr[$mon], $mday, $year+1900;
return $YesterdaysDate;
}
:shepface:

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
DateTime is a prime candidate for this:

print DateTime->today->subtract( days => 1 )->ymd;

or maybe instead of ymd, you can also use strftime with an appropiate pattern.

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 Really Wish Parrot Had Memory Barriers :sigh:

Fenderbender
Oct 10, 2003

You have the right to remain silent.
Does anyone have any experience with XS? I'm writing some web services that use this commercial format for geolocating IPs and the pure Perl module they have is way too slow for my needs but they have a very quick C library. What would be a good start in just making a bare bones XS library for exposing the functions in the C library?

For reference: http://www.ip2location.com/c.aspx

tef
May 30, 2004

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

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
After an hour of googling, for the life of me, I cannot figure out how to extract information from a hash table without using a key value.

Lets Say I have a has table called %thisStupidTable with the following keys/values:

code:
fruit, orange
veg, carrot
meat, beef
Now lets say I want to extract the first key and first value of information independently (fruit and orange respectively) from thisStupidTable without using 'fruit' as a reference. What I'd expect to be able to do is something like this

code:
$someVariable = %thisStupidTable[$key0];
$someVariableTwo = %thisStupidTable[$value0];
Similiarly, if I wanted the 2nd set of values independently, I'd figure I'd be able so say the following:

code:
$someVariable = %thisStupidTable[$key1]; #this would assign 'veg' to $someVariable
$someVariableTwo = %thisStupidTable[$value1]; #this would assign 'carrot' to $someVariableTwo
But I can't do that and I cannot figure out how to do it. I don't want to put the entire table through a loop, I just want direct access to my goddamn lovely hash table. Someone be my hero baby and tell me how to do this before I start pulling hair out in frustration.

Canine Blues Arooo fucked around with this message at 01:49 on Feb 15, 2011

Anaconda Rifle
Mar 23, 2007

Yam Slacker
There are a couple of mistaken assumptions and bad syntax in your post, but I'll try my best with an answer.

First off, the concept of order in a hash is not straight forward. You can create your hash, but getting the same order out without tricks isn't going to happen.

If you want to pull information out of your hash, you're going to want to look at keys and each.

Also, when you're extracting scalars out of a hash, you need to use the scalar sigil ($) instead of the hash sigil (%), so:

code:
my $type = $thisStupidTable{'orange'};
print "$type\n";
would print "fruit\n".

Is that what you're asking?

Edit: I don't know if I came off condescending. I apologize if I did.

Anaconda Rifle fucked around with this message at 02:18 on Feb 15, 2011

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer

Anaconda Rifle posted:

There are a couple of mistaken assumptions and bad syntax in your post, but I'll try my best with an answer.

First off, the concept of order in a hash is not straight forward. You can create your hash, but getting the same order out without tricks isn't going to happen.

If you want to pull information out of your hash, you're going to want to look at keys and each.

Also, when you're extracting scalars out of a hash, you need to use the scalar sigil ($) instead of the hash sigil (%), so:

code:
my $type = $thisStupidTable{'orange'};
print "$type\n";
would print "fruit\n".

Is that what you're asking?

It's close, but instead of using 'orange' as a point of reference, I want to reference it from it's numerical position in the hash table, in this case, instead of using this:

code:
my $type = $thisStupidTable{'orange'};
I want to do something like this:

code:
my $type = $thisStupidTable{0, 1}; #using it like a 2d array, 'orange' being the 2nd element of the 1st hash in this case
The above is probably incorrent, but it illustrates how instead of using a reference, I want to use it's numerical position in the table to access it. For the moment, I just did this:

code:
$arrayTracker = 0;
@array = @remoteHostsArray;
%count;
map { $count{$_}++ } @array;
foreach $value (reverse sort {$count{$a} cmp $count{$b} } keys %count)
	{	
		#print "$value $count{$value}\n";
		
    		push(@orderedHostArray, $value);
    		push(@orderedHostArray, $count{$value});
    	}
Which works well enough to extract the information I want ordered and such, but it'd be nice to know how to simply directly reference it from a hash instead of having to dump it into an array every time I want to do something with it.

However, with my solution above, when I try to reference, say $orderededHostArray[5] later in the program, it returns null, even though if I uncomment the print lines, it clearly shows there is a value in the 6th slot of the array.

edit: figured out the issue with the code above as well and it mostly revolves around me making more assumptions about this language.

Canine Blues Arooo fucked around with this message at 02:41 on Feb 15, 2011

Anaconda Rifle
Mar 23, 2007

Yam Slacker
http://search.cpan.org/~mhx/Tie-Hash-Indexed-0.05/lib/Tie/Hash/Indexed.pm maybe?

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer

That right there is a thing of beauty!

Kidane
Dec 15, 2004

DANGER TO MANIFOLD

Canine Blues Arooo posted:

That right there is a thing of beauty!
You should probably step back and rethink what you are doing or the way you are storing data. I can't think of a compelling reason to reference hash data by index. If you really need to, you can have an array full of hash references but again I'm not sure why you would need that. Maybe you could elaborate on what you're trying to accomplish?

Roseo
Jun 1, 2000
Forum Veteran
If you use Tie::* whoever uses your code after you is going to hate you. If you want to access your values in numerical order, simply use a data structure. For example:

code:
my $items = [ { category => 'fruit',
                type => 'orange',
              },
              { category => 'veg',
                type => 'carrot',
              },
              { category => 'meat',
                type => 'beef',
              },
            ];

say "Item 0 '$items->[0]{type}' is a '$items->[0]{category}'"; ### "Item 0 'orange' is a 'fruit'
Edit: it's late, but I'm fairly certain you want something like:

code:
use strict;
use warnings;
use 5.12.1;

my @remoteHostsArray = qw/ 127.0.0.1 192.168.1.1 127.0.0.1 192.168.1.2 127.0.0.1 192.168.1.1 /;

my %count;
$count{$_}++ for @remoteHostsArray;

my @orderedHostsArray = map { { ip => $_ , requests => $count{$_} } } sort {$count{$b} <=> $count{$a}} keys %count;

for my $host (@orderedHostsArray) {
  ### Do stuff with hosts from most to least requests
  say "Host $host->{ip} had $host->{requests} pageviews!";
}
Outputs:

code:
Host 127.0.0.1 had 3 pageviews!
Host 192.168.1.1 had 2 pageviews!
Host 192.168.1.2 had 1 pageviews!
edit: And use <=> to sort, it's the numerical sort operator. cmp stringifies and sorts alphabetically.

Roseo fucked around with this message at 07:47 on Feb 16, 2011

unlock
Oct 23, 2008

by T. Finn

Triple Tech posted:

Nevermind what I said. Low reading comprehension. :colbert:

Why don't you go gently caress yourself

uG
Apr 23, 2003

by Ralp
Is there a way to have Catalyst output what it is using from cache? I'm dynamically creating thumbnails, but i'm not sure if page_cache is caching them or not.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
I just got done overhauling quote_literal in EUMM and i have this need to share the love pain. After all, sharing is caring, right?

If you have simple strings like this:
code:
perl -e "print qq{@ARGV};"      --    " " "
 
Nothing happens. It seems to work fine to just escape it though:
code:
perl -e "print qq{@ARGV};"      --    " \" "
                                       "
Things will work fine even when you do this:
code:
perl -e "print qq{@ARGV};"      --    " < \" "
                                       < "
But this blows up:
code:
perl -e "print qq{@ARGV};"      --    " \" < "
                                      Das System kann den angegebenen Pfad nicht finden.
Now you google and find out that quotes need to be doubled to be escaped and it works again:
code:
perl -e "print qq{@ARGV};"      --    " "" < "
                                       " <
So okay, you just double-quote every quote. And try something like this:
code:
perl -e "print ""@ARGV"";"      --    " "" < "
                                      Can't find string terminator '"' anywhere before EOF at -e line 1.
Wait, what? Ok, sheesh, more googling. Turns out you ACTUALLY have to triple-quote quotes sometimes. Why? :iiam: In either case, this works fine:
code:
perl -e "print """@ARGV""";"    --    " 1 "
                                       1
So, let's throw some <s in there!
code:
perl -e "print """@ARGV""";"    --    " """ < "
                                      Das System kann den angegebenen Pfad nicht finden.
drat! More googling. Turns out <, > and | are special characters that need to be escaped with a caret:
code:
perl -e "print """@ARGV""";"    --    " """ ^< "
                                       " <
Awesome, let's be adventurous:
code:
perl -e "print """@ARGV""";"    --    " ^< """ "
                                       ^< "
What. No, seriously, what? Let's try this:
code:
perl -e "print """@ARGV""";"    --    " ^< """ ^< "
                                       ^< " <
:what: Apparently escaping with the caret works only sometimes! More fun:
code:
perl -e "print """@ARGV""";"    --    " ^< """ ^< """ ^< """ ^< "
                                       ^< " < " ^< " <
Not shown: Literally hundreds of different permutations of character doubling, tripling, caret-escaping and backslash-escaping that produce results that make absolutely zero sense for someone expecting a parser dealing with balanced string delimiters.

Apparently the DOS batch parser is hilariously naive! This is code that actually represents working escaping under DOS batch parsing rules:
code:
    my @text        = split '', $text;
    my $quote_count = 0;
    my %caret_chars = map { $_ => 1 } qw( < > | );
    for my $char ( @text ) {
        if ( $char eq '"' ) {
            $quote_count++;
            $char = '"""';
        }
        elsif ( $caret_chars{$char} and $quote_count % 2 ) {
            $char = "^$char";
        }
        elsif ( $char eq "\\" ) {
            $char = "\\\\";
        }
    }
    $text = join '', @text;
And now EUMM will, with the next release, be able to handle escaping anything people throw at it. Until someone finds another edge case...

qntm
Jun 17, 2009
Perhaps I haven't looked far enough, but I've never found a command line shell which provides the simple ability to safely escape-and-quote an arbitrary string. If you fancy another hilarious/maddening edge case in DOS, try getting this to actually print "%PATH%" out:

code:
perl -e "print qq{@ARGV};" -- "%PATH%"
Of course this is a problem with the shell, not Perl.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

qntm posted:

Perhaps I haven't looked far enough, but I've never found a command line shell which provides the simple ability to safely escape-and-quote an arbitrary string.

I think fish does? I should switch to it because I hate every shell including the one I use, zsh. Any shell that makes me type '"'"' instead of \' is a bastard.

To bring this back to Perl a bit, there's a module that should be in your toolbox: String::ShellQuote.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
^^^^
Edit: This is entirely on Perl, let me assure you. I'm working on EUMM right now to get it to behave a lot nicer on Windows. Perfect DOS escaping would really be a treat there, but is just one of the things i'm doing.


Heh, that one was surprisingly simple when you know that cmd.com ends input strings either at the closing quote or at the end of the line.
code:
C:\Windows\System32>perl -e "use Data::Dumper; print Dumper( \@ARGV );print qq{@ARGV};" -- "%PATH%"
$VAR1 = [
          'C:\\Program[...]'
        ];
C:\Program[...]
C:\Windows\System32>perl -e "use Data::Dumper; print Dumper( \@ARGV );print qq{@ARGV};" -- "%"PATH%"
$VAR1 = [
          '%PATH%'
        ];
%PATH%
Try this one. :haw:
code:
perl -e "use Data::Dumper; @ARGV = '%PATH%'; print Dumper( \@ARGV );print qq{@ARGV};" --
I have no idea what the gently caress.

leedo
Nov 28, 2000

Has anyone ever encountered code where a hashref is preceded by a +? I have seen this a few times and have not been able to figure out why it is being done. I assume it forces some sort of context... but I have never been able to find a case where it actually did anything.

e.g.
code:
+{
    'DBI' => [
        'dbi:SQLite:dbname=development.db',
        '',
        '',
        +{
            sqlite_unicode => 1,
        }
    ],
    'Text::Xslate' => +{
    },
};
edit: and a quick google search later clears it up. It is meant to disambiguate a hashref from a code block.

leedo fucked around with this message at 23:12 on Mar 8, 2011

Clanpot Shake
Aug 10, 2006
shake shake!

Is there a platform independent way to determine the amount of free memory on a system? I need to pass a heap size argument to a java process and the systems this will run on vary in OS and memory. I'd like to use 2, 3, or 4 GB of RAM depending on what's available.

Adbot
ADBOT LOVES YOU

Vomik
Jul 29, 2003

This post is dedicated to the brave Mujahideen fighters of Afghanistan
I am having some troubles with the Outlook OLE and accessing some of its methods from Perl.

Specifically, I'm looking to get the attachments from a file sitting in a public mailbox and move them to the network.

A paired down version of my code is below:

code:
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const '.*Outlook';

my $outlook = Win32::OLE->GetActiveObject('Outlook.Application');
die "Outlook isn't running." unless $outlook;

my $namespace = $outlook->GetNameSpace("MAPI");

# some code here to get the location of the mailbox and the inbox of that mailbox
my $inbox = $namespace->Folders($i)->Folders($j);

# some code here to get to the proper email message
my $text = $inbox->Items->Item($wanted);

Now from here I know I have the right message because print $text->Subject; will return the subject line. The problem is I can't seem to get anything else. I've looked through the object browser in outlook and I've tried Attachments but it doesn't seem to work. For instance, print $text->Attachments->Count; just returns the warning "Can't call method "Count" on an undefined value." Also, body/to/from etc. don't seem to return anything either. Does anyone have any tips/ideas? I checked the class of the item and it is class 43 (mailitem.)

  • Locked thread