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
EVGA Longoria
Dec 25, 2005

Let's go exploring!

With Win32::OLE, is it possible to pass credentials for a call to retrieve information with a GetObject? The code I'm using works fine locally, but gets access denied remotely. Everything I can find about passing credentials seems to be specific to AD or running processes, and not for GetObject. Can anyone point me in the right direction for credentials?

Adbot
ADBOT LOVES YOU

mike12345
Jul 14, 2008

"Whether the Earth was created in 7 days, or 7 actual eras, I'm not sure we'll ever be able to answer that. It's one of the great mysteries."





I already posted about this in the Linux-thread, not knowing that there's an entire sub-forum for programming. Sorry for the double-post:

I'm looking for someone to write a script for my website, more info @ http://forums.somethingawful.com/showthread.php?threadid=3398004 (SA Mart).

Basically the scripts needs to crawl folders of static html and randomize links and images. I pay 20 bucks.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
The new release of ExtUtils-MakeMaker has run into a very unexpected snag. It requires Scalar-Util, which is not core with 5.6 and thus bundles its own, in pureperl, which however breaks Compress::Zlib >V2.

Since i know some people who're very well-versed in Perl have an eye on this thread, i'd like to request any input you'd be willing to give on this issue: https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/issues/4

Video Nasty
Jun 17, 2003

