|
SpeedFrog posted:http://returnvalues.useperl.at/ Really, any number not 0 is true.
|
# ? Nov 19, 2008 20:33 |
|
|
# ? May 17, 2024 20:57 |
|
Aside, the string "0 but true" does what it says, and doesn't throw a warning when you use it as a number. $ perl -we "0+'0 foo'" Argument "0 foo" isn't numeric in addition (+) at -e line 1. $ perl -we "0+'0 but true'" $
|
# ? Nov 20, 2008 01:44 |
|
tef posted:Aside, the string "0 but true" does what it says, and doesn't throw a warning when you use it as a number. Any string would be true except for "" and "0"
|
# ? Nov 20, 2008 02:39 |
|
EVIR Gibson posted:Any string would be true except for "" and "0" Yes, but not every string can be used as a numerical zero without throwing a warning. That's what makes "0 but true" magic. Slightly irritatingly, you still get a warning from constructs like "1 but true" in a numeric context, so if you want a function that returns either false or a number which may or may not be zero, you have to jump through an extra hoop. Arguably, this may just be a crazy thing to want, but I've had it come up when trying to add features in the least painful way to old code.
|
# ? Nov 20, 2008 09:21 |
|
You can also use "0e0" as a true value without raising warnings.
|
# ? Nov 20, 2008 10:02 |
|
What does the following mean. I knew it had to do something with a key->value or perhaps a method but the second line I am not getting.code:
code:
EVIL Gibson fucked around with this message at 04:37 on Nov 21, 2008 |
# ? Nov 21, 2008 03:37 |
|
There's probably a syntax error on the second line. The first one means look up method "b" off of the object $a (etc regarding Perl's oop implementation). The second one written as $a->{b} means look up the value of key "b" in the hash that is referenced by $a (barring any discussion on bareword interpretation).
|
# ? Nov 21, 2008 03:59 |
|
code:
|
# ? Nov 21, 2008 15:55 |
|
EVIR Gibson posted:What does the following mean. I knew it had to do something with a key->value or perhaps a method but the second line I am not getting. The first one is a method call on a blessed object. The method called is "b", and the package this looked up under is the package that the object $a was blessed with. See the Method Invocation section of perlobj. The second one is accessing the key "b" from the hash reference $a.
|
# ? Nov 21, 2008 19:12 |
|
code:
(And in case anyone's wondering why i'm benchmarking this: This operation occurs 120000+ times in a loop that i'd optimally would like to crunch into 0.1 seconds.)
|
# ? Nov 21, 2008 22:10 |
|
I bet it's because Perl has to keep track of the value of $[, which controls the first index of an array. Then again, the perlvar doc says $[ has a compile-time effect. I'd still bet on it though. $#array is defined as the index of the last element of array @array, so must respect $[. scalar @array is defined as the number of elements in @array and can ignore $[.
|
# ? Nov 21, 2008 22:18 |
|
Never knew about that. Your explanation makes sense though, as perldoc only says it's *treated* as compile-time in respect to whether it affects other files or not.
|
# ? Nov 21, 2008 22:27 |
|
I want to state right off the bat that I'm not that experienced at perl scripting and I am sorry if I'm missing something obvious or trying to something that is actually dumb. So I'm writing a setuid script in perl that has input piped to it from another script. It needs to be setuid because the script that is piping input to it is going to be called by a variety of users. The setuid script then writes to log file that I don't want to be writable by everyone calling the first script. Since its setuid security and validation is a big concern. I've already got some pretty good regex to validate the content of the input, but I was wondering if I could take it a step further and validate the source of <STDIN>. Is there a way for a perl script to see whats piping input to it? Basically I want it to work so only a specific script is allowed to pipe input to the setuid script. Is this even possible?
|
# ? Nov 24, 2008 06:44 |
|
NeoHentaiMaster posted:Is there a way for a perl script to see whats piping input to it? If it's Linux, there's always searching /proc. /proc/$PID/fd/0 will be linked to a pipe -- use readlink to get the value. Find the other fd linked to that pipe in /proc, and you know what's feeding you input. There might be an easier and more portable way to do that, but I wouldn't know where to begin looking. You can also change it so the first thing sent by the calling script is a password of sorts. In order to pull that off, you'd need to make the calling script setuid, as well. For security, I'd recommend having the calling script disable core dumps, read the password out of a file readable only by the user it's setuid as, and then drop privileges. For disabling core dumps, you can use the BSD::Resource module or a wrapper for your script.
|
# ? Nov 24, 2008 14:58 |
|
Erasmus Darwin posted:If it's Linux, there's always searching /proc. /proc/$PID/fd/0 will be linked to a pipe -- use readlink to get the value. Find the other fd linked to that pipe in /proc, and you know what's feeding you input. Well, then you know the PID of what's feeding you input. Verifying the code that's feeding you input is significantly harder. Note that the process could be a completely legitimate program and memory space, but being straced by the user and fed malicious instructions to execute one-at-a-time, for example. Erasmus Darwin posted:You can also change it so the first thing sent by the calling script is a password of sorts. In order to pull that off, you'd need to make the calling script setuid, as well. Making the calling script setuid/setgid is the correct thing to do, but at that point simple permissions can be used to ensure that only it can access your backend. The way this would normally be setup is to have the logger program setuid root:loggergroup and only executeable by the loggergroup group, and the calling programs setgid root:loggergroup. That way the calling programs don't wind up running as root, and users can't interfere because permissions don't let them.
|
# ? Nov 24, 2008 18:15 |
|
Jeez, you guys try way too hard. I was going to post "barring any crazy workarounds, no, there's no easy or built-in way to determine where STDIN is coming from". But lo and behold, here are the technical workarounds.
|
# ? Nov 24, 2008 18:21 |
|
For those of you going to Frozen Perl (Triple Tech, you are, right?), I'm going to be giving two talks. My Devel::REPL/Carp::REPL talk was accepted, and now I'm also giving the Intro to Moose talk. It's going to be held in Minneapolis on Saturday, February 7th. If anything on the schedule piques your interest, come by and learn something!
|
# ? Nov 25, 2008 04:23 |
|
Thanks for the reminder. I'm scheduling YAPC NA and Frozen Perl on my calendar and I'll talk to my boss about it tomorrow. And I can't believe that dumb gently caress Steven Lembark is presenting. He unironically revels in being an awkward gently caress. He can't stay at one job because he's a terrible employee and his Perl sucks. I hope someone kills you with your Model M you goony waste of life.
|
# ? Nov 25, 2008 04:33 |
|
Lembark may be a dork but his Signal::StackTrace is handy. edit: I use it to find where my code is infinitely looping. A life saver every couple of months. Filburt Shellbach fucked around with this message at 04:44 on Nov 25, 2008 |
# ? Nov 25, 2008 04:39 |
|
So I am backticking a command and it isn't working. It doesn't die or return a null value, it just hangs and waits for a response - incredibly messed, especially since I can run the exact same command from the command line and it works. The method with the backticked command lives inside of a package. I recently moved the package from being in the .pl file my script utilizing the package is in into its own .pm file because it got large and I had other packages. The backticked command worked before, I'm not sure why it wouldn't now. It works if I copy and paste it to the command line and I'm really confused. Here's the offensive method(pardon the copious ugly logging, it's for debugging right now): code:
code:
If I execute that `/usr/bin/svn info --non-interactive https://mysvn.com/svn/some/path` on the command line, I get my expected output: code:
|
# ? Nov 25, 2008 23:51 |
|
This probably isn't related (but it couldn't hurt), try putting your debug flag into the log activity subroutine. Also, stick to simple scalars ($just $like $this) for interpolation. And then try again.
|
# ? Nov 25, 2008 23:55 |
|
Triple Tech posted:This probably isn't related (but it couldn't hurt), try putting your debug flag into the log activity subroutine. Also, stick to simple scalars ($just $like $this) for interpolation. And then try again. Nah, I have logs that should always occur regardless of if I'm in debug mode or not. A $self->log_debug method or similar would be appropriate, though. I'm pretty sure it's not the interpolation of the scalars because the first backticked command runs fine and I get its output in my log. edit: this what you mean?(logging truncated) code:
ashgromnies fucked around with this message at 00:05 on Nov 26, 2008 |
# ? Nov 26, 2008 00:01 |
|
ashgromnies posted:Nah, I have logs that should always occur regardless of if I'm in debug mode or not. A $self->log_debug method or similar would be appropriate, though. I'm pretty sure it's not the interpolation of the scalars because the first backticked command runs fine and I get its output in my log. What is the value of $svn and $checkout_path? Check that the user perl is running as can resolve and execute the command. If svn is really hanging, try attaching strace to the pid and see what is holding it up. Also, there are many subversion-related CPAN modules available.
|
# ? Nov 26, 2008 00:38 |
|
how do i get my program not to process -1 in my sort lists (ex. it always says -1 is the smallest number when -1 is the escape number) and print "No numbers to process if -1 is entered as the first entry only and not go through the sort lists?code:
|
# ? Nov 26, 2008 04:16 |
|
Double negatives kick rear end
|
# ? Nov 26, 2008 04:22 |
|
Consider a do while to avoid code duplication. Also, better whitespacing.
|
# ? Nov 26, 2008 04:28 |
|
Triple Tech posted:Consider a do while to avoid code duplication. Also, better whitespacing. code:
Voltaire fucked around with this message at 04:56 on Nov 26, 2008 |
# ? Nov 26, 2008 04:33 |
|
Voltaire posted:how do i get my program not to process -1 in my sort lists (ex. it always says -1 is the smallest number when -1 is the escape number) and print "No numbers to process if -1 is entered as the first entry only and not go through the sort lists? code:
|
# ? Nov 26, 2008 05:03 |
|
satest4 posted:
i got that to work sweet. now if the first entry is -1, the output should be No numbers to process. where should i insert this if statement? code:
|
# ? Nov 26, 2008 05:27 |
|
Are you loving kidding me? Go take a programming course, go read a book, anything. You're wasting our time with retard questions.
|
# ? Nov 26, 2008 05:28 |
|
satest4 posted:What is the value of $svn and $checkout_path? Check that the user perl is running as can resolve and execute the command. If svn is really hanging, try attaching strace to the pid and see what is holding it up. I printed the log above that shows that the backticked commands it tried executing were correct. I am running the script as the same user as I ran them from the command line with. code:
We have SVN::Client, I was recommended not to use it but I haven't looked into it. Is there anything you've used? I don't have strace on my Mac, I'll try running this on Linux tomorrow. ashgromnies fucked around with this message at 05:51 on Nov 26, 2008 |
# ? Nov 26, 2008 05:48 |
|
Sartak posted:Are you loving kidding me? code:
|
# ? Nov 26, 2008 05:49 |
|
I hope you get the job buddy
|
# ? Nov 26, 2008 05:52 |
|
Sartak posted:I hope you get the job buddy I already got the job buddy! These are just practice exercises i'm going through Voltaire fucked around with this message at 05:58 on Nov 26, 2008 |
# ? Nov 26, 2008 05:55 |
|
Voltaire posted:I already got the job buddy! I haven't tested this but it should work and looks more like perl. code:
Beardless Woman fucked around with this message at 06:36 on Nov 26, 2008 |
# ? Nov 26, 2008 06:31 |
|
ashgromnies posted:We have SVN::Client, I was recommended not to use it but I haven't looked into it. Is there anything you've used? When we used subversion, we'd get information directly from the repo (ie, on the filesystem), because it proved more reliable than using a client (and I avoid CPAN like the plague despite me suggesting it to you ). We switched to Git earlier this year. I like it a lot more than subversion.
|
# ? Nov 26, 2008 16:30 |
|
Voltaire posted:
For the love of christ. If you have the gall to ask people on the internet to solve your homework which the company (what company is it anyhow?) which gave you a Perl job despite you quite obviously just plain now knowing perl, then at the loving least run your poo poo through perltidy before posting it. It hurts my eyes just to look at it. [ http://search.cpan.org/~shancock/Perl-Tidy-20071205/bin/perltidy ]
|
# ? Nov 26, 2008 16:39 |
|
I'm glad you guys are taking a stand. Majority wins. Lrn2Perl.
|
# ? Nov 26, 2008 16:43 |
|
satest4 posted:When we used subversion, we'd get information directly from the repo (ie, on the filesystem), because it proved more reliable than using a client (and I avoid CPAN like the plague despite me suggesting it to you ). Yeah, we use Mercurial for actual development, Subversion is used only as a backend for a specific deployment management application(what I'm working on). Once we feature-freeze a release, we import it into Subversion and then have the ability to use the deployment management software to put it on any of our servers/environments. edit: hrm, ran it on Linux, same issue with the backtick exists, strace reveals a bunch of spam saying this: code:
editx2: So I'm pretty sure it has nothing to do with the backticked expression, it looks like an issue because I wasn't disabling buffering on my logfile so I thought it was halting somewhere that it wasn't... oops. ashgromnies fucked around with this message at 17:36 on Nov 26, 2008 |
# ? Nov 26, 2008 16:45 |
|
|
# ? May 17, 2024 20:57 |
|
Got another noob question. Once again I'm sorry if what I'm trying to do is just too advanced/complicated or not possible. Basically the situation is this. I have program1, script 1 and script 2. Program one calls script 1 and script 1 has the following code: open (HANDLE, "| /bin/script2"); print HANDLE stuff; close (HANDLE); Now, script2 takes the piped input and compares it to data in another log file to generate its output. The problem is that the log file data script2 needs is not available until script1 exits. Is there a way to make script1 just pipe information to script 2 and then continue on and exit while script2 continues to run? (basically have script2 wait for script 1 to exit so it can check the log file for new data) The way I have it now it seems script 1 always needs to wait for script 2 to exit before it exits. Any help or hints on what I need to at least look into as far as Perl goes will be greatly appreciated.
|
# ? Dec 1, 2008 00:34 |