Long-time reader, first time poster for Perl help.
Preface: I'm only well-versed in HTML and CSS with light understanding of Perl so far. After re-writing a trouble ticket alert system into a better designed interface, I am having trouble with the actual alert emails it sends out after checking input and determining difference between current time and when the ticket was submitted to fire off the emails to a list.
The code snippet I'm having trouble with understanding is
code:
open(DB, "<", "C:/Inetpub/wwwroot/DBase.htm") || die "Error: $!\n";
			  
    my(@arr, $line, $i);
	while (<DB>)
	{	 
	study;
	for ($i = ++$i ){
	@arr = <DB>;	
	$arr[$i] = (split /\n/, $line);    
	}
	
		splice (@arr, 0, 12);
		foreach $line (@arr) {
				$line =~ s/\|//g;
				$line =~ s/<\/TD><\/TR><TR><TD>/\n/g;
				$line =~ s/<\/TD><TD>/\|/g;
				$line =~ s/&nbsp;//g;
				$line =~ s/<\/TD><\/TR>//g;
				$line =~ s/<TR><TD>//g;
				chomp($line);
			}
		
}
	close (DB) || die "Error: $!\n";

					
	ticketsDue();
	
	sub ticketsDue {
	
	  while (++$i <= $#arr) {
	    $line = "$arr[$i]";
		my ($ticket,$DateAdded,$STime,$ETime,$Pri,$SiteName,$Comments) =
 split(/\|/,$line);
	   	 my($Ehour, $Emin) = split(/\:/,$ETime);
	if ($Ehour >= $SLAhour && $Emin >= $SLAmin && $Ehour <= $hour && $Emin <=
 $currmin && $DateAdded == $currDate) {
		my @currArray = ($ticket,$Pri);
		my (@newarr);
	     push(@newarr, @currArray);
	
	      }
The subroutine is where I'm unable to pass variables from the split line into the new arrays so I can push those into an email alert.
The code afterward plugs the $newarr[0] and $newarr[1] into an email for ticket and priority level, but I keep hitting "uninitialized value" in the split. I've been unable to reach the original creator of this, so would anyone be able to show me where I'm loving up? Any advice would be greatly appreciated. I have not been able to find much on this elsewhere.

edit: bumped the line wraps so the page doesn't stretch.

edit: I know everyone hates using RegEx to remove HTML markup, but this will not be dynamic and I'm only pulling off table tags to split the columns into their own scalars.

Winkle-Daddy
Mar 10, 2007

Jake Blues posted:

I keep hitting "uninitialized value" in the split.

Well, the first thing I would do is just throw some basic print statements in there. Before

code:
my($Ehour, $Emin) = split(/\:/,$ETime);
Print the value of $ETime to make sure it's returning a value. Though, the problem is likely to be more subtle then that. If it was me I'd load up the ol' wonderful perl debugger and step through this line by line constantly doing x $[var] and making sure I have values set at each step and what they look like. I've had more then one split fail because the way I handled some input built my string or array in a strange/unexpected way.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
code:
	for ($i = ++$i ){
I had to actually run this to find out what Perl does with it, it turns out it merely executes that loop once (consuming a line from input) and then exits. But doesn't the while() loop already consume lines?

:wtc:

Winkle-Daddy
Mar 10, 2007

Mario Incandenza posted:

code:
	for ($i = ++$i ){
I had to actually run this to find out what Perl does with it, it turns out it merely executes that loop once (consuming a line from input) and then exits. But doesn't the while() loop already consume lines?

:wtc:

I thought that would cause it to go on in an endless loop and only break when told to break the loop. Now I have to try it too!

e: Just tried it, you're right! All I can think of is that it's used to test a function that you eventually want to make a loop out of it, but just need it to temporarily run once for testing.

e2: VVV I sad all I can think of, not to be confused with 'I think it's a good idea.'

Winkle-Daddy fucked around with this message at 01:59 on Mar 31, 2011

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Winkle-Daddy posted:

All I can think of is that it's used to test a function that you eventually want to make a loop out of it, but just need it to temporarily run once for testing.

What the gently caress. Just do for (1) or do if that's what you need. If multiple people need to run a code snippet to figure out what it does, it probably doesn't belong in real code.

Erasmus Darwin
Mar 6, 2001
I believe the infamous code fragment:
code:
for ($i = ++$i ){
is pretty much identical to this:
code:
foreach $_ (++$i) {
And since it's using a foreach loop to iterate through a single item list, it's effectively the same as:
code:
++$i;
{
  local $_ = $i;

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled
What I want to know is, if you're already a perl guy, why the hell aren't you using Request Tracker for your ticketing system? Knowing some perl you can make it to do all kinds of awesome stuff.

Anaconda Rifle
Mar 23, 2007

Yam Slacker

Cock Democracy posted:

What I want to know is, if you're already a perl guy, why the hell aren't you using Request Tracker for your ticketing system? Knowing some perl you can make it to do all kinds of awesome stuff.

Do you work with Filburt Shellbach?

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled

Anaconda Rifle posted:

Do you work with Filburt Shellbach?
Nope, but I enjoyed his work in Rocko's Modern Life.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Cock Democracy posted:

What I want to know is, if you're already a perl guy, why the hell aren't you using Request Tracker for your ticketing system? Knowing some perl you can make it to do all kinds of awesome stuff.

What kind of awesome stuff have you made it do? (disclaimer: I work for the company that makes it, hence Anaconda's question)

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled

Filburt Shellbach posted:

What kind of awesome stuff have you made it do? (disclaimer: I work for the company that makes it, hence Anaconda's question)
It's just so easy to do the custom reports. As an example, I have a report where you pick a queue and a date range and it shows you each ticket along with the time between ticket creation and our first reply. Basically an "average response time" report.

The scrip system is handy too. Here's an example of a special scrip we use. Our e-mail is hosted by a third party so we have to pay per-user licensing on email accounts. Therefore it's cost prohibitive to have an email account for every address going into RT. We dealt with this by giving RT one real mailbox and using forwarders for the different queues' addresses. Then we have a custom scrip that looks at the "to" address and moves the ticket into the correct queue.

I realize these are kind of minor things, but what a powerful platform. My impression is that tons of great data is being collected, I just need to write more custom reports to take advantage of it.

I'm looking forward to the new 4.0 release and am planning on setting it up on a test server next week. Can you share any "inside scoop" type things to look forward to?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Glad to see you're making good use of RT!

Lifecycles are the coolest new feature in 4.0. You can define your set of ticket statuses and transitions between them at the queue level. There's also full-text search that doesn't suck, and lots of good UI improvements like quote folding.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
Any OpenSSL gurus around? I'm trying to get a client-side x509 cert from Thawte working but I'm getting 'sslv3 alert certificate unknown' bubbling up through Net::SSLeay and IO::Socket::SSL. Apparently they added an intermediary certificate to their chain last year and now it seems Perl isn't properly walking up the chain of trust.

syphon
Jan 1, 2001
Quick, what's the easiest way to take a list, edit it down to only unique entries, then sort it? Here's what I've got, but it feels inelegant.
code:
for (@raw) { 
  $unique->{$_} = $_; 
}
for (keys %$unique) {
  push @sorted, $unique->{$_} . "\n"
}
print sort @sorted;
EDIT: Whoops, fixed a cut&paste error.

syphon fucked around with this message at 00:47 on Apr 5, 2011

Anaconda Rifle
Mar 23, 2007

Yam Slacker

syphon posted:

Quick, what's the easiest way to take a list, edit it down to only unique entries, then sort it? Here's what I've got, but it feels inelegant.
code:
for (@raw) { 
  $unique->{$1} = $1; 
}
for (keys %$unique) {
  push @sorted, $unique->{$_} . "\n"
}
print sort @sorted;

print sort map{!$}{$_}++?$_:()}@raw;

Edit: depends on what you consider "elegant"...

Anaconda Rifle fucked around with this message at 01:03 on Apr 5, 2011

leedo
Nov 28, 2000

code:
use List::MoreUtils qw/uniq/;
sort uniq @raw;
!!!!

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
List::Util
List::MoreUtils


ffffffffffffffffffff

qntm
Jun 17, 2009

Anaconda Rifle posted:

print sort map{ !$}{$_}++ ? $_ : () } @raw;

Edit: depends on what you consider "elegant"...

What the hell does %} (as referenced in "$}{$_}" ) do? Apparently it's a global variable (I can't declare "my $};" or "my %};") but it's so obscure it doesn't even appear in perlvar :psyduck:

Also, why the exclamation mark?

quote:

print sort map { $someotherhash{$_}++ ? () : $_ } @raw;

Anaconda Rifle
Mar 23, 2007

Yam Slacker
Elegance in Perl is in the eye of the beholder.

My response was a joke. I would never write production code like that. The use of %} passes warnings and stricture, and has the added benefit of looking like it pairs with the { before the !. The negation was because I wanted to see a monkey in my one-liner. Why did you choose to make unique a hash reference instead of a hash? Why did you assign the value as the key instead of 1 or "This poo poo been done seen"? It's all in good fun.

qntm
Jun 17, 2009
I get that it's silly code. I was just puzzled as to why an obvious Perl golf candidate had an extraneous character.

And also: if you do

code:
print Dumper(\%a);
then that doesn't work - obviously, because %a hasn't been declared. But

code:
print Dumper(\%});
does work, and outputs an empty hash. Where, and why, is a hash named %} declared? It's not me, and it's not mentioned in perlvar as a built-in variable. Obviously, it's straightforward to populate it with stuff, but what is it supposed to be for? Very strange.

Anaconda Rifle posted:

Why did you choose to make unique a hash reference instead of a hash?

I'm not sure what this means.

Anaconda Rifle
Mar 23, 2007

Yam Slacker

qntm posted:

I'm not sure what this means.

You used $unique as opposed to %unique.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

qntm posted:

Where, and why, is a hash named %} declared? It's not me, and it's not mentioned in perlvar as a built-in variable. Obviously, it's straightforward to populate it with stuff, but what is it supposed to be for? Very strange.

In general, special variables like $_ and @ARGV are "superglobal" because package scope does not apply to them. This means you can use them in any package and they have the same value. The way this is implemented internally is (I presume) marking the globs *_ and *ARGV as superglobal. This has a side-effect of making @_ %_ $ARGV and %ARGV superglobal as well. @_ is even specialer so ignore it for now.

%ARGV is populated by modules like Getopt::Whatever and is generally useful.

Jifty abuses sub _ { ... } to get a superglobal function for localizing text. Functions are in stored in typeglobs too.

$} is not a special variable so I don't know why it follows this pattern. Maybe an oversight, or maybe it's just because it's a punctuation variable.

summary: gently caress symbol tables and gently caress type globs

qntm
Jun 17, 2009

Anaconda Rifle posted:

You used $unique as opposed to %unique.

%unique{$_}++ wouldn't work. Would it?

syphon
Jan 1, 2001
I've got another hopefully quick question. Can someone explain how escaping works when running perl expressions directly into a Windows command line using perl -e? I'm trying to run this command at a command prompt:
code:
type sitelist.txt | perl -e "while (<>) { $_ =~ s/\"//g; if ($_ =~ /(?:Site Name|sitename) (\S+)$/) { print \"$1\n\"; }};"
Its purpose is to take some input, strip out all double quotes, then output lines that match a regular expression.

However, when I run this command, It simply errors with "'sitename)' is not recognized as an internal or external command, operable program or batch file." Obviously the command prompt is freaking out because I need to escape something (maybe the | inside the second regex? Maybe the " from my first regex?)

The weird thing is, the expression works if I remove either of the two regular expressions! If I remove "$_ =~ s/\"//g;" the script works, and if I remove "if ($_ =~ /(?:Site Name|sitename)" the script works. Because of this, I don't know what character is causing the problem and how to fix it!

Mario Incandenza
Aug 24, 2000

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

Mario Incandenza posted:

Any OpenSSL gurus around? I'm trying to get a client-side x509 cert from Thawte working but I'm getting 'sslv3 alert certificate unknown' bubbling up through Net::SSLeay and IO::Socket::SSL. Apparently they added an intermediary certificate to their chain last year and now it seems Perl isn't properly walking up the chain of trust.
RESOLVED: socat TCP4-LISTEN:7000,reuseaddr,fork OPENSSL:example.com:700,verify=0,cafile=$ca_cert,key=$key_file,certificate=$cert_file

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

syphon posted:

I've got another hopefully quick question. Can someone explain how escaping works when running perl expressions directly into a Windows command line using perl -e? I'm trying to run this command at a command prompt:
code:
type sitelist.txt | perl -e "while (<>) { $_ =~ s/\"//g; if ($_ =~ /(?:Site Name|sitename) (\S+)$/) { print \"$1\n\"; }};"
Its purpose is to take some input, strip out all double quotes, then output lines that match a regular expression.

However, when I run this command, It simply errors with "'sitename)' is not recognized as an internal or external command, operable program or batch file." Obviously the command prompt is freaking out because I need to escape something (maybe the | inside the second regex? Maybe the " from my first regex?)

The weird thing is, the expression works if I remove either of the two regular expressions! If I remove "$_ =~ s/\"//g;" the script works, and if I remove "if ($_ =~ /(?:Site Name|sitename)" the script works. Because of this, I don't know what character is causing the problem and how to fix it!

Short version: Just don't do it. Use Cygwin if you need complex perl poo poo on the command line on windows.

Long version: I'm working on fixing the DOS quoting in EUMM, among other things, and i thought i had a decent algorithm to do it. Then i stumbled across the little puzzle of how to escape %PATH%. Fixed that yesterday, two or three weeks after i found out about it. Then today i wrote a fuzzer to see if i could improve the algorithm and it's falling over literally everywhere and it's already stupidly complicated.

welcome to hell
Jun 9, 2006
And don't forget about escaping !PATH! if delayed expansion is turned on.

Winkle-Daddy
Mar 10, 2007
Concept question here...recently we've been tightening security on a few of the command line scripts we run for various reporting and in the past we would do something like:

code:
system("path_to_whatever $some_var1 $some_var2");
Obviously straight forward. Now, I've been tasked with hardening a lot of these scripts with things like:

code:
my @cmd;
push (@cmd,
      "path_to_whatever",
      $some_var1,
      $some_var2,
     );
my $in;
my $out;
IPC::Run::run(\@cmd,\$in,\$out);
When this is not a web accessible service...am I wasting my time in rewriting everything to use IPC::Run? One of our other Perl guys insists this is more secure, and another Perl guy insists this really does nothing helpful security wise. Goons weigh in?

Out of habit, I started writing any system command using IPC::Run, what I'm doing now though is going back and rewriting very old code to do the same.

Mario Incandenza
Aug 24, 2000

Tell me, small fry, have you ever heard of the golden Triumph Forks?
They're both right. Technically if the arguments to system() ended up containing metacharacters for whatever reason (malice, ignorance, bad luck) then it could do something dangerous, but if the scripts are not publicly accessible and the box is sufficiently locked down, then it's less of a concern.

Winkle-Daddy
Mar 10, 2007

Mario Incandenza posted:

They're both right. Technically if the arguments to system() ended up containing metacharacters for whatever reason (malice, ignorance, bad luck) then it could do something dangerous, but if the scripts are not publicly accessible and the box is sufficiently locked down, then it's less of a concern.

Yeah, I was just getting ready to come back and edit that I found out why I've been asked to do this. Anything checked in to our SVN system gets scanned on check-in and a bug is auto filed for certain functions being used (in this case 'system') and no one thought to include those of us fixing it on the bug. Instead the people who got it just spread out the work amongst us and told us it was a "security issue."

After some digging, the same security criteria for internal and external facing code review is the same; hence the alert.

At least I only have a few dozen super old scripts to review, and I should be able to retire about half of them.

id107
Aug 1, 2004
put optional title text here
I'm probably stupid, but perl is being weird again.

FOUND IT: I changed <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
to <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
--
I have a html form with the name "search". In this form I enter "é" (without quotes). I pass it to perl. There, I want to convert it to &eacute; . Sadly, perl likes to output &Atilde;&copy; (é) better than &eacute; for some reasons.

code:
#!/usr/bin/perl 

print "Content-type: text/html\n\n";

use HTML::Entities;
use CGI qw(:standard);

$search = param('search');

print encode_entities($search), "\n"; #fails: é
if ($search=~/é/){print "they are exactly the same";} #fails
print "search: ".$search."\n"; #prints é
$search=encode_entities($search);
print "search: ".$search."\n"; #fails: é

$input = "vis-à-vis Beyoncé's naïve\npapier-mâché résumé";
print encode_entities($input), "\n"; #these two lines work perfectly :-(

id107 fucked around with this message at 21:23 on Apr 6, 2011

StrikerJ
Oct 8, 2001

I have a text file containing stuff like "abz abx aby" (among other words) and I want to match on the "ab"-part and get a list of the next character. In the above example it should produce the following:

z
x
y

I got the following code that works but I have a feeling it can be done much more effective:

code:
@matches = $file =~ m/ab\w/g;

foreach (@matches) {
	$_ =~ s/ab/\n/;
	print $_;
}
Any suggestions or hints would be appreciated since I'm trying to learn the concepts and not only produce an acceptable result. :)

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

StrikerJ posted:

Any suggestions or hints would be appreciated since I'm trying to learn the concepts and not only produce an acceptable result. :)

This will extract just the matches:
code:
@matches = $file =~ m/ab(\w)/g;

StrikerJ
Oct 8, 2001

Mithaldu posted:

This will extract just the matches:
code:
@matches = $file =~ m/ab(\w)/g;

Just what I was looking for, thanks!

octobernight
Nov 25, 2004
High Priest of the Christian-Atheist Church
I'm trying to extract names out of a tree structure and replace the labels with my own labels. The format is called newick, so this represents a full binary tree: ((A,B),(C,D)).

Here's my code to get the names and make a rename map.

code:
        
	if (@matches = $file =~ /[\(,]([^,\);]+)/smg) {
		foreach my $match (@matches) {
			my $name = trim($match);
			$name_map{$name} = $name + "_foo";
		}
	}
Here's where I get confused. The names can be substrings of each other, so if I do a global search/replace to replace A with A_foo, it will also replace AA with A_fooA. How do I prevent this? It feels like I'm so close since I have the part that needs to get replaced, but I have no idea how to finish the very last step. I imagine the code will be very similar to this snippet.

EDIT: Never mind, I figured it out. It doesn't feel very elegant, but I think it works:
code:
        #Requires that labels end with a ,) or ;
	foreach my $key (keys %name_map) {
		$file =~ s/$key([,\);])/$name_map{$key}$1/g;
	}

octobernight fucked around with this message at 05:10 on Apr 22, 2011

qntm
Jun 17, 2009
That solution does work, but I foresee problems if the existing tree already contains elements ending in "_foo", e.g. "A" and "A_foo". The existing "A" will be converted to "A_foo" on the first pass, while the existing "A_foo" will be left alone. On the second pass, you will end up with "A_foo_foo" and "A_foo_foo" respectively, which is wrong.

This might work instead:

code:
$string =~ s/([\(,])([^,\);]+)/$1$2_foo/sg;

Adbot
ADBOT LOVES YOU

EVGA Longoria
Dec 25, 2005

Let's go exploring!

When did stat start returning an arrayref instead of an array? Cause every thing I can find on the internet says it'll return an array, but I have to reference before I can pull any thing out.

  • Locked thread