|
11/23 |
2013/4/9-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Apps, Computer/SW/Languages/Perl] UID:54650 Activity:nil |
4/04 Is there a good way to diff 2 files that consist of columns of floating point numbers, such that it only tells me if there's a difference if the numbers on a given line differ by at least a given ratio? Say, 1%? \_ Use Excel. 1. Open foo.txt in Excel. It should convert all numbers to cells in column A. 2. Open bar.txt in Excel. Ditto. 3. Create a new file in Excel. 4. In cell A1 of the new file, enter this: =IF(foo.txt!A1=0, IF(bar.txt!A1=0, "same", "different"), IF(ABS((b\ ar.txt!A1-foo.txt!A1)/foo.txt!A1)<1%, "same", "different")) 5. Select cell A1. Hit Ctrl-C to copy. 6. Select the same number of cells as the number of cells that exist in foo.txt or bar.txt. Hit Ctrl-V to paste. 7. Hit Ctrl-F. In "Find what:", enter "different". In "Look in:", choose "Values". Click "Find All". Another way is to write a C program to read the two files using fscanf("%f") an do the arithmatic. \_ does this help? #!/usr/bin/python import sys threshold = float(sys.argv[3] if len(sys.argv) > 3 else 0.0000001) list1 = [float(v) for v in open(sys.argv[1]).readlines()] list2 = [float(v) for v in open(sys.argv[2]).readlines()] line = 1 for v1, v2 in zip(list1, list2): if abs((v1 - v2) / v1) >= threshold: print "Line %d different (%f != %f)" % (line, v1, v2) line += 1 \_ Something like this might work ($t is your threshold): $ perl -e '$t = 0.1 ; while (<>) { chomp($_); ($i,$j) = split(/ \t/, $_); if ($i > ((1+$t)*$j) || $i < ((1-$t)*j)) { print "$_\n"; }}' < file |
2012/12/18-2013/1/24 [Computer/SW/Languages/Perl] UID:54561 Activity:nil |
12/18 Happy 25th birthday Perl, and FUCK YOU Larry Wall for fucking up the computer science formalism that sets back compilers development back for at least a decade: http://techcrunch.com/2012/12/18/print-happy-25th-birthday-perl \_ I tried to learn Perl but was scared away by it. Maybe scripting lanauages have to be like that in order to work well? \_ I tried to learn Perl but was scared away by its incoherience. \_ I tried to learn Perl but was scared away by its incoherence. Maybe scripting languages have to be like that in order to work well? I don't know other scripting languages. \_ We laugh at Perl today and say it is the new COBOL, but to give credit, Perl came out at a time when awk/sed were the ways of doing things. People didn't know any better, and programming languages/compilers/parsers were not as formalized as it is now today. Try Python, it is a very elegant language that came out as a result of a lot of the earlier trial and error and undos a lot of the mistakes that earlier folks made. Python is VERY consistent (syntax, usage, etc) and very readable, so that 10000 developers can read and develop each other's code. Computers evolve. So do languages. \_ Part of this is just image. People hate perl now. People loved perl before. Python is cool now. Next it will be ruby or something else. All of these languages, whether FORTRAN, COBOL, C++, Java or Python do basically the same shit to an order of magnitude. \_ you are not a computer science major. Yes you are correct that all modern languages all perform the same computations and have the same power in the Chomsky Hierachy. They will however provide different features, most of them are time savings or productivity boosts. Features such as static typing and static analysis (bane of old dynamic languages) detects type errors BEFORE the program even runs (sorry Perl). Dynamic languages saves people time by not requiring a long dance (e.g. verbose Java/C declarations) so programmers can focus on coding instead of syntax. New languages have both features of dynamic and strong/static typing (e.g. Go, Scala) which allow programmers to code like dynamic languages AND allow the compilers to perform semantic analysis. Sorry again Perl (it is not even a language that can be described in a standard AST). Look, even old Java itself was a big thing as programmers no longer need to spend so much time worrying about memory management and debugging and monitoring stack trace and heap. Java provides faster time-to-market over C, just as Go/Scala/etc will provide faster time-to-market over Java. Don't discount future programming languages, runtime, and compilers. There will always be something better (sorry, Ruby is NOT better) and meta-productivity will always increase with further language research. BTW you are probably wondering how much productivity a higher level language provides. Read the Mythical Man-Month. It is provide concrete numbers. Read it. -CS, thesis in programming languages \_ I have a MS in CS from UCLA and I stand by my statement. Most of what you say is true, but it doesn't contradict anything I said. What language is "better" depends on a lot of variables. Note specifically that I am not claiming that FORTRAN, Perl, Java, and C++ are equivalent. Of course not. However, for solving certain classes of problems they certainly are. Further, sometimes some of the "advantages" aren't. There is definitely some element of a beauty contest when it comes to the "new, improved" language du jour. When all you have is a hammer, everything looks like a nail. I see this with freshouts all the time. \_ what is your thesis? What is UCLA's ranking? \_ Why don't you ask me how big my penis is? \_ Since you brought it up... \_ Are you hitting on me? \_ It depends on what your answer is. \_ compare scripting to scripting, and static typed compiled languages to static typed compiled languages. Any other comparison is apple & orange. Perl is a scripting language that can be easily replaced by any modern scripting language just as FORTRAN can be replaced by any C/C++ variants today. How many companies today still actively develop their products using COBAL? \_ What is your claim here? |
2011/11/2-8 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:54208 Activity:nil |
11/2 Celebrating fifty days of uptime! 00:16:58 up 50 days, 19 min, 13 users, load average: 1.00, 1.00, 1.00 \_ Thanks, jordan! \_ I would bitch about the 1, but it is not like anyone else is trying to do anything resource intensive with soda. \_ The culprit: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25757 edilaic 20 0 32088 4284 2052 R 100 0.1 21565:48 perl \_ Yeah I saw that too, but it is not like he is slowing anyone else down. This is some kind of irc bot, right? \_ rodney on irc.csua/#hosers -- it announces nethack deaths. |
2011/1/19-2/19 [Computer/SW/Languages/Perl] UID:54012 Activity:nil |
1/19 Perl god, please go to http://perldoc.perl.org/perlre.html Go to "Quantifiers" and the greedy operator, such as +?, *?, ??, {n,}?, {n,m}? So I understand the greedy operator that does matching based on having different choices (instead of the default maximal munch). What about "{n}?" ? What are some examples of using "{n}?" ? \_ s{2,} will match "ssss" once. s{2,}? will match it twice. \_ that is clear. s{n,} and s{n,m} will match between n to m number of s. Traditionally regex is maximal munch. However the "?" minimal munch operator such as s{n,m}? will perform minimal munch. My question is, if you have just s{n} and you match exactly n number of s, then what is the point of the minimal match, given that there is no choice? \_ It's just for consistency. s{n} and s{n}? are identical. \_ ^consistency^redundancy ^consistency^stupidity Perl programmers are like Republicans-- righteous, unapologetic, and incapable of seeing the point of view from other languages. \_ How would you design it? If s{2,3}? is legal but s{2,2}? is an error, then s{$min,$max}? will fail if $min and $max happen to be equal. That seems suboptimal. \_ "$_Wha???" lol |
2010/12/11-2011/2/19 [Computer/SW/Languages/Perl] UID:53984 Activity:nil |
12/11 Anyone have experience with Perl PDF::API2 or PDF::API3? Can you point me to a good tutorial for creating a simple document (a small table of 2-3 rows and a single image)? |
2010/8/12-9/7 [Computer/SW/Languages/Perl] UID:53922 Activity:nil |
8/12 Ruby coders, do you mostly DIY your stuff or use the ruby libs out there? How is their quality compared to other libs you have used for other langs? Thx. \_ I use Ruby for hobby stuff, etc. I use libraries for system stuff (web access, process, etc.) but that's about it. Perl libraries are much better/more complete. I assume because of the maturity and size of the community. \_ I've found the quality of ruby libs to be lower than perl, which also often has quality issues. The plus side is reading the ruby code to figure out wtf is going on is easier than reading perl, imo \_ what do either of you think of python libs by comparison (speaking of readability)? \_ python is quite mature and the programmers that use it tend to be much higher quality than ruby. ruby programmers, on average, are just slightly above average php programmers, which isn't a very good bar to begin with. \_ I've looked around with some libraries, most of which give me the feeling that you are right, from their code base, they seem to have been made for "grab that low hanging fruit for mindshare" - it's the dancing bear problem of software. Mostly written by yeah college kids or highschoolers. Reminds me of MySQL codebase. Which I guess is where most of these people are from... \_ dancing bear? \_ You don't grade the bear on its routine, you are jus amazed it dances at all. |
2009/8/18-9/1 [Computer/SW/Database, Computer/SW/Languages/Perl] UID:53283 Activity:low |
8/18 trying to write an intentionally slow regex. what is your worst regex ever? this is using MySQL regexp but I'll also accept perl format --brain \_ you need to know how regex is implemented internally in order to have a worst regex in terms of running time. Something that uses a decent hash table that fit in L1 cache will be fast regardless. Lexical analysis with a hash lookup of constant time will be linear (to the length of input). NFA->DFA. Are you not a CS major? \_ rather than responding to trolls: yes, I specified MySQL for a reason: The inherent linear nature of most regex engines is what makes the problem challenging. Soliciting for ideas, not a lecture on how regex works; remember I went to Cal too. Although if you know how the MySQL regexp works, I'll take anything you got! --brain \_ Sorry but I don't think you're a CS major. \_ Is the OP even aware of DFA vs NFA/traditional NFA/posix as a start? \_ What is a MySQL regexp? You should look up the Qadafi/Khada'ffi regexp. \_ There are some fairly ugly regexps built into procmail for things like FROM_DAEMON, and there's some ~6K regexp for fully validating email addresses (may be in the RFC). These are big, but not necessarily slow. If MySQL doesn't precompile its regexes, and it supports extended regexes, you can do stuff with nested ranges: (.{1,100}){1,100} Perl regex for RFC822 validation: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html |
2009/6/2-5 [Computer/SW/Languages/Java, Computer/SW/Languages/Perl] UID:53072 Activity:nil |
6/2 http://gmarceau.qc.ca/blog/2009/05/speed-size-and-dependability-of.html Ruby sucks. \_ Looks no different than python/perl/etc. It's a scripting language that needs a virtual machine if it is ever going to be fast. The scary thing is how much modern computing doesn't need stuff to be fast, especially when dealing with web applications. There's also a big problem with that shootout; there's no concept of how your average coder will do in language x. Some languages are amazingly powerful, and if you know what you are doing you can write good, terse, fast code, but if you put an average engineer down and teach them the language they will write unmaintainable garbage that noone can read (even after years of experiance). That's what dependability really means. \_ As above, if Ruby sucks here then so do Python and Perl. |
2009/5/6-14 [Computer/SW/Languages/Perl, Computer/SW/Languages/Web] UID:52961 Activity:kinda low |
5/6 I'm sure you've seen web sites that distribute software by making a user fill out a form and then e-mailing the user a randomly generate link to the software that works just once. What software is used to do this? I'd like to distribute software in such a way. \_ "Software"? What web server/web application environment are you using? \_ Yes, software. Like let's say I have a software package I am distributing and it's a tar.gz. Right now people just download it, but I'd like to use one of these more sophisticated systems to track who downloads it and give them a link that works just once. I can use whatever web server or environment will do the job. \_ Uck. Those types of links suck. Please don't. \_ What sucks about it? I never had any issues with these. It is not acceptable to publish a publically accessible link, so what do you suggest instead? \_ I've never downloaded softward this way, but I have downloaded a secured copy of my tax return from my CPA this way. They use something from LeapFILE. -- yuen \_ I'll look into it, thanks. Any other suggestions? I am surprised most of you have never dealt with this. It's really common when downloading commercial software like compilers and such. \_ It's something I could build in an afternoon, and by doing it myself it would be a lot easier to integrate with all my existing deployments. Sometimes it's just easier to write it yourself. \_ It's usually a lot more trouble to write it yourself. Then you get to maintain it, too. These hacks are always simple upfront and evolve into headaches later. Seems a lot of people use PHP + MySQL for this and continually reinvent the wheel, which I think is silly. A perl module sounds like a good idea. It's also a lot of baggage for something so simple. I need to install a *database* and a scripting language just for this? Just installing PHP will probably get me hacked. \_ Gee, you already have a scripting language, it's called perl. You are going to need a database of some sort no matter what. (It doesn't need to be mysql or a relational database, but you are going to need some sort of data store.) A perl module doesn't make sense. If (token in store) then (remove token and serve application). How hard is that to write? \_ perl module makes a lot more sense than PHP to me. You also don't really need a database of any kind. Why for? You can do fancier things with a DB, but it's not really needed. All you need is to be able to do is generate a random URL and keep some counters. It's not a matter of "how hard is that to write" as it is that I'd rather spend $50 for an app to do this than spend $100/hour for a developer to write and maintain this, even if he spends just 10 hours/year on it. \_ Because you are forgetting the time to install/set up the damn app in the first place. That takes time too. \_ Yes and it will have to be setup and installed no matter if I write it or buy it. So that's a wash. \_ curious, why go to the trouble? What's to stop someone from replublishing the software on their torrent site of choice, unless you're also watermarking the software image, ni effect customizing the copy for the downloader ? \_ CYA. If someone else publishes it then they are the ones that will go to jail. Whereas, if I publish it to the world then it will be me in jail. \_ There's a legal aspect to it. If I have a one-time link, I can make sure you only get the software after you've agreed to my license agreement. If you can download the software without clicking through the license, you can argue that you're not bound by the license. \_ You might also want to avoid people being able to "deep link" to the software, thereby depriving you of ad revenue. The place I work for is in this situation. \_ He wants to collect email addresses. |
2009/1/14-22 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:52378 Activity:nil |
1/13 I want to extract a couple integer from an xml file, mainly, xml file from http://weather.com so I can put it on my xplanet marker file. has anyone done similar things (parse and extract data from xml) using shell script instead of python/perl? in the world of perl, it make sense to dump things into a hash which i can easily extract key/value pair. can i achieve similar things with xmllint/xmlcatalog? thanks \_ xmlstarlet lets you do xpath/xslt stuff via the command line \_ didn't know this existed... Thanks \_ thanks again for telling me about xmlstarlet. this is wonderful and easy to use tool. |
2009/1/7-12 [Computer/SW/Languages/Java, Computer/SW/Languages/Perl] UID:52334 Activity:nil |
1/8 I have several old CS books that I want to get rid of, just in time for the new semester. If someone from the CSUA wants to pick them up for the CSUA library or for themselves, contact me. I don't have a list handy but they include the dinosaur book, dragon book, some crappy EECS122 networking book, an intro to Java book that was used in 61B, and a few others. I'm keeping my Programming Perl book but might get rid of K&R ANSI C as well. --abe \_ More books for our library! You're in Cupertino, right? I wonder if Steven might be close enough to pick them up. He may already be back in Berkeley, though. --t \_ work in Cupertino, live in SF (Haight/Ashbury). Here's what I could find (I have another box of maybes somewhere, includes an^H^Hthe ANSI C book and Design Patterns): computer networks 1558603689 java language specification 0201634511 java how to program 0132634015 operating system concepts "dinosaur" 0201591138 DBMS 0070507759 \_ If you'd like me to pick stuff up, I can come to Cupertino. Email vp@csua if so inclined. |
2008/11/26-29 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Perl] UID:52111 Activity:nil |
11/25 Yargh! They sank the wrong pirate ship! http://news.yahoo.com/s/ap/20081126/ap_on_re_as/as_piracy_1 \_ Oh shit! \_ duh, work with indian java monkeys sometime. \_ That's stereotyping! Other language (C, C++, Perl, etc.) monkeys are also the same. \_ The boat was taken over by pirates! Now no one needs to worry about paying ransom. Why didn't they think of this earlier? Oil prices and environmental awareness are too low as it is. Fire away! |
11/23 |
2008/7/14-16 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:50557 Activity:moderate |
7/14 Shell Programming question: I want to call a script with 1 arg and have it figure out whether $1 is a MAC address or an IP address and then do call the appropriate function. What is the best way to do this, given that sh/bash/ksh do not have something like the =~ in perl. Check for exit status of grep, or is there a a better way? For the moment, let's just say the two tests are: echo $1 | fgrep : > /dev/null && echo isMAC || echo notMAC echo $1 | fgrep . > /dev/null && echo isIP || echo notIP and if neither, then Usage() I want to avoid requiring the user to either do "-i IP" or "-m MAC". Note: this doesn't have to do extensive syntax checking ... it's not a security application. Just trying to save typing. \_ You may want to recheck your assumption of bash not having =~. \_ Thanks for that information. I didn't know know about that. Although right now it is in sh. Any portable pure sh ideas? I'm really interested in what is the "right" way to do this, rather than just coming up with something which works. \_ "right" depends on your situation. If you actually need to support old systems, or be portable across many systems, then maybe you should stick with sh. If you know your audience is all going to have bash or whatever (and that is not at all unlikely these days), then I see no good reason to suffer under older, less capable tools. \_ Dude, it's a sh script. If it works, it works. Seriously. Stick it in a function if it looks too ugly and then forget about it. If you need something to be maintainable or it's a called enough there is any concern about it being too slow you are going to have to bite the bullet and use a reasonable scripting language. Otherwise just make it work and move on to something that is worth spending time on. \_ I think "right" in this case, means readable and maintainable by the next poor guy that has to come along. Just document your code and you will be fine. \- I think one way to distill the question is "how do i get =~ in sh" ... would you do "echo $string | egrep <regexp>" + $? to get exit status of the grep ... I think the case approach below is nice and clean as long as you are ok with something like *:*:*:*:*:* for MACs and *.*.*.* for IPs, and dont need "true" regexps. "true" regexps. I wouldnt use awk to test, but maybe if you need to mangle. \_ Why would you do this in a shell progam? \_ use case: found="NO" case "$1" in *:*) echo "isMAC"; found="YES";; *.*) echo "isIP"; found="YES";; *) if [ "$found" = "NO" ] ; then echo "NOT MAC" ; echo "NOT IP"; fi ;; esac |
2008/6/18-22 [Computer/SW/Languages/Perl] UID:50292 Activity:nil |
6/18 Anyone reccomend a simple way in perl to detect an animated gif? |
2008/5/28-31 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:50069 Activity:nil |
5/28 dreamhost tells customers to quit complaining about email and just use gmail http://www.informationweek.com/blog/main/archives/2008/05/huge_web_hostin.html \_ search for dreamhost on motd. sucky suck. \_ http://csua.com/?entry=45409 http://csua.com/?entry=45383 |
2008/4/29-5/5 [Computer/SW/Languages/Perl, Computer/SW/Languages/Python] UID:49852 Activity:moderate |
4/29 Scaling your web app in the real world: http://teddziuba.com/2008/04/im-going-to-scale-my-foot-up-y.html \_ This article is crap. While yes, 99.9% of all websites don't need any serious scalability plans, if any of them become worth anything they will need to scale. If you write a web application without careing about scalability you are writing a webapp that can never be more than niche. Any developer should know where the next few scaling bottlenecks live in his application and have some basic plan for how to solve them when they become an issue. \_ I feel the same way about language Nazis. "Java is the best!" "No C is the best!" "Perl sucks it's not readable!" "Python rules!" Dumb asses blame the language and not the stupid programmers. \_ Different tools for different jobs. That said, I particularly like python. Its syntax is very clean. \_ I don't know python. I like Pascal the best, although I haven't used it in 18 years. \_ If you liked Pascal, you will love python, unless you get hung up on the fact that blocks in python are defined by indentation rather than by "begin/end" \_ Yeah, I like python, but that blocks by indentation thing drives me up the wall. Couldn't they at least make it optional? -!pp \_ My experience is that Ruby is a lot cleaner than Python, and doesn't have stupid syntactical whitespace. However, I have only used Perl for stuff at jobs etc due to familiarity. Python's object orientedness was less complete than Ruby's and I definitely don't like the indentation thing. \_ I struggled, trying to like Python. Then I found Ruby and it's the most fun I've had programming in a *long* time. The fact that regexes are as easy as Perl in Ruby was a big deal. \_ Ruby is whitespace sensitive. -- ilyas \_ Far less so than Python. \_ I am not a huge python fan, and I don't like python's whitespace indentation, but I found ruby's specific whitespace sensitivity far more confusing. -- ilyas \_ Interesting, I've never noticed a problem. \_ Perhaps this is because you are not used to programming with closures (blocks are the closest thing in ruby to closures). Ruby blocks have very odd whitespace requirements: (1..3).each {|x| puts x} works (1..3).each {|x| puts x} works (1..3).each {|x| puts x} does not work. -- ilyas \_ No, I use closures, just never have had to break across the line. \_ I write fairly hairy closures sometimes, and often my closure code is nested. I find this behavior completely bizarre and unintuitive. I can't even imagine why Ruby would insist on this. -- ilyas \_ I got yer hairy closure right here, pal. \_ This is funny, but not really applicable to real world scaling. I have been doing this stuff for 15 years and scaling is more of a system architecture and capacity planning issue than a developer issue. Of course, if your code is bad enough, no one can make it scale. \_ I disagree completely. I've taken courses on optimizing applications for performance and the best bang for the buck is almost always received by altering the code to run faster. Sure, things like high-speed interconnects to reduce latency can solve problems not easily solved by modifying code, but the majority of problems are developer issues that they (I would say unknowingly, but maybe because they don't care) foist upon the systems people. \_ Most cases of performance scaling problems I have encountered have been due to the volume of data being written to disk. These problems can be fixed by using the right RAID type, better use of filesystem caching, a better filesystem, or most often, simply by throwing more disks at the problem. These are not the kinds of issues I would expect a programmer to know or even care too much about. I haven't "taken courses" on it, but I have worked on numerous overloaded web and application sites in the Real World. \_ Sounds like you have haven't encountered a large variety of problems then. Often when a developer profiles his code he can find all sorts of bottlenecks. Often it seems easier to throw h/w at problems, but the biggest gains come from writing better code. For instance, don't write so much data to disk or be smarter about how you do it. You are correct that programmers don't know and care about these issues, but they should. They usually only care when they are forced to because their code doesn't meet requirements, because it compares unfavorably to competing code, or because the hardware solution has failed or is too costly to implement. \_ "In nearly every case the most serious bottleneck is an overloaded or slow disk." -Adrian Cockcroft Sun_Performance_And_Tuning (Ch 1, Paragraph 1) \_ You ever wondered why Google search is so fast? They have the world's largest RAM disk. They index and keep most of their search data ***IN MEMORY***. Last time I attended a talk I learned that they have more a shitload more RAM than many corporations have on disk. It is ridiculous. \_ Thanks for making my point. \_ Well no shit, but this is tangential. The question isn't "Is disk slower than RAM?". It question isn't "Is disk faster than RAM?". It is "Is there a way to do this such that it doesn't write to disk as much?" One example is when developers decide to write 6 million small files in one directory and the filesystem bogs down. Sure, you can buy a faster filesystem but that's correcting the symptom and not the problem. You don't need to buy $$$ hardware that probably still can't handle that particular issue if the code didn't do something so stupid. \_ I heard reiserfs is really good at storing lots of little files. \_ I heard reiserfs is really good at storing lots of little files. \_ unfortunately, it stores them in a dumpster in San Leandro. \- lexis/nexis was pretty fast at seearch +20 yrs go. the old bell labs people [who after all were working for a phone company] have lots of interesting stories about optimizations for various phone company applications. one of the main altavista people wrote some code to use a cache that was physically closer to a processing unit to avoid die-crossing latency [and had numbers to show the difference it made]. google is mostly read data and it's not authoritative but a cache/copy for much. contrast this with say ebay. for a somewhat interesting discussion of scaling look at randy shoup's presentation/talk on ebay scaling. [trivia: randy was a high school acquaintance of mine. i thought he was going to become a lawyer and i was mighty surprised he went into cs/ databases]. \_ Getting all your caches right is not really a developer responsibility, but I admit that it starts to cross disciplines. Most people are just sort of confused how it works, so in this case, the one eyed man is king. \_ Whose responsibility do you think it is if not the developer? If he doesn't have the knowledge then he needs to consult with someone who does, but he's the implementer. Too often the developer has no idea, doesn't ask anyone, and implements something stupid. \_ I guess I would have to say that it is a shared responsibility between the system architect and the developers. A lot of times developers don't know what is possible, especially what is possible at a reasonable price point. How big a RAM disk cache can you expect to have available for your application in a shared disk array? How would a developer hope to possibly know that? But far too often system administrator types don't share this kind of info, even if they do know it themselves. \_ I would argue that developers should know what they don't know - or at least consider these issues early (before they become a problem). Part of the problem is that people with systems knowledge often come into the project late in the development of it - too late to make major changes. We see this problem in spacecraft operations. The hardware guys build a shiny new spacecraft without consulting with the people who are going to fly it. They make "sound technical decisions" and h/w design decisions that are intended to save lots of money, but they have no knowledge (or, worse, just enough to hang themselves) about how to operate the h/w they build. This often ends up being a case of saving $$ on the h/w and spending $$$$ on the operations (or not being able to operate at all - or with greatly increased risk). The *good* h/w guys know who to involve early in the process and why, but they are a small minority even in large, experienced companies like Lockheed. With scaled systems it's rather the opposite. The s/w guys design and build a system without considering h/w (or the systems environment). \_ I had that exact problem at one place (millions of files in one directory). We talked about various ways to fix this and decided that switching from WAFL to VxFS was the best solution. In some ways this was just because the developers were too lazy to figure out how to use a database, but it worked. \_ Why not spread those millions of files over many directories? In itself that helps a lot and it's a simple fix. A database is another idea. Switching filesystems sounds pretty drastic to me. \_ It was already hashed, so what we really had was billions of files, millions in each directory. There is no magic bullet for dealing with that quantity of data. Millions of directories is not really a good solution either, for reasons that should be obvious. By the time I left the company, they had started work on what was essentially their own filesystem but I don't know what happened to that project. \_ What a disaster. This sounds like poor s/w design. \_ All that because the devs don't want to figure out how to use a db? \_ Yeah, well it was 1999 and good developers (or sysadmins) were hard to come by. The new filesystem I was referring to had a DB included. \_ You think they are easier to come by now? If anything, it seems to be getting worse as a lot of Microsoft-trained, Java-loving weenies have entered the field and very few hardcore assembler-loving PDP-11 weenies still exist. Over time it seems the average developer/sysadmin knows less and less about the details of the systems in favor of high-level constructs like WWW and GUI design. There's a place for both, of course, but I am horrified by what recent CS grads do not know. \- I disagree as well. Some simple problems are solved by throwing money at them ... say $20k - $100k problems. But at some point programmer time does become cheaper than cycles, space etc. And there are other cases where the best hardware cant do what brainpower can. Trivial example are new crypto attacks. Another case is reading 10gb traffic streams... you cant just naively throw hardware at the problem. It's combination of hardware [ASIC, FPGA other specialized network devices], OS/kernel/devce driver hackery, and application design. \_ Any network with 10gb of traffic on it that cannot be easily broken up is not scalable. \- what you control may affect your options. we want to do IDS on 10G. We cant tell say ESNet to tailor bandwidth provisioning around IDS. What we can ask for is $ for hardware as long as we're not being stupid about it. The "web application scaling" is a different problem than some other scaling issues ... something like the LHC has different scaling issues, for example. |
2008/3/4-7 [Computer/Networking, Computer/SW/Languages/Perl] UID:49324 Activity:moderate |
3/4 Does anybody have some code or know of a program that will take a network/mask and return the list of address in that CIDR block? e.g. "iplist 10.10.10.0/24" and return 10.10.10.0 ... 10.10.10.255 [I have a way to do this, but it involves distributing a large amount of code, which is kind of a hassle. Looking for something lightweight and either standard or easdy to rpm/port/yum install.] \_ shouldn't be hard to do, its all bitwise binary math. \_ Because I was interested in how to do it in perl, I hacked up some quick code. ~mehlhaff/netmask.pl for your enjoyment. -ERic \_ there are couple out there. The one I settled on is sipcalc \_ Thanks for the pointer. I only knew about the "builtin" ipcalc. I see sipcalc return the "usable range" in the form 10.10.10.1 - 10.10.10.254. Is there a way to get it to return each of the 254 addresses, one per line, which can be piped to another program's stdin etc. \_ doing it in perl? Net::IP http://search.cpan.org/dist/Net-IP/IP.pm \_ doing it in perl? Net::IP http://search.cpan.org/dist/Net-IP/IP.pm \_ look at nmap code \- i thought the nmap code was somewhat hard to understand [this was maybe 2yrs ago]. however, you can steal this exact function and parser from a modern version of fping which supports the "-g" flag. nevertheless, i'd be interested in a real standalone untility for this. starting with fping, this is do-able in like 30min [you can also do it in 2 lines if you want to do this in a stupid but perfectly workable way]. it would take me a lot longer to extract this from nmap. --psb ./fping-psb -n -g 10.10.10.0 10.10.10.56 | wc -l 57 ./fping-psb -n -g 10.10.10.0/30 | wc -l 4 \_ I wrote a script last year that basically produces the same output as psb's solution. My perl vs. mehlhaff's perl. Round 1: Fight! ~dbushong/bin/expand-ip-range --dbushong \_ dbushong is definitely sexier than mehlhaff. meh! \_ Hah, oops. Mine only expands the last two octets. (i.e. doesn't do anything useful for /n where n < 16) Ah well. --dbushong \_ clever code vs. simple code w/comments. Two very different styles to accomplish the similar things. It is left as a exercise to the student to decide which they like better. -ERic |
2008/2/11-14 [Politics/Domestic/President/Clinton, Computer/SW/Languages/Perl] UID:49115 Activity:nil |
2/11 Clinton's campaign manager replaced with a perl script. News at 11. |
2008/1/14-18 [Computer/SW/Languages/Perl] UID:48942 Activity:nil |
1/14 My perl foo is weak. What's a simple elegant way to write the content of $result to the file $filename? Thanks! \_ open(FILE,">$filename");print FILE $result;close FILE; -tom \_ Added a $ in the right spot \_ Depending on what you're doing: perl's print default to STDOUT, so you can also just print $result; and then run your script from the command line as: foo.pl > file. When doing the open() you also probably want to test that the open succeeded. You may not have perms on the file, you may have typod the path, etc. \_ Dependin on how complex $result is you can also do shell escapes in perl. I.e. system "echo $result >> $filename"; \_ Not exactly elegant when the real solution fits in about 1/2 again as many characters. |
2007/10/22-25 [Computer/SW/Languages/Perl] UID:48415 Activity:nil |
10/22 I want a perl regex that reduces 2 or more consecutive newlines to 2 newlines. perl -pe 's/\n\n(\n*)/\n\n/gms' doesn't work, and I don't understand why. Any ideas? \_ You're reading your input one line at a time. Try this: perl -0pe 's/\n\n+/\n\n/g' --mconst \_ Are they just \n's or are they \n\r's? |
2007/10/20-24 [Computer/SW/Languages/Perl, Recreation/Pets, Computer/SW/Languages/Misc] UID:48397 Activity:nil |
10/19 I'm the op who threatened to delete dog posts using my super script. I didn't actually write one, but I did trick you guys into posting dog shit amonst others. Boy, that was fun!!! \_ POODLE! (super script? It's a few lines of perl... ARF!) Maybe you need a nice lab: someone who can keep up with you. |
2007/9/23-24 [Computer/SW/Languages/Perl, Computer/SW/WWW/Server, Computer/SW/Languages/Web] UID:48152 Activity:kinda low |
9/23 I have an Apache question: If I have a directory which allows both CGI handler and Perl handler (mod_perl) how can I tell which is being invoked by the web server? The scripts are being executed, but I have no idea if mod_perl is running correctly or if the CGI Handler is just picking them up and running them. How can I tell? \_ If you like wasteful suburban living, chances are you don't need to know if they're running. They're all magically taken care of by other tax payers, like freeways and support systems for your big suburban mansion. \_ http://modperlbook.org/html/3-10-How-Can-I-Tell-if-mod_perl-Is-Running.html \_ http://urltea.com/1khw (modperlbook.org) Also you're supposed to get a 50X performance difference so try out a bunch of your own DoS clients and see the latency or something. \_ http://www.perlmonks.org/?node_id=377648 Check the http header! Look for: HTTP/1.1 200 OK Date: Tue, 27 Jul 2004 07:10:54 GMT Server: Apache/2.0.48 (Unix) mod_perl/1.99_13 Perl/v5.8.0 PHP/4.3.5 <=== !!! ... \_ I do not think this is valid for RHEL, which loads mod_perl as a .so. Certainly my server does not say this and yet it certainly does not complain when it loads the module. RHEL installs apache as an RPM and mod_perl as another RPM, so I don't think the apache ID string reflects reality. My question is not really "Is mod_perl installed?". I am sure it is. The question is "How do I know that my configuration is working the way I want it to, with mod_perl handling the .pl scripts instead of .cgi?" |
2007/9/18-22 [Computer/SW/Languages/Perl] UID:48097 Activity:nil |
9/18 What does "qq/.../" in Perl mean? I don't want to ask my "leet" stuck up co-workers because they'll think I'm an idiot. Well maybe it's already too late but whatever. ok thx. \_ 2 q's mean same thing as double-quote. Now for the bonus question: what does "q/.../" mean? \_ Please don't do other people's homework. \_ Why not? We're old. \_ man perlop |
2007/9/10 [Computer/SW/Languages/Perl] UID:47986 Activity:low |
9/10 Hi. I'm running a package based linux distro. Should I install perl CPAN modules through the provided packages, or through sudo cpan> install modulename etc ? Opinions? \_ Depends on the package system you're using, you may have to deal with both. I had an experience where I installed via CPAN because the packaged version was older than what I needed. Later, I installed an RPM via yum that installed the CPAN module package, causing it to be downgraded and breaking my app. |
2007/8/24-27 [Computer/SW/Languages/Perl] UID:47746 Activity:nil |
8/24 perl 5 slash fiction: http://tinyurl.com/2ouhb2 |
2007/8/22 [Computer/SW/Languages/Perl] UID:47707 Activity:nil |
#!/usr/local/bin/perl of choices out there with different tradeoffs. of choices o\ ut there with different tradeoffs. |
2007/8/20 [Computer/SW/Languages/Perl] UID:47665 Activity:nil |
#!/usr/bin/perl Oakland police put the main suspect in the killing of a journalist investigating\ Your Black Muslim Bakery in an interrogation room with the bakery's leader afte\ r the two were arrested, then left them alone and didn't record the conversation\ , sources close to the case said Friday. |
2007/8/13-15 [Computer/SW/Languages/Perl] UID:47608 Activity:very high |
8/13 Is there a unix command to print the full filesystem path of something? e.g. % pwd /home/troll % print-full-path drivel /home/troll/drivel \_ function print-full-path { (cd "$1"; pwd); } Implementation as a csh alias left as an exercise. \_ that doesn't work... $1 could be a file \_ You need something like: FDIR=`dirname "$relpath"` FBASE=`basename "$relpath"` FABS="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B" \_ christ. ok the answer is "no, you need a script". \_ which foo \_ Ok here's my little perl script for this, if anyone cares. -op \_ locate foo whereis foo find `pwd` -name foo -maxdepth 1 echo `pwd`/foo \_ that last thing would work but I wanted symbolic links \_ `pwd`/foo would work but I wanted symbolic links and relative paths converted to absolute paths. The others don't work in general. \_ Here's my perl script for this, if anyone cares. -op #!/usr/bin/perl chop($cwd = `pwd`); foreach $arg (@ARGV) { chdir $cwd; chop($rel = `dirname $arg`); chop($base = `basename $arg`); chdir $rel || die "path not found: $rel\n"; chop($full = `pwd`); print $full; print "/" if ($full ne "/"); print $base if ($base ne "/"); print "\n"; } \_ Look up chomp() as a chop() replacement for removing \n. |
2007/8/7-13 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:47555 Activity:nil |
8/7 I'm trying to figure out whether it's possible for get wget to authenticate to a web page protected by a login form ('post' method to send username/pass, and cookies.) Cookies don't seem to be the problem, with --save-cookies and --keep-session-cookies but getting the username/password submitted isn't doing it. On this particular page, getting to a link, let's say 'example.aspx', redirects to 'login.aspx?href=/example.aspx'; login.aspx is a standard http form. Anyone ever get this working? -John \_ You want a single wget command or are you scripting this? If scripting just hit the logon page first to get your cookie. Otherwise you have to recognize you've been redirected. \_ Why wget? Have you tried curl? \_ I've been able to get this working using wget's CLI options --user=[user] and --password=[passwd] or by posting the right form elements for authentication. \_ Yeah tried both, no good. Curl sounds like it might work, though. Thanks. -John \_ If curl doesn't work for you, I've done this in perl before. It isn't that hard with cpan's lwp, cookie libraries, etc. \_ Or if you hate Perl, Ruby does a good job too. \_ Curl works for submitting the credentials, but I'm having trouble with cookies; the site issues 4 for a normal browser login, but with curl I only get one. I'll keep plugging. -John \_ How can you hate perl for a hack script like this? |
2007/8/1 [Computer/SW/Unix, Computer/SW/Languages/Perl] UID:47500 Activity:high |
8/1 perl/sed/awk/etc question: Is there a good way to change every other delimiter or string match? For example change a colon delimited list to a :+, one... Apple:12:Pear:2:Orange:9:Plum:7:Banana:22:Mango:2 to Apple:12,Pear:2,Orange:9,Plum:7,Banana:22,Mango:2 (And I dont mean a trick that relies on some fields being alpha and some numeric or only a known number of fields). \_ How 'bout the straightforward approach s/([^:]+:[^:]+):/$1,/g \_ That didn't work?! Am I doing something wrong? echo Apple:12:Pear:2:Orange:9 |sed -e 's/([^:]+:[^:]+):/$1,/g' Apple:12:Pear:2:Orange:9 \_ use perl, sed will kill you with quoting. \_ Thanks! perl -pe ... does it! \_ One more question, why is there a differene between : and |? I now need to use |. echo "Prog 1:61.3:Ch 2:91.0:Num3:83.4" |perl -pe 's/([^:]+:[^:]+):/$1,/g' Prog 1:61.3,Ch 2:91.0,Num3:83.4 echo "Prog 1|61.3|Ch 2|91.0|Num3|83.4" |perl -pe 's/([^|]+|[^|]+)|/$1,/g' Prog 1,,|61.3,,|Ch 2,,|91.0,,|Num3,,|83.4 First one works. Second does not. \_ man perlre, search for | |
2007/7/31 [Computer/SW/Languages/Perl] UID:47482 Activity:nil |
7/27 I just wrote a perl script to delete your puppy bullshit |
2007/7/6 [Computer/SW/Unix, Computer/SW/Languages/Perl] UID:47196 Activity:high |
7/6 my google fu is weak. How do I match EOF ( tr or perl or sed or any linux tool that will do substitutions in a file)? thanks. \_ What are you trying to do? |
2007/6/15-16 [Computer/SW/Languages/Perl] UID:46958 Activity:nil |
6/15 Haha - Perl using Vista voice recognition http://tinyurl.com/2td2y3 -John |
2007/5/1-4 [Computer/SW/Languages/Perl] UID:46497 Activity:nil |
5/1 Oops, Tenet's a big fat liar. He claims that he ran into Perle the day after 9/11 and Perle said that Iraq had to pay. Problem is, Perle was out of the country and couldn't get back until 9/15 http://weeklystandard.com/Content/Public/Articles/000/000/013/593daqmw.asp \_ Do you think Perle didn't say that? http://thinkprogress.org/2007/04/30/perle-five-days-after Is Tenet a liar and Gonzales not? Is Tenet a liar and Gonzales not? -scotsman \_ There's a difference between saying "Iraq has to pay for what happened yesterday" and saying "there are links between OBL and SH". Oh, and Gonzales is either a liar or an incompetent. -op \_ So, again, you don't think "Iraq has to pay for this" or something very close came out of Perle's mouth in Tenet's presence? Also, as those "links" were included in the authorization to attack Iraq, do you honestly think you can call that a distinction with a difference? Also: http://edition.cnn.com/TRANSCRIPTS/0109/16/en.00.html Let's look at the full transcript. Even if we cannot prove to the standards that we enjoy in our own civil society that they were involved. We do know, for example, that Saddam Hussein has ties to Osama bin Laden. That can be documented. So, on the theory, which seems to be a valid one, that if you support terrorists and they then commit atrocities against Americans, you are responsible. Unless we hold those countries responsible, we will be chasing terrorists without significant effect. So.. Iraq is responsible, and we must hold them responsible. Still think there's a difference? -scotsman \_ Not to mention that Perle was a signatory to the PNAC letter saying we should attack Iraq back in January 1998. http://www.newamericancentury.org/iraqclintonletter.htm. (Note that letter doesn't mention bin Laden or terrorism: 9/11 was just a convenient excuse to do what they wanted to do anyway). -tom |
2007/4/13-16 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Perl] UID:46288 Activity:kinda low |
4/12 Just finished a programming quiz. Do you think critizing the test was OK? They wanted someone to write code for something that could be done via shell aliases. This was at Riverbed. \_ I assume Riverbed is a company and this was an interview? If so, I think this kind of criticism is a great thing to do. It shows you really know your stuff if you can do both. If they count that against you they are idiots and you don't want to work there anyway. \_ this was actually after the phone screen. Probably not a good sign. Or maybe the manager's worries too much. \_ IMO, the right way to handle something like this is to say, "Oh, this would be really easy to do with shell aliases, and I can show you how I'd do it that way after I write the code to do it..." -dans \_ It makes you think twice about their ability to create well architected code if they cant come up with a good quiz; especially considering what is already out on the net. I have seen too many cases these days crafty perlers who write terrible code. Knowing what $_ means does not you are good engineer or coder. \_ Jesus christ you are an idiot. A programming quiz is not real work. It is a way of saying "prove to me you can do basic tasks in this language." Making it a simple problem means it is something you can actually have someone write in half an hour or so. Most simple tasks are probably easier to do with a shell script than with a real program. So what. That's totally orthogonal to the tester's goal. Oh and I'd almost take dans's advice. Start with answering the problem the way they asked and then mention, as an aside, not a critisism, something like "you know, if this was something I had to solve at work I'd probably just do x instead." You don't come across as too good for the test (which looks very bad, lots of otherwise good engineers are a disaster because they don't work well with others), you show you know your mad shell skillz, and you are letting someone know that you know to use the right tools for the right job. I've seen people rewrite stuff like find | xargs grep because they didn't know diddly about unix. That kind of stuff is never pretty. \- sort of the flip side of this, for a sysadmin interview, i've asked questions like "how would you generate a 10 random numbers between 1-100 from the shell", "how would you generate the numbers 1-100 from the shell" etc and people who would do it in C are slightly missing the point. people who would do it in C are sort of missing the point. i mean it is fine to say "i dont know how i would do it from the shell, but here is the 5line C program, that took 2min to write", but to say "that's dumb to do from the shell" will not serve you well. yeah, there are a lot of people unfamilar with xargs, mapcar, apply, lambda ... while riverbed may be in an inflationary phase, i suspect they are still small enough that they are being careful about who they hire. the OP had an interesting quandry whether to not to de-anonymize himself on the motd ... if he's an active member of the sloda community he faced either a "oh i dont know about his technical chops, but he seems pleasant enough" to "i havent seen his code, but he seems like a dumbass" ... given that various people here have various riverbed connections. various riverbod connections. |
2007/2/5-7 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:45654 Activity:nil |
2/4 Help UNIX experts. I setup a crontab and it keeps outputing crap. The cron is as follows: 0 4 * * * /bin/sh -c "cd mydir; tryit.pl 2>&1 > /dev/null" The error/email I keep getting is as follows, what does this mean? "stdin: is not a tty" \_ Check to see if "mesg y" is set anywhere. Disable that. \_ Instead of mushing about running /bin/sh to get a 'cd', I would put the 'cd' as part of the perl script and run that directly with a full path: 0 4 * * * /myhome/tryit.pl 2>&1 > /dev/null. Also, since this appears to be new code you might want to let cron mail you any output instead of devnulling it, at least for the first few runs. \_ This suggests your script is doing something that looks at stdin. Normally when you run the script from commandline, you are on a tty. Things run from cron arent. One way to test the different operating environment is to ssh into soda without a tty, and test. Try 'ssh soda /bin/csh -i' and try running your command. That will start a tty-less shell. -ERic |
2006/11/10-12 [Computer/SW/Languages/Perl] UID:45314 Activity:nil |
11/10 perl question: I want to bind the result of a pattern match on one variable to another variable. I constantly find myself doing something like: $myvar1 = $long_string; $myvar1 =~ s/.*(regex.*)/$1/g; and it seems silly to do an assignment followed by a modification. Am I missing something? Is there a way to do this in a single step? \_ Not a good way. One of the things ruby fixes and that they're fixing in Perl6. You can do: ($myvar1 = $long_string) =~ s/.*(regex.*)/$1/g; but since you're being a good little perler and using strict, you'll still need two lines since you need my $myvar1; in there somewhere \_ (my $myvar1 = $long_string) ... ? Now mconst will explain how there's an even better way. --dbushong \_ Not to nick pick but what's wrong with two lines? There's a fine line between convenience and readability. In either case regex in Perl is 100X easier to code and read than Java/STL/Python. \_ there's always the match, then assign... $long_string =~ /.*(regex.*)/; $myvar1 = $1; |
2006/10/25-27 [Computer/SW/Languages/Perl] UID:44961 Activity:nil |
10/25 I recall there being a really quick easy perl way to do global replace from the command line, but I can't seem to quite get it right. Something like: perl -e 's/pattern/replace/' file.txt Help? \_ I know how to do it with sed: sed -e s/pattern/replace/g file.txt > /tmp/output.txt \_ modern seds support perl's -i syntax as shown below: sed -i -e s/pattern/replace/g file.txt \_ perl -pi -e 's/pattern/replace/' file.txt (You need the -pi) |
2006/10/6-7 [Computer/SW/Languages/Perl, Computer/SW/Languages/Python] UID:44706 Activity:moderate |
10/5 Python experts, help. I'd like to do the following Perl regexp and reg substitution equivalent in Python, what's the best way? $line=~s/hello/world/i; if ($line=~/(foo\w+)/) { $myfoo = $1; } elsif ($line=~/(bar\w+)/) { $mybar = $1; } My limited Python knowledge says I must do the followings which seems really awkward: import re ... matchFoo = http://re.compile('(foo\w+)') matchBar = http://re.compile('(bar\w+)') m = matchFoo.match(line) if (m): myfoo = m.group(1) ... \_ I don't know Perl so I'm not sure what you are trying to do, maybe this link will be of some help: http://gnosis.cx/TPiP -scottyg \_ One of the reasons I gave up on Python and love Ruby is that Ruby has OO but maintains the nice regex syntax of Perl. \_ Its OO is also a lot cleaner and more consistent than Python's, and none of this indentation-is-important i-can't-paste-code bullshit \_ Yeah, those would be some more of the reasons. \_ I don't know python, but this would be the equivalent, AFAICT: import re line = re.sub(r'(?i)hello', 'world', line) m = re.search(r'foo\w+', line) if m: myfoo = m.group(0) else: m = re.search(r'bar\w+', line) if m: mybar = bm.group(0) --dbushong \_ Now I remember why I never learned python. |
2006/10/4-5 [Computer/SW/Languages/Perl] UID:44658 Activity:kinda low |
10/3 Does anyone know why using DB_File in perl would suddenly stop working and start storing only blank entries into the DB? The code is something like this (there can be multiple instances of this perl script running hence the lockfile) open (LOCKFILE, ">lock_file"); flock (LOCKFILE, $LOCK_EX); dbmopen (%PERLDB, db_file, 0666) set values in %PERLDB flock (LOCKFILE, $LOCK_UN); close (LOCKFILE) dbmclose (%PERLDB); So once in a while if I set a value in %PERLDB it just sets it to blank (nothing) instead of the right value. I've tried checking the value afterwords, and setting it over and over again until it sticks, but that eventually leads to Too Many Files open. Is there a way to check file handle leaking in perl? I don't see a place where I'm opening a handle without closing it in my script ... \_ You need to do the dbmclose before you unlock the lockfile. \_ good catch \_ Maybe you're hitting a race condition between the open() and the flock(). -tom \_ I think so too if that's what the code actually looks like. OP, why do you open()/close() the lock file at all? Why not just lock/unlock it? Can you show us the actual production code block? \_ I commented out the flock and opens and the problem didn't go away. It turns out the open was a braindead way of making sure that file existed, I'll fix that too. \_ Without locking and multiple instances of this code running I would expect Bad Things(tm) to happen. You do want locking of some sort. You don't need the open(). I'm left wondering if your file is randomly named or is really the static "lockfile" in your code. Again, if you can post the real production code you'll probably get better help than this sort of vague hand waving. \_ Actually I take what I said back, the flock/open is correct, at least according to examples on how to lock a file. How do you do a flock on a file that you haven't opened? \_ My error. In perl you do have to open the file to get a filehandle for flock. Anyway, perl relies on your OS's underlying locking mechanism which may not even exist and you should really be testing the return value, not assume it has been successfully granted a lock. If you test the return value you may find you're not getting a lock which is why your code behaves the same with and without the flock(). |
2006/9/14-16 [Computer/SW/Languages/Python, Computer/SW/Languages/Perl, Computer/SW/Languages/C_Cplusplus] UID:44378 Activity:kinda low |
9/14 http://www.salon.com/tech/feature/2006/09/14/basic I never knew C++ was a higher-level language than BASIC \_ It's salon. So what? \_ More specifically, it's David Brin, who writes decent hard sci-fi. Too bad he apparently didn't get a decent computer education either. \_ More specifically, it's David Brin, who writes decent hard sci-fi. Too bad he apparently didn't get a decent computer education either. [formatd] \_ Still doesn't bother me. He's a fiction writer, not a scientist. \_ A friend of mine was in a technology-related tv show with David Brin, and reports that he's pretty technically naive / clueless. I do like his books, though. - niloc \_ It doesn't bother you that he's saying "the problem with doing X w.r.t educating our children is that <incorrect fact>"? \_ Not at all. It's a slate article online, not an official publication from anyone who has anything to do with education. I give it the weight it deserves: zero. \_ I once read an article by a tech analyst which said the internet was invented in year 1991. \_ Wow that guy is a total idiot. Everyone knows it was the year 1991 when they invented the 1nt@rw3b!1. \_ Quick, someone tell that man about ruby/python/scheme/whathaveyou \_ He already discarded Perl as "too high level" He doesn't seem to understand that crappy != "low-level" \_ He mentions Python os well, and calls C++ "high-level." |
2006/8/17-19 [Computer/SW/Languages/Perl] UID:44038 Activity:nil |
8/17 Any movabletype experts on soda? When I try to create an entry on my blog I get a huge perl process and 'Out of Memory!' in my error log. The post appears in an individual archive but not on the main page. Thanks! -sameer \_ Maybe the post is generating an E_HOTAIR. |
2006/8/16-18 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:44021 Activity:nil |
8/16 Having some trouble with jhead, maybe someone has an idea: I have a large number of pics with no EXIF creation date, but a correct file modification date. jhead lets you set the modification time to the same as the creation time, but I can't figure out how to do it the other way around--any ideas? Thanks. -John \_ Doesn't look like it'll do it. I wrote a script to do this: ~dbushong/bin/filedate2exif \_ Many thanks, I'll try this. -John \_ for i in ... do jhead -ts perl -MPOSIX -e "print strftime(\"%Y:%m:%d-%H:%M:%S\", l\ ocaltime((stat(\"${i}\"))[9]));" ${i} done \_ Embed the timestamp into the filename, YYYYMMDD_HHMMSS_nnnn.jpg. |
2006/8/11-14 [Computer/SW/Languages/Perl, Computer/SW/Languages/Functional] UID:43974 Activity:low |
8/11 How do you find out the max # of file descriptors for a process, thread, and entire system? \_ Dep on OS. Are the youth today assuming "linux is the standard"? That is kinda sad. \_ LINUX RUUULES! W1ND0ZE DR000LEZ! \_ while(true) { do(something that uses a fd) if (good rc) counter++; print } \_ while(true) { do(something that uses a fd) if (good rc) counter++; print } \- well AssOS is better than windows like perl is better than basica. but it's not actually good. i can understand using something "useful" instead of good [like using perl instead of lisp today] but it's non-good when you dont know what is good because you have no exposure to it ... "It's a light saber. The weapon of a Jedi Knight. Not as random or clumsy as a blaster. An elegant weapon for a more civilized age." \_ This post is unintelligible. \_ E_TOOSHORT \_ How about E_FUCKINGINCOHERENT \_ Worse than that... this person got into Cal. I wonder what their application essay looked like. \_ while(true) { do(something that uses a fd) if (good rc) counter++; print } \_ sysconf(3) maybe what you are looking for. I think the variable for max fds is _SC_OPEN_MAX. Also try unlimt -a (or -n). |
2006/6/29-7/3 [Computer/SW/Languages/Perl] UID:43527 Activity:nil |
6/29 Visual Programming in Perl: http://search.cpan.org/dist/Acme-EyeDrops/lib/Acme/EyeDrops.pm |
2006/6/16-19 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:43422 Activity:nil |
6/16 Is there anyway in Ant to change/append the value in java.library.path before starting the script? I'm trying to use Ant to generate a DLL and then call a Ant task which needs native libraries in that DLL. I'd rather not have to modify my system path to include libraries before they have been generated... \_ Use perl. Wait, sorry, nevermind. :-) \_ Use ruby (rake). Wait, sorry, nevermind. :-) |
2006/6/13-15 [Computer/SW/Languages/Perl, Computer/SW/Languages/Web] UID:43374 Activity:nil |
6/13 In PHP what is the Perl equivalent of map {$_="HEY $_ HO";} @array; ? Thanks so much!!! \_ foreach ($array as $i => $val) $array[$i] = "HEY $val HO"; --dbushong |
2006/6/2-4 [Computer/SW/Languages/Perl] UID:43255 Activity:nil |
6/1 Writing a hash/array/scalar traversing function. How do I tell if a variable passed to me is a hash, scalar, or array in Perl? Thanks. \_ You can't, unfortunately. If you really want to do that, you have to pass a reference instead. --mconst \_ Ah I got it. I need to dereference a variable, then do a ref($var) to see its type. THANKS SO MUCH mconst. \_ Guessing that you really mean you were passed a reference, call ref() on it, which will give you undef (it was just a scalar), 'ARRAY', 'HASH', 'SCALAR', etc, meaning it was a reference to one of those. --dbushong \_ Welcome to perl, the worst of all typing worlds \_ How about PHP, where the only way to find out if something is an array or a hash is heuristically (i.e. "are the first few keys ordered ints starting from 0?") \_ And to be fair, ruby does some amazingly annoying things with arrays as return values. \_ Really? Like what? I've always found ruby's behavior w.r.t. arrays to be as convenient as possible while still completely flexible. --dbushong |
2006/5/23-28 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:43168 Activity:nil |
5/23 I'm trying to learn sh, bash, and csh programming. What's a good site that has sample syntax of the following ***psuedocode*** for each of the shells? foreach $file in (<dir/*>) do; echo I have file $file done; switch ($var) { case 0: echo hello; break; // this is a comment default: echo default; break; } if ($z>=5 || $str eq '12345) {print $hello} \_ not really. I'll start w/ sh: --dbushong for file in dir/*; do echo I have file $file done case "$var" in 0) echo hello ;; *) echo default ;; esac if [ $z -ge 5 -o $str = 12345 ]; then echo $hello fi \_ bash is basically a superset of sh. Whenever I need to brush up I usually just google for shell scripting, and frequently (re)discover this site: http://vertigo.hsrl.rutgers.edu/ug/shell_help.html Incidentally, csh is a great interactive shell, but there are some compelling arguments why you may want to avoid it for general scripting purposes (of course, one nerd's compelling arguments are another nerds religious claptrap so ymmv): http://www.faqs.org/faqs/unix-faq/shell/csh-whynot Also, I find the O'Reilly UNIX Power Tools book to be a very useful reference to have around when shell scripting. -dans \_ I gave up on csh for all but the simplest shell scripting when I noticed it didn't handle nested if/then cases sanely, and went through coding hell trying to workaround it. If you're going anything more than 2-3 lines, use a sh based shell, or a "real" script language like perl. -ERic \_ I'll second that. I still use tcsh from the cmd line just because I find it more pleasant than bash, but meh. I'll tend to use perl unless the script is going to end up being more than about 25% program executions. --dbushong \_ My rule is 10 lines. If I can't write it in 10 lines of some shell script language in a few minutes I'll use perl instead. |
2006/5/8-9 [Computer/SW/Languages/Perl] UID:42970 Activity:nil |
5/7 >./news.cgi Can't locate XML/RSS.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.\ 8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.\ 8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) Can someone install the XML/RSS module? Thanks. \_ Done. --mconst |
2006/4/26-28 [Computer/SW/Languages/Perl] UID:42845 Activity:nil |
4/26 How come the Perl man pages aren't installed? (or where are they?) Like, e.g., "man perlfunc". Ok thx. \_ Sorry about that; I've installed them. Please let me know if anything else seems to be missing. --mconst \_ how 'bout "man sex" ? \_ As long as it's done in safe mode, more power to you. Mount that host yourself. |
2006/4/16-17 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Perl, Computer/SW/Languages/Python] UID:42756 Activity:nil |
4/16 I'm very disappointed with os x: I made an application bundle around a python script: it executes fine but dropping a file on it doesn't work turns out finder passes a ProcessInfo object and you get that as argv[1] well, you get its UID- and that is the only arg you get so far the on;y way i have found to translate the UID into a process info, and thus to get the path of the file i dragged, is with cocoa i.e. c++ or objective c. doesn't seem to be any decent applescript way to do it, or i could just shell out to osascript i guess this explains why all the droplet hacks use a binary executable to call shell, perl, or python scripts this man-made creation troubles me |
2006/4/5-7 [Computer/SW/Languages/Perl] UID:42693 Activity:nil |
4/5 any online tutorials/exam question for Perl? thanks \_ {ajani,darin}@csua.berkeley.edu taught a perl decal class, try pinging them. -dans |
2006/3/27-28 [Computer/SW/Languages/Perl] UID:42473 Activity:nil |
3/27 Anyone have experience with embedded Perl in C/C++ apps? I've been using this for a while but now I find out I can't "use POSIX" for example in the Perl code, and trying to follow instructions on the internet for how to load extensions like this doesn't seem to work. So, maybe someone can help describe what should be done... I tried putting in an xs_init function generated by ExtUtils, but for example when the DynaLoader tries loading POSIX it can't resolve symbols that come from perl.h (PL_sig_name). |
2006/3/18-20 [Computer/SW/Languages/Perl] UID:42306 Activity:kinda low |
3/18 I'm looking for a file management utility that will copy files and create directories based on the date of the file. I recently bought a new digital camera (old was canon; new is casio) and their file storage naming conventions and directory structures are totally differently. Each different "loader" does a different thing. And Picasa doesn't copy and create directories based on file date. What I want to end up with is a directory structure like this: My Pictures/2006_03_18/img12345.jpg I don't care about the filename since each camera has their own naming convention. But the directory name has to be customizable to that exact format. SW doesn't have to be free. I'll pay for this. Thank. \_ This sounds like a 5-10 minute perl hack to opendir/readdir a directory structure, cd'ing around, then moving files based on an fstat. I suspect any of dozens of people here could write this blind folded, drunk, asleep and off their meds. Or maybe a list created with find piped through perl. There's a lot of ways to do something like this depending on what your starting structure looks like. \_ perl -MFile::Find -MPOSIX -e 'find(sub{-f&&rename($_,strftime("/My Pi\ ctures/%Y_%m_%d/$_",localtime((stat)[9])))},".")' \_ perl -MFile::Find -MPOSIX -e 'find(sub{-f&&rename($_,strftime("/My Pi\ ctures/%Y_%m_%d/$_",localtime((stat(_))[9])))},".")' Change the part after strftime to suit your format and run this from the directory you want it to start the search at. --dbushong \_ This breaks if you have any %'s in your filename, btw, though that isn't hard to fix. --dbushong \_ Thanks for the responses. I guess I wasn't clear. By the date I mean the date of the picture embedded in the EXIF header inside the jpeg file, not the date of the file itself. And this has to be a windows xp program. I can't write code anymore so I'm looking for some generic photo manager SW that can do this. Thanks. -OP \_ Oh, just download some real tool then, like Organizr or Picassa. (Though modding that line of perl to use EXIF header Picasa. (Though modding that line of perl to use EXIF header is also easy :-) --dbushong |
2006/3/10-13 [Computer/SW/Languages/Perl] UID:42187 Activity:low |
3/10 I wrote a little perl, that had a little curl right in the middle of it's call stack. And when it crashed, it crashed very very fast, but when it was slow, it was working \_ LWP::UserAgent! \_ Can I use LWP::UserAgent to do multiple concurrent requests, and time them? Will it deal with a redirect automatically? \_ There's also a parallel version of LWP:UserAgent but it is a bit clunkier to use but if you need it, I found it better than forking off multiple child procs. \_ Eh, using the default one with Parallel::ForkManager's pretty easy. I used that for the remote-link checking part of a linkchecker I wrote and it was pretty easy. \_ I haven't used P:FM. I assume it's forking off procs? I'll take a look at it, thanks. I wonder if P:FM or the P version of LWP:UA is faster.... \_ How would you time the parallel requests in perl? (how long one takes to complete). \_ Since I was running dozens or even hundreds at a time, I just did a simple $end - $start timer for entire runs. Timing a single connection is a tiny bit harder because the start time is just a "go do them all now" call but you can time any particular connection if you want. You know when you fired off the batch, you control if the batch runs in order or as fast as possible/parallel, you know for each connection when you get the first bits back and you of course can tell when a particular connection is done. But as I said, I just fired off however many, noted the start and end times and that was it. Divide # requests by total time was good enough for me. |
2006/3/2 [Computer/SW/Languages/Perl] UID:42064 Activity:kinda low |
3/2 LDAP help: I am trying to dump the userPassword from an ldap database with ldapsearch but it is coming out base64 encoded: userPassword:: e2NyeXB0fWhhKllueGJrSXhrR2M= Is there a shell tool to decode this ... I want to avoid re-writing the whole thing in perl (I'm not that familar with LDAP or encodings and this isn't important enough to spend a lot of time on ... but I've answered a lot of motd questions in my areas of expertise so hoping somebody can return the favor.) \_ If you've got OpenSSL installed: \_ If you have OpenSSL installed: $ echo '[passwd]' | openssl base64 -d If you've got perl and Base64.pm installed: If you have perl and Base64.pm installed: $ perl -e 'use MIME::Base64; print decode_base64($ARGV[0])' [passwd] Some versions of uudecode also support base64 decoding: $ echo '[passwd]' | uudecode -rm \- I have to do this once in a blue moon and use the emacs base64* functions. Wont work on shell stream but YMMV. \_ These answers are great! Feel the love. |
2006/1/28-29 [Computer/SW/Languages/Perl, Computer/SW/OS/OsX] UID:41579 Activity:moderate |
1/27 Can anyone recommend a good open-source PDF creator for os x? Thanks. \_ File -> Print -> PDF -> Save as PDF? \_ Oops, sorry. I mean SERVER-SIDE PDF creator. I need to create PDF documents for users of our web site. -op \_ Create them from what? You can generate PDF directly in perl with perl-PDF. Or you can use htmlpdf to convert HTML to PDF. -tom \_ Create a CUPS printer with a PDF driver. On the Mac OS X machine go to <DEAD>localhost:631<DEAD> \_ If you don't have to produce too many documents, you could do this with AppleScript. The performance is ass, but fine if your not trying to pump out many documents a minute. \_ I won't (I only need approx 1 document/day). How do I use Applescript? I've never used it before. Thanks. -op |
2006/1/18-21 [Computer/SW/Apps, Computer/SW/Languages/Perl] UID:41420 Activity:low |
1/18 I need to gain 20-30lbs of weight and want to track my progress. I could do this in an Excel spreadsheet but I don't have it installed right now and would rather have some nifty web thingie - I googled and most of the stuff I found kind of sucked. Before I revert to Excel (if lazy) or write my own (if bored) does anyone have recommendations? \_ "need" to gain? why? \_ My BMI is 15.4 . If it wasn't from being sick and/or I was a girl, I'm sure that's eating disorder range :) -op \_ http://www-128.ibm.com/developerworks/library/l-gnuplot Look at figure 8. \_ Sigh, duh. I actually have used gnuplot a fair amount. This should be perfect for an unpolished barebones thing. Thanks! -op \_ If I wanted to gain 30 pounds, I'd get a spiked tail grafted on to my ass. This would help with both balance and self-defense, and seems like the best possible way to gain weight. It might also be possible to use your mouse or trackball with the tip of your tail, increasing productivity. \_ Dude, just roll your own. It's a really simple bit of Perl. \_ I'm not a big Perl hacker. It is pretty trivial but a nice one with login/security, and pretty pictures rather than text would take me at least a few hours to write, because I'm not particularly familiar with the web/graphics libraries - op \_ The less you do on the couch, the faster you can put on that weight. (or more seriously, vi does this just fine) \_ depends on what kind of weight. he could put on a lot of weight sitting on the couch or in front of the computer, he just needs to eat more. EAT MORE LARD! \_ I lost the weight because I was/am sick, and need to gain it back in a healthy way or it defeats the purpose. Thanks anyway! (defeating silly comments with reasonable responses) - op \_ So far as I know the only way to quickly gain weight is to gain fat. If you eat right and exercise a lot, you might take a couple of years to gain 30lbs of lean-ish body mass. Unless you have naturally high levels of testosterone and/or take steroids. Though there are some other drugs you could possibly take. \_ Luckily (?), I am actually on (safe) steriods for medication for a few months. I have seen a nutritionist... it's not too bad to put on a pound a week, it turns out (eat a lot and drink Ensure). More than that, maybe I'll get lucky - if I'm underweight, maybe my body wants to recover or something. -op \_ I know dawne wrote one a few years ago; I'll see if it's still lying around somewhere and easy to get working again. --dbushong \_ Found it: http://bushong.net/dawn/widgets/tracker The graphing's a little sluggish b/c GD's broken under mod_perl for me, but otherwise it seems to work. --dbushong \_ Oh, right, it doesn't handle weight _gain_. I'll work on it. \_ If you have a palm use EatWatch: http://www.fourmilab.ch/hackdiet/palm |
2006/1/15-17 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:41383 Activity:high |
1/15 This is a computer question which photo geeks would appreciate. I am trying to extract date/time from JPEG's EXIF header and use that to override Windows/NTFS's filename's create time. I need to do this in a batch mode involves hundreds of photographs. How to do this? write a shell script in cygwin? which library do you recommend to extract EXIF header? how to modify ctime on NTFS? thanks. kngharv \- i dont know anything about the windows side but i use "jhead" [http://www.sentex.net/~mwandel/jhead/] or tcl. ok tnx. --psb \_ thanks. jhead fits that part of my need. However, I am also looking for something where I can add a field to EXIF, namely "FocusLengthIn35mm." If any of you guys knows how to do this, please let me know. OP \_ Image::ExifTool --dbushong \_ http://jpgtime.learsy.com i've used it to change the time stamps, not sure if it can add other exif data \_ Since the beginning of my digital camera days, I've adopted the policy of renaming my digital camera images YYYYMMDD_HHMMSS_NNNN[_tag].jpg (where NNNN is the sequence number and tag can be the camera model). The time a picture was taken is more important to me than all the other attributes, and name my files this way make sure that information will not be lost and every file has a unique identification. I use my own perl script to do this, but I am sure you can find utilities that does rename for you. My script can also re-touches file timestamp based on the time embedded in the filename, so I can very easily adjust the file timestamp if necessary. The important thing is to make sure your camera's clock is set correctly (for the timezone you are in), but my script has an offset option for those "ops" occasions. On my last trip we used 2 cameras, and the file ordering allows me to dump the pictures from both cameras together and do slide shows in the order the pictures were taken across both cameras. Email me if you want to give it a try. -chiry \_ I didn't agree with "The time a picture was taken is more important to me than all the other attributes" until I became a parent. When other people see my baby's pictures, the first question they ask is nearly always "how old was he?". For those pictures without imprinted dates, I quite often find myself unable to answer. pictures without imprinted dates, I usually find myself unable to answer. \_ unfortunately, the reason why I've asked this question at first place is that I am still using 35mm and other film cameras. and they don't have EXIF info :p \_ might be a bit overkill, but these should be able to do what you want: http://www.luminous-landscape.com/reviews/software/asset-management.shtml |
2006/1/4-6 [Computer/SW/Languages/Perl] UID:41229 Activity:nil |
1/4 How can I kill a win32 process in perl that I created from fork? I tried fork + Win32::Process::KillProcess, but I don't think that's the right process id. \_ One would assume you could just call kill() on whatever id you got back from fork(), but that probably makes too much sense. \_ I've tried kill, and it doesn't kill the proc. I of course tried that first. It works fine on Unix. I'm using activestate perl. \_ what are you forking? \_ The child proc exec's mplayer, the parent monitors it and kills it under certain conditions. |
2005/12/18-20 [Computer/SW/Languages/Perl] UID:41065 Activity:nil |
12/18 With FreeBSD's sysinstall program, is there a way to search for packages by name only and not by description? That is, if I search for perl, can I filter out all the zillion modules that happen to mention "perl" in their description? Alternatively, is there a way to navigate the long lists of packages without continuously using page-up/page-down? (Why are the first letters highlighted in a different color if they aren't mnemonics?) Is the answer simply: "don't use sysinstall, use ports"? \_ either use cd /usr/ports; make search name=whatyouarelookingfor or poke around http://freshports.org - danh \_ check out portupgrade too. if you use its -PP option, it will only use packages |
2005/12/7-9 [Computer/SW/Languages/Perl] UID:40911 Activity:kinda low |
12/7 Sure, call me crazy, but is there a way to run Perl on a PDA? I stfw, and all I found was a 2001 article on http://Perl.com saying that it's impossible, but in tech terms, this is like finding a 1930s article saying it's impossible to send a man to the moon. \_ uh... which PDA? I don't see why not, and probably the only issue is limited memory. \_ I wouldn't say limited memory is an issue w/ PDAs these days. I think my Treo has more memory than my first linux box (it certainly has a bigger "hard drive" - 1 GB flash) \_ Well, your Treo still has only 16 MB of RAM, much of which is probably in use. The 1 GB flash doesn't really help here. And even then, Palm OS has a pretty puny stack. Anyhow, it's still an issue for some PDAs, hence my question about which one. \_ Well, it's more of a wishlist kind of thing. I'd like a PDA that I test some scripts on; being able to read a PDA that I can test some scripts on; being able to read ebooks and listen to music on it wouldn't be bad, either. Suggestions? \_ There is something for WinCE: http://www.rainer-keuchel.de/wince/perlce.html Supposedly there is a port to PalmOS, but it looks dead: http://sourceforge.net/projects/palmperl I think there are some Linux based PDAs that come w/ Perl (Zarus?) \_ Is the Zaurus discontinued? I'm having a hard time finding one for sale.... \_ Is JavaScript close enough? We have pretty good DOM/JS support in recent versions of the AvantGo client. --dbushong \_ Sorry, no, Perl-heavy work environment. |
2005/12/5-7 [Computer/SW/Languages/Perl] UID:40851 Activity:nil |
12/5 Ever since the reboot, I've been getting the following messages: procmail: Kernel-lock failed procmail: Kernel-unlock failed many times. What does this mean? Anyone know what might be causing this? \_ I think we're missing the perl module File/MkTemp.pm; want to mail root for both of us? \_ Done. -op |
2005/11/22-24 [Computer/SW/Languages/Perl] UID:40693 Activity:nil |
11/22 "Beginning Perl" vs. "Picking Up Perl", which one is better for learning Perl from scratch? I know C for more than a decade but don't know any Perl. Thx. \_ if you can borrow it, borrow Beginning Perl, it's a quick easy \_ if you can borrow it, borrow Learning Perl, it's a quick easy read, makes for a good intro. \_ Programming Perl may be just as good of a choice or better. |
2005/11/18-19 [Computer/SW/Languages/Perl] UID:40650 Activity:nil |
11/18 In C, argv[0] is the command that invokes the program. Is there an equivalent in Perl? Thx. \_ $0 I believe the perlrun manpage has all you would ever want to know on this subject. \_ It works. Thx. |
2005/11/12-14 [Computer/SW/Languages/Web, Computer/SW/Languages/Perl, Computer/SW/Unix] UID:40555 Activity:nil |
11/11 Hey MOTD, I'm looking for a good webhosting service. A coworker has recommended http://dreamhost.com. Does anybody have any first hand experience with that provider? Does anyone have any suggestions, warnings or general advice? Ideally I'm looking for a place with a unix shell, php, perl, and possibly mysql & cron -- but it doesn't have to have heavyweight bandwidth, etc. TIA. -mice \_ It may be more money & work than you wanted, but I've had good luck w/ http://johncompanies.com. You get root on a jailed system: FreeBSD w/ ports tree available or some Linux distro w/ some pkg system. So you can run any sort of mail/web/anything server you want. Very responsive support. But it's like $30 - $70/month. --dbushong \_ Is that how much you pay for http://csua.org? \_ No, currently I just run it off my home DSL. I'm thinking about getting either a colo'ed box or something like this one of these days just to have the option to scale a web app to higher bandwidth on short notice should I ever actually manage to market anything successfully (e.g. http://floatingsheep.com/wishlist ), but for now it's not quite worth the expense. --dbushong \_ I have friends who use dreamhost (and one of them gave me a login). AFAICT it seems to be pretty good (unix shell, perl, php, mysql, and I assume cron). If I had to pay for hosting myself, I'd probably go with them. --jameslin |
2005/10/24-26 [Computer/SW/Languages/Perl] UID:40247 Activity:kinda low |
10/24 Dear motd. I need some perl to randomize the lines in a text file. I know this is easy but i have no perl-fu. Please help. \_ @lines = <FILEHANDLE>; print splice(@lines,rand(@lines),1) while @lines; \_ Let's hope your file is not bigger than the amount of virtual memory of the machine. \_ Yes, since motd so often grows to fill memory on soda.... \_ Let's... How completely pointless. This was a 2 minute perl snippet, fer chrissake... \_ Maybe I should show what I have and you can tell me where I'm going wrong, This uses a fisher-yates randomization to be unbiased: #!/usr/bin/perl open(FILE, "+< $_"); while (<FILE>) { push(@lines, $_); while (@lines) { print splice(@lines,rand(@lines)%@arraylength); } @reordered = fisher_yates_shuffle(@lines); foreach (@reordered) { print $_; } sub fisher_yates_shuffle { my $list = shift; # this is an array reference my $i = @{$list}; return unless $i; while ( --$i ) { my $j = int rand( $i + 1 ); @{$list}[$i,$j] = @{$list}[$j,$i]; } } \_ Your function isn't returning the array. @reordered is being set to "0" (The return value of the "while"). Change "foreach(@reordered)" to "foreach(@lines)" and this code should work. \_ Careful about using rand with %. You can get into distribution problems there. \_ The % doesn't do anything; perl rand called that way can never return >= @lines. \_ Upgraded as per dbushong. I didn't trust perl enough. print splice(@lines,rand(@lines)%@arraylength) while (@lines); \_ Upgraded as per dbushong \_ Where's $_ coming from in the open() line? \_ #!/usr/bin/perl die "usage: $0 file\n" if @ARGV != 1; open(my $fh, '<', $ARGV[0]); my @offsets = (0); push(@offsets, tell($fh)) while <$fh>; pop @offsets; while (@offsets) { seek($fh, splice(@offsets, rand(@offsets), 1), 0); print scalar <$fh>; } close($fh); ## this is how i'd do it. --dbushong \_ My (extremely short) version: /msg dbushong hey, can you write a solution to that motd thing? \- i have had problems using perl rand to do this on files with more than 32k lines. you may want to test this out ... maybe rand returns more values than it use to but i had to re-write this for larger files ... this was +5yrs ago. if you want the codes mail me. oh also for larger files performance can be an issue. [i dont mean really large files ... i typically was operating on about 130k entries ... 2x/16netblocks of addresses] --psb \_ Actually, it looks like it's not perl rand, it's just manipulating the slices efficiently on large arrays that's making things suck. I'll ponder. --dbushong \_ OK, redone to user fisher-yates as above. Now it only takes 22 seconds on soda on /usr/share/dict/words: --dbushong #!/usr/bin/perl die "usage: $0 file\n" if @ARGV != 1; open(my $fh, '<', $ARGV[0]); my @offsets = (0); push(@offsets, tell($fh)) while <$fh>; for (my $i = @offsets - 2; $i >= 0; $i--) { my $j = int(rand($i)); @offsets[$i,$j] = @offsets[$j,$i] if $i != $j; } for (@offsets) { seek($fh, $_, 0); print scalar <$fh>; } close($fh); \- hello my codes taeke about 5-6 sec on /usr/dict/words on sloda but the sloda numbers are not that stable it is interesting to see the memory growth variations of the different approaches. ok tnx. this time i didnt check the quality of the shuffle. SSH-soda{12}[~/bin]% while 1 loop==> ./rand1.pl /usr/share/dict/words > /dev/null loop==> end 0:05.46sec, [3.961u 0.100s 74.3%], [10080Kbmax 0pf+0#swap] 0:06.56sec, [3.949u 0.146s 62.1%], [10078Kbmax 0pf+0#swap] 0:05.42sec, [3.953u 0.108s 74.7%], [10080Kbmax 0pf+0#swap] 0:06.70sec, [3.921u 0.172s 61.0%], [10082Kbmax 0pf+0#swap] 0:08.29sec, [4.041u 0.182s 50.9%], [10074Kbmax 0pf+0#swap] 0:05.19sec, [3.870u 0.185s 78.0%], [10074Kbmax 0pf+0#swap] 0:04.79sec, [3.830u 0.176s 83.5%], [10078Kbmax 0pf+0#swap] 0:04.55sec, [3.902u 0.159s 89.0%], [10074Kbmax 0pf+0#swap] 0:06.07sec, [3.917u 0.182s 67.3%], [10076Kbmax 0pf+0#swap] \_ How would an Intel Critical Asset randomize a file? |
2005/10/19 [Computer/SW/Languages/Perl, Computer/SW/OS/Windows] UID:40189 Activity:nil |
10/18 This is a serious thread, please don't delete it. I'm about to get \_ Ah come on... Beastiality never goes out of style. married and will be sharing my XP file server files (MP3 and videos) on 802.11x. The server will be up and accessible 24x7 to run regular stuff too like TV (all-in-wonder card), browser for house guests, etc. I also have about 50G of porns on it and I need to hide them from my wife since she doesn't like them. Since she's in tech she knows how to mount, log in, and do other things. What's the best way to hide my porn collection? Thanks. \_ Burn to DVD and then delete. \_ Agreed. \_ Or buy a firewire drive, transfer everything to it, keep it unplugged and in a closet for the duration of the visit just to make sure that some random guest doesn't accidentally replug it in. \_ Yes, but you'll be stupid and leave it plugged in after a really good session. Poof. Caught. Just admit to yourself you have a porn collection, cull it down to just Good Porn, and put it somewhere she won't see right away. Make a backup because once she does find it, she'll delete it. Get yelled at. Find another place to hide in directory structure. Best place? Game and app directories. \_ Can't you just make the folder not readable for other users? \_ Yeah, win xp has per-user security stuff available like unix. \_ What about 2k and NT? -- !OP \_ i think it's tied to NTFS \_ This is hilarious! \_ I guess you could try just obfuscating it under some innocent directory tree and rename all the files with a perl script or something. \_ nuke it all. enjoy your wife more. \_ link:csua.org/u/drp (work-safe) \_ PGPDisk. Confidential_work_docs.pgd. And make a backup to a 3.5" USB drive. -John \_ pkzipc -pass foo ...... \_philcompress \_ Did phil ever graduate, or is he still a perpetual undergrad creeping closer to graduation one unit at a time? |
2005/10/6-9 [Computer/SW/Languages/Perl] UID:40002 Activity:nil |
10/6 Is there an easy way in Perl to enumerate a complete file tree from a given directory? \_ File::Find? \_ This looks far too complex for what I need. But if there's nothing simpler I guess I can use it. \_ use File::Find; find(sub { print("$File::Find::name\n"); }, '.'); # how much simpler did you want? \_ Yeah, after trying it, it was easier than I thought. Thanks for the recommendation. |
2005/9/23-27 [Computer/SW/Languages/Perl] UID:39836 Activity:low |
9/23 In the interests of not re-inventing the wheel: anyone know of a simple way,inside a perl program ,to have a command start at the top of the minute? Thanks \_ cron \_ on a not-busy system cron is good at starting commands at the top of the minute but does not guarantee your job will run at that time, just at *some* time during the minute. if you really actually need to run at the top of each minute, you could write a check vs the current time and do a "sleep 1" or something equally silly in a loop until $current_second_in_minute = 0 or whatever your criteria is. on a busy system all bets are off. \ This is a test program that needs to send specific data to a device which bins data every sixty seconds and I am losing bits at the beginning and ending of the test because the test code does pay attention to where in the minute its started. Its a small but noticable error that I would like to get rid of; if possible. \_ What sort of granularity do you need? Less than a second? Less than two seconds? Less than a tenth of a second? \_ I would just sleep # of secs until next minute then run command if you need greater precision there are probably millisec calls \_ I would at least like to start off with a +/- 1 second and go from there. The sending and receiving machines both use the same ntp servers so the clocks are in sync. \_ setitimer() is what you want, but it is in C, Time-HiRes uses it in perl. Or you could write a few lines of C to sent your perl a signal every min. \_ I'd second this. Let us know if there are other limitations. \_ use a real-time language (ie not perl/java) \_ What does the language have to do with it being real-time or not? There are plenty of real-time JVMs out there. The OS/environment is responsible for this, not the intrinsic language. |
2005/9/21 [Computer/SW/Languages/Perl] UID:39789 Activity:low |
9/21 In Perl how do I pass by reference a scalar variable? \_ \$foo --dbushong |
2005/9/2-3 [Computer/SW/Languages/Perl] UID:39466 Activity:nil |
9/2 Hey motd I used to have perl w/DBI 1.42 & DBD 2.9003. After upgrading Perl, DBI 1.48, & DBD 3.0002_1 I'm seeing something really weird. The following used to work: $dbh=$DBI->prepare("INSERT INTO data VALUES(\?)"); for ($i=0; $i<10; $i++) { if (!$dbh->execute($i)) { print("Oh no! Can't execute: ",$dbh->errstr); } } This runs ok before the upgrade. After the upgrade, if I ever see just one error, the rest of the execute statements give me an error, even though they do insert. Anyone run into this problem? Is this a bug? ok thx. \_ Hi, I'm the op. I tried DBD 3.0002 instead of 3.0002_1 even though the CPAN web site lists them with the same number of PASS/FAILED tests. I guess they missed this simple test case. Anyways, DBD 3.0002 seems to work. Thanks. |
2005/8/31 [Computer/SW/Languages/Perl] UID:39376 Activity:nil |
8/31 Looking for an XML parser for Perl, preferably one that doesn't require installation (something already built in). If it's not already built in, I prefer something that doesn't require C compilation, and that I can just stick the *.pm to use. I'm looking for portability, not performance. Thanks. \_ What's wrong with using CPAN? \_ Sometimes it's nice to be able to just give someone a self-contained tar-ball and say "here, run this" without expecting them to debug the various CPAN error messages that might crop up. I've always found CPAN to be a slight PITA. \_ Huh? CPAN simply automates the compile for you. It's not like you can simply tell someone to tar xzf foobar.tgz without doing a perl Makefile.pl and then doing a make on it for the majority of modules. Given that you aren't guarenteed where the site modules for perl reside on any given distribution, your safest bet in terms of portability is to utilize make. In the majority of cases, it usually just simply dumps the pm files in the correct place. If you have problems with CPAN, then you most likely will have problems with installation of perl modules anyway. The only way you can really ensure no make, no brain portability is if you have the same setup on all your distribution machines and then do a straight tar off of it. If you're that paranoid about it, you can simply wrap CPAN into a script... \_ By searching for XML Parser on CPAN I got like over 1000 results. I never know whech CPAN modules are the best to use and end up wasting time experimenting them. Let me give you an example. Someone put up XML::Parser. The name is good but the format they use is completely fucked up (hard to use). Someone else put up XML::Parser::EasyTree, which is much easier to use. By the time I figured out which one has the least bugs or problematic or easiest to use, I've already wasted 2-3 hours. \_ I've been using XML::Simple... I'm only doing basic stuff. \_ Interesting! Unlike shitty XML::Parser, according to XML::Simple the following two cases are actually equivalent! case 1: <tag1 field=value>HELLO</tag1> case 2: <tag1><field>value</field>HELLO</tag1> Do you ever run into problems? I think this is perfectly acceptable for my cases and actually makes my life a lot easier. THANK YOU MOTD, YOU ARE GREAT. \_ Four problems w/ XML::Simple: 1) if you're trying to _output_ XML to conform to a specific schema/DTD, it's very hard 2) unless you turn off some of the behavior that makes it easy to use, a different file of the same schema can produce a different data structure in perl; not always what you want 3) at least when I used it, it caused mod_perl to die horribly 4) It reads the whole file into memory. If you have a huge file you should use something like XML::Twig --dbushong |
2005/8/31-9/2 [Computer/SW/Languages/Perl] UID:39372 Activity:nil |
8/31 Anyone here use ruby? Is it worth learning (say for someone who mostly programs in perl/c)? \_ You don't say what your intended use is. For what? For personal pleasure because you're a language geek? For work? For a big team project? For one off throw away code? What? \_ I've been hearing a lot about it from co-workers and I wanted to know if I should spend some time to learn it b/c it is one of those things that any reasonable unix person is expected to know. Also it is pretty nice, I'd like to re-write some of my personal perl programs so I can ditch perl. \_ Yeah, it's worth learning, why? Because it's not perl. I'd suggest learning Python over Ruby (probably bigger base). Scripting in perl just plain sucks, especially if you have to come back to it in a couple of months and update the crap. \_ If you write crap code in ruby, it will still be crap code months from now. Don't blame the language if you're a shitty programmer. \_ I started on it. I read all the online intro/how-to/beginner docs but since I'm already proficient with perl I just couldn't find a real excuse to write anything in ruby. Same thing happened to me with python. Yes, there are some things that might be somewhat easier in one language over the others, but not so much better that I saw value in climbing the learning curve for the rest of it. \_ So, all the "small clean code" fans I know swear by it, including my boss. They usually say it's got the best of Perl and Python, plus some new features. \_ Getting paid to write in it is different than choosing to because you like it. If my boss swore by it I'd be over that pesky little learning curve. :-) \_ I use ruby for scripting, primarily because I know Smalltalk and I don't know perl. Ruby has a bit of kitchen-sink syndrome (let's throw in another language construct / feature!), but all-in-all it's decent. If you can already do everything you need to in perl, there's probably no need to learn ruby, but, I think ruby programs are usually easier to read and ruby has some features like continuations that are good to know for general programming knowledge. - ciyer \_ I've started to use it. A buddy of mine who was a bigtime coldfusion programmer says that Ruby on Rails is prob one of the coolest things out now for web app dev. see: http://www.michaelbuffington.com and search for ruby. - vallard \_ Ruby is probably the most fun language I've ever coded in. It makes writing everything as beautiful little OO jewels beautifully easy. It also lets you do lots of "cool hacks" that probably don't lead to good, maintainable code, but they're a hell of a lot of fun to write. That being said, it has some issues: * it's the slowest modern language i've ever used * dynamic typing + no sigils (perl's @foo, $foo, %foo things to sort of indicate type) = lots of runtime errors, for me. supposedly if you're a better programmer this doesn't happen, but I'm just weak. --dbushong \_ Yeah this is what I'd say. Well, the slowness part. The lack of sigils is a benefit I think... if it's a problem I think you might try using naming conventions. But mainly I've only played around with it for fun because nobody at work knows about it, it's slower, and the smaller userbase and "stuff" out there for it compared to Perl. Perl's OO blows so hard though. \_ I think one thing Perl is teaching me is that it's important to give pretty names to stupid things. 'Sigil' sounds so much better than 'declare-with-every-use.' -- ilyas \_ I like perl, being a slow learner I have a hard time learning yet another new language. I think what you get with The use of ruby on rails is nice; Active Record, MVC (CRUD w/ scaffolding), AJAX 'api', testing and debug builtin, reflection (MINIMAL schema configuration), etc. Check out the intro videos on. http://www.rubyonrails.org |
2005/8/25-26 [Computer/SW/Languages/Perl] UID:39273 Activity:nil |
8/25 Is there any way in Perl for win32 to explicitly kill a process started with fork? kill 9, $pid doesn't do it. \_ cygwin or activestate? \_ I'm using activestate. -op |
2005/8/19-22 [Computer/SW/Languages/Perl] UID:39181 Activity:nil |
8/19 Sight Seeing with Google: http://perljam.net/google-satellite-maps |
2005/7/15-18 [Computer/SW/Languages/Perl] UID:38643 Activity:nil |
7/15 How do you check what Perl libraries you have on your machine? \_ Perldoc isn't working for me to figure out command line way right now, but you can always 'perl -V' and manually look in the @INC directories. \_ If you just want to know if module Foo is installed, you can say: perl -MFoo -e '' If Foo is present, this will exit silently. If it's absent, you'll get an error to the effect of 'Can't locate Foo.pm in @INC' -dans |
2005/7/12-14 [Computer/SW/Unix, Computer/SW/Languages/Perl] UID:38585 Activity:nil Edit_by:auto |
7/12 Your favorite O'Reilly books online, for free. This includes big titles on Java, Perl, networking, UNIX, Oracle, Linux, and Samba. http://www.unix.org.ua/orelly and here <DEAD>www.hackemate.com.ar/textos/O'reilly%20-%20Complete%20Bookshelf<DEAD> \_ With all the political trolling that's been going on around here, at first I thought this was about Bill O'Reilley. \_ keywords: book learning perl mysql postgres Oreley keywords: OReilly Reilly OReiley Reiley OReilley Reilly Orelly Orelley |
2005/7/7-10 [Computer/SW/Languages/Perl] UID:38467 Activity:nil |
7/7 Is there an easy way in Perl to parse command-line arguments like: -opt1 val1 -opt2 val2? \_ Getopt::Std module \_ Ah, thank you--both for the useful answer and the quick reply. \_ Specifically, look at the getopts() function in there. \_ How about in Python? \_ python has a standard getopt too. stfw. |
2005/6/27 [Computer/SW/Apps, Computer/SW/Languages/Perl] UID:38320 Activity:nil |
6/27 PDF -> Excel question. In a PDF file there are rows and columns of numbers (a spreadsheet). Is there an easy to to copy and paste that into excel and preserve the format? I tried it many times and spent a lot of time dicking around with the "paste formatter" manually putting in column delimiters. And it still didn't come out ok because the columns couldn't line up. Is there a third party software that can do this? or some other way like export the highlighted PDF segment into some other format/document and then move it back into excel? This is not for a small table. It's huge and I probably need to do this for several PDF files. Manual input is out of the question. Thanks. \_ perl, Perl-PDF and Spreadsheet::WriteExcel -tom |
2005/6/21-23 [Computer/SW/Languages/Perl] UID:38230 Activity:high |
6/21 My math and/or perl fu is weak. Is there a way to get integer multiplication in Perl the way it's done in C? i.e. limiting to 32 bits. Like 1588635697 * 1117695901 = 1166976269 in C. \_ Can't you just multiply and then mask all but the last 32 bits? \_ I don't think so; that's not the same as mult overflow. > perl -e 'print (1588635697 * 1117695901)' > 1.77561160671918e+18 > perl -e '$foo = (1588635697 * 1117695901); printf("%u",$foo)' > 4294967295 > perl -e '$f=(1588635697*1117695901)&0xffffffff;printf("%u",$f)' > 4294967295 I guess I could call C from perl but I'd rather not. Or construct my own slow 32-bit binary multiplier in Perl, haha. \-ObUseLISP \_ People sometimes give me a hard time for disliking Perl, but I really do feel it's not a well-designed programming language. This is one example of why. Most other high level languages have a notion of a native integer and native floating point type. Lisp and ML languages certainly do. By the way, what you want to do is 'use integer;'. In other words: perl -e 'use integer; $f=(1588635697*1117695901);printf("%u",$f)' -- ilyas \_ Perl never claimed to be strong computationally. It's a text munging engine at its core. That "use integer" is required isn't all that surprising. \_ Neither Lisp nor ML claim to be strong computationally either (they are both meant for symbolic processing). This does not stop them from having good design, and a GC that doesn't leak. Matlab, which is often used for numerical tasks, has a base numeric type that is a complex-valued matrix! This excuse is neither here nor there. Perl's poor quality coupled with Perl's popularity really lowered consumer expectations, I feel, which is a pity. -- ilyas \_ Thanks, that works... except I had to play around a bit. For example this case doesn't work: perl -e 'use integer; $f=1117695901*(3177271395/2); printf("%u",$f)' > 137188522 The division seems to throw a wrench in it. But it works if I put only the multiplication in a block by itself, with 'use integer' there. I'm not sure I trust this thing. \_ how do you get the C-integer behavior in Lisp? \_ Lisp, by default, uses bignums in case of overflow, but it is possible to get around this with some syntax verbosity, for instance in cmucl: (defun f (x y) (declare (optimize (safety 0))) (declare ((unsigned-byte 32) x y)) (the (unsigned-byte 32) (* x y))) (print (f 1588635697 1117695901)) There's probably a shorter way, but I don't care enough to find it. At least it does the Right Thing always, unlike Perl above. Notice that Lisp treats this issue as one of type safety -- setting the safety knob to 0 forces it to use the unsigned 32 bit integer type for the result even if it cannot prove the result will 'fit.' -- ilyas \_ well those people are idiots. Perl is not a programming language, it's a bunch of ugly hacks that look like a programming language. The fact that Perl is so popular is not so much that it is intuitive or has features of good languages, but the fact that it has one of the most comprehensive libraries out there. I hate Perl, but I also hate writing stuff in Java or scripts where I need to build or find my own CGI lib, XML parser, code generator, sql mod, and all the extra nice things that are readily available on Perl. \_ You should give Python a try. It has plenty of drawbacks, like any interpreted language, but its a million times better than Perl IMO. And you get a huge set of the aforementioned bells and whistles that are roughly comparable to what Perl has. Note that one of the first complaints about Python is usually its use of whitespace as a block delimiter, so if you can't get past that you're probably SOL. \_ I feel Python is a poorly implemented, inelegant Lisp with decent library support. See Norvig's essay on this subject. -- ilyas \_ From Norvig's site: "The two main drawbacks of Python from my point of view are (1) there is very little compile-time error analysis and type declaration, even less than Lisp, and (2) execution time is much slower than Lisp, often by a factor of 10 (sometimes by 100 and sometimes by 1). Qualitatively, Python feels about the same speed as interpreted Lisp, but very noticably slower than compiled Lisp. For this reason I wouldn't recommend Python for applications that are (or are likely to become over time) compute intensive. But my purpose is oriented towards pedagogy, not production, so this is less of an issue." Overall from what I can tell, he seems to *like* Python despite these objections, and his main objection seems to be that you can't compile it. I've done tons of useful production work with Python, so while I see where he's coming from I don't see the practical downside of his complaint. I can see why a computer scientist might object to Python, though. \_ You have to understand that Norvig works at Google now, and Google has standardized on Python, like it or not. I am not really familiar with internal politics over there, but it wouldn't surprise me if he was somewhat pressured to not hate Python too much. I feel scheme + SICP is the best pedagogy tool for CS. There are a lot of really clunky things about Python I don't like, but then again, that's true of most languages. That's why I want to roll my own one day. Also, the kinds of things I like in programming languages are fairly obscure, hard to explain and verbalize things. -- ilyas \_ Well, roll your own then. It's actually pretty easy these days. Jim Gray is quoted as wondering why everyone isn't doing it. \_ Writing is easy. Designing is hard. -- ilyas \_ "A poorly implemented, inelegant Smalltalk with decent library support," is probably a more accurate description of the language. - ciyer \_ How do you feel about ruby? -aspo \_ Yeah, ruby is a new take on smalltalk (dynamic typing, everything is an object). Python resembles lisp more than smalltalk. -- ilyas \_ So. What do you think about ocaml? \_ I don't like ocaml as much as I once did. It's a good implementation (which is rare), but I have been finding design problems. E-mail me if you are interested in a serious discussion rather than half-hearted trolling attempts. -- ilyas \_ Foolish me for thinking that perl used bignums instead of magically converting ints to floats. -pp \- people who think perl is good as opposed to useful typically have not been exposed to something actually good. while one can debate what is the "Right Thing" it's pretty pointless to debate what somebody else finds useful. i use perl now and then but at the back of my mind i am always a little nervous because of all the things it is doing behind the scenes [to allow sloppiness] which i dont understand. although admittedly i havent seen perl do too many really crazy things since perl 4 [where you would hit crazy implementation as opposed to design bugs like you would reorder a case statement and all of a sudden perl core dumped. it's funny how berkeley unix was the example of "worse is better" in the famous "essay" and now BSD Unix is sort of the gold standard. \_ psb, did you write some Open Source polynomial solvers in Lisp? I came across some code by a "psb" at my last job. \- um, i did write some stuff for MACSYMA a while ago. this was sort of pre-open src so it was more like i threw it out there. this actually indirectly came out of a ucb linear algebra class. a dumbass friend of mine brought us what he said was an extra credit homework problem, but turned out sort of a hard problem [maybe a Knuth 42] and this lead to some useful stuff being written. the only place i was aware this was being used was IBM. \_ My favorite thing that Perl got wrong is their garbage collector, which leaks on cyclic data structures. There is even an AI koan about this very subject. -- ilyas \_ point is valid. Luckily, most Perl programs like CGI/PHP don't persist too long. Perl doesn't scale well for real huge programs. \_ Is that a GC bug or a result of the way it was designed? \_ It was designed that way. -- ilyas \_ It was designed that way. See koan #2 here: http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?AI+koan -- ilyas |
2005/6/7-8 [Computer/SW/Languages/Perl] UID:38010 Activity:nil |
6/7 Who the hell is toshi? 92998 toshi -22 0 21652K 7340K swread 0:04 1.60% 1.56% perl 93677 toshi 60 0 22400K 11632K RUN 0:03 1.92% 1.51% perl 92893 toshi 62 0 25020K 7788K RUN 0:09 1.80% 1.42% perl 93173 toshi 62 0 25060K 17216K RUN 0:07 1.22% 1.22% perl 93020 toshi 63 0 25048K 15072K RUN 0:08 1.17% 1.17% perl 92957 toshi 62 0 25028K 11168K RUN 0:08 1.03% 1.03% perl 92988 toshi 61 0 25020K 9380K RUN 0:08 1.30% 1.03% perl 93074 toshi 61 0 25028K 15584K RUN 0:07 0.98% 0.98% perl \_ Isn't he the dinosaur that Mario rides? \_ nah, that's yoshi \_ Yeah, was Toshi the evil cat-child in 'The Grudge'? \_ I think you mean Toshio, though I don't speak Japanese so for all I know that might functionally be the same. \_ http://www.toshireagon.com |
2005/4/29-5/1 [Computer/SW/Languages/Perl] UID:37411 Activity:moderate |
4/29 I need help getting information off a web site. A page presents information about an item in locations spread througout the page. Each page presents information about one item. What is a quick and easy way to go through several pages, capture all the information related to each item, and put them into a spreadsheet with a unique index? I think this might be possible by scraping the screen, but how does one go about this from a Windows workstation (with no app servers)? Would it be easier to record a bunch of copy and paste actions with automation / macro recording software and replay the macro? \_ On a windows machine with dotnet you can just simply write the whole thing in a couple lines of C Sharp. They've even got a snarf util in the O'Reilly book. \_ perl. -tom \_ Typical Tom answer. Tom, when you dont know much about something, why don't you leave it for others to answer? \_ what do you mean? perl is a fine solution. -tom \_ WWW:Mechanize is a valid suggestion. "Use perl" is a step away from "write a prgrogam." Sad you can't see this. \_ If you know anything about perl, you know there's more than one way to do it. I wouldn't use WWW::Mechanize, though that's certainly a reasonable approach. -tom \_ more specifically, WWW::Mechanize is useful -dwc \_ Python's urlib module does this quite easily also. -scottyg |
2005/4/13-5/25 [Computer/SW/Languages/Perl, Computer/SW/SpamAssassin] UID:37167 Activity:nil |
4/14 Perl upgraded to 5.6.2. SpamAssassin (spamd/spamc) upgraded to 3.0.2. moria (and angband, and NPPAngband) installed, for all you really old-schoolers. |
2005/4/4-5 [Computer/SW/Languages/Perl] UID:37058 Activity:nil |
4/4 entry-level whitebox testing job at hot startup, involving crazy Big Brother type technologies. Email brain for details! Have a resume and be prepared to code C++, Java, and possibly perl. Code is more crucial than QA skills; I'll show you that part. -brain \_ big brother in a good way or in a bad way? of course, how could it be in a good way? \_ I think he means the s/w called Big Brother, which monitors the health and status of systems. \_ Problem solving is the more important part in any QA. (Person who is doing Sr QA and deals with programming QA types outsourced to Russia who can perl like a demon but can't understand testing worth a damn.) \_ Developers who can't write their own functional and unit tests are dangerous and not to be trusted. |
2005/3/25-29 [Computer/SW/Languages/Perl] UID:36872 Activity:nil |
3/25 In Perl, how do I specify a SIGHUP and SIGKILL handler? I want to clean up stuff when I press CTRL-C on my Perl script. -ok thx \_ RTFM. Look for %SIG in "man perlipc" \_ STFW: http://www.unix.org.ua/orelly/perl/cookbook/ch16_16.htm \_ Above trolls should STFU. \_ Methinks you need to STFW for the definition of "troll" \_ ROFL LOL, WTF!? |
2005/3/24-25 [Computer/SW/Database, Computer/SW/Languages/Perl] UID:36846 Activity:nil Edit_by:auto |
3/24 How do I do non-blocking read in Perl? For example, let's say I do open(FD, "tail -f file.log |"); And I'd like to read it, but not block it. Can that be done? -ok thx \_ Yes. You need to use fcntl to mark FD as non-blocking and then you need to use select and sysread to read from FD. \_ http://www.unix.org.ua/orelly/perl/advprog/ch12_03.htm http://www.unix.org.ua/orelly/perl/cookbook/ch07_15.htm Bottom page, very useful Open the file with sysopen, and specify the O_NONBLOCK option: use Fcntl; sysopen(MODEM, "/dev/cua0", O_NONBLOCK|O_RDWR) or die "Can't open modem: $!\n"; If you already have a filehandle, use fcntl to change the flags: use Fcntl; $flags = ''; fcntl(HANDLE, F_GETFL, $flags) or die "Couldn't get flags for HANDLE : $!\n"; $flags |= O_NONBLOCK; fcntl(HANDLE, F_SETFL, $flags) or die "Couldn't set flags for HANDLE: $!\n"; Once a filehandle is set for non-blocking I/O, the sysread or syswrite calls tha\ t would block will instead return undef and set $! to EAGAIN: use POSIX qw(:errno_h); $rv = syswrite(HANDLE, $buffer, length $buffer); if (!defined($rv) && $! == EAGAIN) { # would block } elsif ($rv != length $buffer) { # incomplete write } else { # successfully wrote } $rv = sysread(HANDLE, $buffer, $BUFSIZ); if (!defined($rv) && $! == EAGAIN) { # would block } else { # successfully read $rv bytes from HANDLE } |
2005/3/4-6 [Computer/SW/Languages/Perl] UID:36520 Activity:high |
3/4 Rave: Chapter Two of Damian Conway's Object Oriented Perl is hands down the clearest exposition I've ever read of perl modules, namespaces, references, as well as local vs. my. I wish I'd read it sooner. Well worth the just over $20 to get it as a PDF, and I will probably drop the $40 or $50 needed for the dead trees edition. Two pages later, it also features the clearest exposition of closures I've ever read, and I'd highly recommend it to anyone taking 61A in order to help get your head wrapped around the magic that is lambda. -dans \_ sometimes you can find editions cheap on amazon used books. \_ Can I give you $10 and you mail me a copy of the pdf? -poor student \_ 26$ for a "like new" used hardcopy from amazon. \_ You can easily get a copy off of emule for free. \_ Are you really so poor that you can afford $10 but not $20? That's two, maybe three trips to La Burrita. Also, seeing as I like Conway's work, I'd like to see him get paid and perhaps write more at a later date. Why don't I arrange to donate a copy to the CSUA library? -dans \_ What I find depressing is how many people seriously don't see a problem with paying money for IP they like, and stealing IP they don't like. As if their subjectivity is any yardstick to measure people's rights by. Or, if you like, as if stupid people didn't have the same rights as everyone else. -- ilyas \_ Fair enough. Do you pay for your copy of Windows and every single warez you've had in your life? \_ Yes, my copy of windows is paid for. I do not 'own' any warez, and never have. Why must you assume everyone is as much of a scumbag as you? -- ilyas \_ I don't know aobut ilyas, but the one copy of Windows I've ever used was legit (paid for by my company). I also paid for all the software I currently use on my Macs. Most of my other systems run either Linux or BSD, and I don't have any commercial software on those systems. At one point in my life (10+ yrs ago) I did have some commercial software (mostly games, though I don't think I ever had a license of MacDraw) on my MacSE, think I ever had a license for MacDraw) on my MacSE, but back then when you bought a computer you just assumed that the stuff on the old hd was yours. \_ Not only would this be illegal, it is also just plain wrong. As a published author, nothing bugs me more than people who feel that they somehow have a right to STEAL your work w/o compensating you for it. If everyone was like you and refused to pay for books, the incentive to write (what little there already is - a tech author may get ~ $2 per copy sold) will completely disappear. Who wants to waste their nights and weekends (most of us need real jobs b/c writing tech books doesn't come close to paying the bils) if there would be no benefit beyond some minor recognition on one's resume? If the book helps you out, PAY FOR IT. </rant> \_ I buy most of my technical books used. This is legal, however the author still doesn't get any money. What do you think of that? If authors asked used buyers to send them a couple bucks, I'd do it, but I've never heard of such a system. \_ I buy most of my technical books used. This is legal, however the author still doesn't get any money. What do you think of that? If authors asked used buyers to send them a couple bucks, I'd do it, but I've never heard of such a system. \_ I have no problem w/ used books. The original purchaser has already compensated the author. Once they bought the physical book (or electronic copy), they can sell it or give it away to someone else assuming that they do not retain a copy for their own use. \_ Just for shits and grins, why don't you try putting a message in the next edition of your book that says "If you really love this book and find it useful send me a dollar" and see what happens. |
2005/2/25-27 [Computer/SW/Languages/Perl, Computer/SW/Languages/Python] UID:36415 Activity:low |
2/25 Any python guys on the motd? I'm trying to find a python equivalent to $/ (the perl input record separator) so that I can parse a file with odd record separators (ie, not \n). The data I got on google suggests that no such thing exists, but those posts were from 2003. Has support for this been added of late? \_ string.split('record_sep_char') I think. \_ Problem with this is having to read in data blocks from the file, because otherwise there's an implicit split on \n (which my records contain). \_is the file really big? f = open("/usr/dict/words") f.read().split('record_sep_char') I'm curious too if there's a better answer \_ I don't do much work in Python so I don't know if this will actually work, but my copy of Python in a Nutshell mentions the os module has an attribute linesep which is set to '\n' on Unix and '\r\n' on Windows. What happens if you try to set that attribute to your desired separator before sucking in your file? -dans |
2005/2/17 [Computer/SW/Languages/Perl] UID:36220 Activity:high |
2/17 This *has* to exist: I'm working w/ a text file that uses ascii #2 for record separators and ascii #1 for field separators. Is there a utility that will print out these ascii values for me, so I can (for example) use them with command line awk and perl scripts? Ex: fs=`atoi 1` perl -pi e's/(.*)$fs(.*)/$1$fsfoobar/g' myfile.txt Also, what would the actual perl syntax be for what I'm trying to do with the above command? Platform is OS X. TIA \_ perl -002 -a -F'\001' -lpi -e '$_="$F[0]foobar"' myfile.txt OK, this sets in the input record separator to #2 (instead of newline), sets the field separator to #1, strips the \002 from the input and readds it on output (-l) and autosplits into @F on \1 --dbushong \_ What about a function that just prints an ascii code - printf("%c", atoi(argv[0])); would be fine, it just seems ridiculous that this doesn't already exist. \_ In most shells, you can press ^V before a keystroke and have that keystroke inserted literally, without being interpreted by the shell. Thus, ^V^A would produce a literal ^A (ASCII code 0x01), and ^V^B would produce a literal ^B (ASCII 0x02). Alternatively, try fs=`echo -ne '\001'`. -gm \_ Ah, that works very well, thank you. I also discovered the perl function chr, which takes an int and returns the associated ascii character. \_ I think you meant argv[1], there, buddy. Anyway, it's trivial, so why don't you write it? \_ You're correct, and yes it's trivial, but so is the command "yes" which repeatedly prints out "y" forever. The thing is, I need to have other people run this script for me, and I don't want to waste their time with "ok, now run gcc -o asciify asciify.c" if asciify already exists. |
2005/1/19-20 [Computer/SW/Languages/Perl] UID:35796 Activity:nil |
1/19 What's the difference between regular threads and threads created with async in Perl? |
2005/1/16-17 [Computer/SW/Languages/Perl, Computer/SW/Languages/Web] UID:35734 Activity:high |
1/15 What's the easiest/best thing to use to quickly create small GUI tools/apps for Windows? (cross-platform ok too) Like the equivalent of a perl script with a Windows GUI. Only for myself right now but I need to decide what to invest my time learning. So it might as well be cross platform if there's no big downside. I have hardly any experience with GUIs. Thanks. \_ I have the same question but maybe not for a perl script, also the GUI can be as simple as possible. \_ perl/tk is decent, though you might want to look into VB if you want to interact with the os. I'd advise staying away from Java at all costs. --darin \_ ya, sounds like VB is what the op is looking for. \_ Is VB cross platform? \_ and free? :( -op \_ Performance aside, why no Java? \_ http://wxperl.sourceforge.net There's also APIs into wxwindows for Python and other languages. I think it's what the original windows version of BitTorrent is written in. --dbushong \_ Ok I started playing with wxruby so I'll see how that goes, even though it's beta. found at http://wxruby.sourceforge.net. |
2005/1/12-13 [Computer/SW/Languages/Perl] UID:35680 Activity:low |
1/12 How can I email a group of people individually if I have a list of their email addresses and names, and I want each email to begin with a personalized greeting (e.g. Dear Mr. A) Any platform is ok. Thanks. \_ write a script. \_ This used to be called "mail-merge" in the days of paper mail which needed to be printed. I'm sure a similar functionality exists within most modern day email programs for something like this, especially Microshaft Outlook. \_ Oh please don't be a spammer. \_ don't worry, I'm not; it's for school. -op \_ anyone here work for a spam company? \_ perldoc Net::SMTP The remainder is left as an exercise to the reader. -dans |
2005/1/12 [Computer/SW/Languages/Perl] UID:35671 Activity:nil |
1/11 What does the @{ } syntax mean in Perl? As used in "man perldsc". Oh nevermind I just read about references. Perl sucks. \_ It's accessing an array, like @foo. The expression inside the braces should evaluate to an array reference. See "man perlref". \_ Yeah I just found that, thanks. |
2005/1/11-12 [Computer/SW/Languages/Perl] UID:35668 Activity:moderate |
1/11 FIX YOUR SPAMASS 3293 root 60 0 22512K 16640K RUN 42:15 12.74% 12.74% perl5.005 2610 root 60 0 22328K 8036K RUN 277:52 12.60% 12.60% perl5.005 amirs 3293 12.7 2.1 22512 16640 ?? R 4:08PM 42:18.75 /usr/local/bi\ n/spamd -a -c -d -m 5 -r /var/run/spamd.pid (perl5.00503) s etol 2610 10.9 1.0 22328 8036 ?? R 3:29AM 277:55.77 /usr/local/bin\ /spamd -a -c -d -m 5 -r /var/run/spamd.pid (perl5.00503) \_ pretty sad that spamass can run out of control like that \_ It is. It might also be the fault of the ancient perl we're running it on. \_ I dunno, the docs I read specifically warn against running spam assassin on large emails. (>250K) \_ I switched from spamd to spamass after spamd kept dumping huge cores in my home directory, putting me over quota. Has this problem been fixed? \_ I dunno, did you ever tell root that that was happening? \_ No, I just switched to using spamassin directly. |
2005/1/11-12 [Computer/SW/Languages/Perl, Computer/SW/SpamAssassin] UID:35663 Activity:nil |
1/11 How do I set up a spam filter without hosing soda with perl processes? (something running on soda, not in my Windoze e-mail client) Thanks! \_ The best you can do is to run spamc (which uses the shared spamd daemon) instead of running spamassassin directly. |
2004/12/29-30 [Computer/SW/Unix, Computer/SW/Languages/Perl] UID:35476 Activity:kinda low |
12/29 Is there a command like 'tail' that will read a file backwards? Tail does not do what I want because of a limited buffer size. I want to read the *ENTIRE* file backwards. Less doesn't work because it relies on line numbers and the file is corrupted. (Essentially, I can read 1-n and n+EOF lines but n itself is corrupt.) More/less lets me read 1-n, but tail won't let me go back far enough. (tail -100000 and tail -3000 are equivalent because of the buffer) \_ you could pipe it through a perl script that reads the file backwards, i can write a multi line one, maybe one of the perl geeks around here will post a 1-liner. \_ Thanks! I found a PM called File::ReadBackwards that worked. \- hello, you can use the "tac" command or sed '1\!G;h;$\!d' --psb \_ Tac looks cool, but seems to be a Linuxism. It's not on soda, for instance. (Yes, it could be ported.) \-tac is a random hack that probably predates linux. portability is why i added the sed cmd. --psb \_ if you use 'less +G' it doesn't actually try to figure out line numbers, it just goes to the end of the file. You can then scroll back ward normally. -ERic \_ I tried this and it did not work. I went to the end of the file, but when I tried to scroll back it attempted to calculate line numbers even when told not to. |
2004/12/29 [Computer/SW/Languages/Misc, Computer/SW/Languages/Perl] UID:35468 Activity:moderate |
12/28 Does anyone have a good (free) program for converting .ogg to .mp3? Either for Linux or Windows. \_ CDex \_ Download the official Vorbis tools and then use oggdec + LAME. \_ Not recommended for Windows. On linux it's a one line perl script. \_ Why is this not recommended for Windows? Can't you use a one-line Perl (or even .bat) script there too? \_ Because the Windows CLI is a piece of crap. Yes, you can install cygwin, but by the time you go through the song and dance of installing cygwin you could've already converrted your ogg vorbis files to mp3 already with CDex. Not only that, unlike Linux you can't simply install an RPM/DEB or emerge in gentoo lame and oggdec. You have to manually download each piece of software and unzip it and path the directories correctly. It's just a hassle. I mean, if you really want to write a batch file go right ahead, but why bother? |
2004/12/17-19 [Computer/SW/Languages/Perl] UID:35343 Activity:high |
12/17 I am doing some simple subtraction on perl, and its generating output like 8.39999999999998, how do I fix this? Thanks. \_ Omg. I can't believe people ask this shit. Did you graduate from Cal with a CS degree? You are a fucking disgrace. \_ There are a significant number of non-CS majors here. \_ There IS a significant number. Fucking disgraces, all of you. Ugh. Go die. \_ Wrong, dumbass. "A number of ___" is a plural noun. "Are" is correct. Fucking disgrace. \_ Agreed. \_ you fix it by giving us example code or int($num + .5) \_ I am doing something very simple, reading some numbers into a variable, and subtract them. in my case, the number is 595 - 586.84, which should give me 8.16, but perl output 8.15999999999997, I need 8.16.... thanks... \_ Like the poster below said, numbers like 8.16 can't be represented exactly in binary, so you'll always get some error. You can use $num = sprintf("%.2f", $num) to force $num to have exactly two digits after the decimal point -- this also means that 8.5 will become 8.50, which is usually what you want if you're dealing with money. \_ And what is the precise binary representation of .84 pray tell? \_ Math::BigFloat \_ If there's a specific precision you want, use fixed-point math or round. |
2004/12/14 [Computer/SW/Languages/Perl, Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Misc] UID:35286 Activity:insanely high |
12/13 http://khason.biz/blog/2004/12/why-microsoft-can-blow-off-with-c.html Why Microsoft Can Blow Off with C the Language (humor/funny) \_ not really. -tom that's because tom holub is the anonymous humourless nuker _/ \_ Feel the babelfish flow through you. \_ Any body who thinks Fortran hasn't seen widespread acceptance hasn't spent much time outside of the world of software development and systems administration, methinks. Out where I do my civil engineering thing, Fortran is the standard langauge. -- ulysses \_ Not the law is clear? There is a beard - there is a success. There is no beard - you are guilty. |
2004/11/30-12/1 [Computer/SW/Languages/Perl] UID:35129 Activity:nil |
11/30 Perl question, I want to make a sub do_these which when called as do_these(('foo','bar')); will call foo() and bar() will something like foreach(@_) { &$_(); } work? \_ Yup. If you get an error about "strict refs", add the line "no strict 'refs';" at the beginning of sub do_these. --mconst \_ I'd suggest looking through hoserchat source code (locate hoserchat on soda) and look at how the function pointers are done there. \_ mconst says I'm good to go, but the way hoserchat does it is to use function references, not dereferenced fuction names. Is this a TWTOWTDI situation, or is it illegal to dereference a function name, since $_ will after all be a string? \_ TMTOWTDI. Real references are sometimes safer: they work regardless of what package you're in, and they keep working even if the original function gets renamed or undefined. (That's why "use strict" disables the ability to use a function or variable name as a reference.) It's usually not a big deal, though. The cool thing is that your code will actually work either way -- if you want to use real references, just call do_these(\&foo, \&bar) instead. --mconst \_ OK, because I'm calling specific instances of a class function (probably should have mentioned that) I actually needed to use $self->$_ in do_each(), as &$_() just gave calls to member function of an uninstantiated class. All in all, thanks a bunch to both of you. -op |
2004/11/24-26 [Computer/SW/Languages/Perl] UID:35061 Activity:nil |
11/24 I was looking at the Perl CGI.pm and I noticed that most of its functions existed only as source code stored in a big hash of %SUBS = (sub_name => 'sub source') What's the reason for doing this? \_ They compile the functions on demand, to reduce startup time. \_ So if you make repeated calls to some of these functions, will you see much of a performance hit? \_ Nope -- once CGI.pm compiles a function, it becomes an ordinary perl function with no extra overhead. On the other hand, even that single compilation is a waste if you're using something like mod_perl that precompiles your code, so CGI.pm does have an option (-compile) to disable the hack and just define everything at compile time. --mconst |
2004/11/22-23 [Computer/SW/Languages/Perl] UID:35028 Activity:kinda low |
11/22 How do I get find to return me a list of files with every questionable character escaped by a backslash? ', ", ?, <space>, etc are "questionable" \_ find . -print0 | perl -0pe 'chop;s#[^\w/.,-]#\\$&#g;$_.="\n"' (assumes you have perl and find which supports print0; both common on modern boxes; also i specified the list of "OK" characters rather than questionable ones; i think it's safer; note also that -print0 by itself may have been what you were looking for, since this will possibly give you results like this: file\ with\ newline\ in\ it.txt (the newline is blackslashed, but that may or may not help you) --dbushong \_ Pipe it through perl -ne 'print quotemeta $_' \_ Pipe it through perl -ne 'print quotemeta $_' --scotsman \_ or just perl -pe 'print quotemeta' \_ Er, no. perl -ne 'print quotemeta' \_ Er, no. perl -ne 'print quotemeta' --scotsman \_ perl -pe '$_=quotemeta' -geordan \_ Actually, perl -pe 's/./\Q$&/g' -geordan \_ That's slick, but the newline issue applies there. --scotsman \_ I guess perl -pe 's/./\Q$&/gs' would fix that, but it's still just getting escaped. -geordan \_ This doesn't work if any of the files have newlines in their names. --dbushong \_ Well, it escapes it, just as yours does. --scotsman |
2004/11/22 [Computer/SW/Languages/Perl] UID:35012 Activity:very high |
11/22 Dear Perl monkeys, how do I match a substring at the end of a string? I want to match '.txt' but not '.txt.gz' or similar. -thanks Something like if($filename <ends with> @valid_extensions) {} \_ $ext = join '|',@valid_extensions; if ($filename =~ /\.($ext)$/) { ... } # -geordan |
2004/11/19-20 [Computer/SW/Languages/Perl] UID:34983 Activity:nil |
11/19 I don't want logwatch to tell me that there were "134 messeges sent" but I would still like to have it parse the maillog file. I can comment out the line in the perl script in "scripts" but that doesn't seem clean. Same with it telling me that my user has logged in. I know my user logs in; can I tell it not to watch for me? Is there a way to modify the .conf files in services to tell it not to send this info? I've searched around a lot for this and can't find anything. <DEAD>logwatch.org<DEAD> just has the man page for docs. If anyone knows of some more extensive logwatch docs on-line, it would be appreciated. |
2004/11/16 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:34922 Activity:high |
11/16 "sed '/^[0-9].*$/\!d' inputfile" will print out only the lines of a file that start with numbers. Supposed I want to print out the 1st, 6th, 10th, 16th, etc lines that begin with a number. How can I do that elegantly with sed or perl or whatever? \_ perl -ne 'print if /^\d/ && $count++ % 5 == 0' --mconst \_ You can replace all the newlines with a new record separator (eg "FOO") and then awk '{print $1, $6, $10, $16}'. \- to do this either you need to understand a little bit about how sed works and then write a little sed program OR if you want a cryptic one liner, it heavily depends on the version of sed ... i cant think of a simple way to do this in "genreic sed" ... i assume your list doenst end at 16 ... that is trivial. i think gsed supports the +5d operator. --psb \_ perl -ne 'print if /^\d/ && <compare $. as line #>' file the compare could be e.g.: $. =~ /^(1|6|10|16)$/ --dbushong \- if all you want to do is print out those 4 lines it is ' trivial ... sed -n -e '1p;6p;10p;16p' --psb \_ This has to work for a file that is 100000 lines long. That's what I meant by etc. I would have thought there would be an elegent way to basically tell it to print the first line, skip the next n lines, print the next line, skip the next n lines, etc. -op \_ Is n 5, 4, or 6? |
2004/11/8-9 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:34742 Activity:low |
11/7 Is there a shell command that will unsort (randomize) a file, like the way sort does on a line-by-line basis? I don't need any mathematical randomizing, just want to mix up my input lines occasionally. tia. \_ ~mconst/bin/shuffle \_ i have some short code to do this. if the file is "large" [+32k ll] it's somewhat tricky to do ... need a good random generator. like perl's default doenst have enough seed values. why do people ask stuff like this anonymously? --psb \- this looks really slow to me: /bin/time ./rand-mconst.pl < /tmp/infile > /dev/null real 46.9 /bin/time ./rand-psb.pl < /tmp/infile > /dev/null real 4.3 \_ What do you expect? One's an algorithm, one's a one line hack. \_ my stupid shell script that works fine for small files: #!/bin/sh awk 'BEGIN { srand() }{ print rand(),$0 }' $1 \ |sort|sed 's/^[^ ]* //' \-I dont think this is portable to "classic awk" ... but gawk is probably good enough. --psb \- btw, i just stumbled, er shuffled, on to: perldoc -q shuffle --psb |
2004/11/1 [Computer/SW/Languages/Perl] UID:34491 Activity:kinda low |
10/31 I've got a file full of names of mp3 files that I want to delete. Problem is that many are contain ', (, ), and other unlikeable characters that make it hard to feed to a bash for loop or a perl script. Is there any (perl?) function to autoescape that sort of thing? tia. \_ Why not run the file through sed? \_ perl -lne unlink filename.txt --dbushong |
2004/10/28-29 [Computer/SW/Languages/Perl] UID:34404 Activity:nil |
10/28 Has anyone had trouble building SpamAssassin 3.0.1 on RH 9? It seems to have major problems, and I can't tell if it's SA's fault or Redhate's. perl Makefile.PL yields a Makefile with stray single quotes and truncated lines. google searches yield no help. --scotsman \_ No idea about that in particular, but can you generate the makefile on some other system and copy it in? \_ doesnt answer your question (this IS the motd) but it worked out of the box for me on Solaris 9 and Gentoo 2004. Instead of using the makefile, i ran: perl -MCPAN -e'install Mail::SpamAssassin' |
2004/10/15-16 [Computer/SW/Languages/Perl] UID:34153 Activity:nil |
10/15 In Perl, what does $| = 1; mean? \_ Flush write buffers after every write \_ Flush write buffers after every write -scotsman \_ why the strange syntax? \_ There are many perl switch varibles. There are also named aliases for almost all of them. read the perlvar manpage for some mnemonic help -scotsman \_ Perl has no other kind. -- ilyas |
2004/10/11-13 [Computer/SW/Languages/Perl] UID:34038 Activity:nil |
10/11 Perl web programming job at AmBusi. See /csua/pub/jobs/ambusi. -ali \_ how much they pay nowadays and how's the job market? |
2004/10/7-8 [Computer/SW/Languages/Perl, Computer/SW/OS/Windows] UID:33976 Activity:high |
10/7 What is the best free mass-renaming application for windows? -thanks \_ cygwin \_ perl \_ "ren *foo *bar" in Command Prompt. \_ don't do that. \_ why not? \_ It would be bad. \_ "Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light." \_ <gulp> Total protonic reversal. |
2004/9/29-30 [Computer/SW/Languages/Perl] UID:33841 Activity:nil |
9/29 How do I use perl to delete some registry setting? such as HKCR\Something. I want to automatically nuke the entry... Thanks... \_ From the 1st google result for 'perl registry' http://jenda.krynicky.cz/perl/Registry.pm.html Load the Win32:Registry module and go from there... |
2004/9/24 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:33738 Activity:insanely high |
9/24 I have a directory with a bunch of image files names DSCNxxxx.jpg. What's the quickest way to rename them all to Dscnxxxx.jpg? (just changing the capitalization of the first 4 letters). \_ foreach i (*.jpg) mv $i `echo $i | sed -e s/DSCN/Dscn/` end I'm a hardware engineer and even I can come up with something \_ You're assuming the OP has csh access to the directory. \_ Okay, the why don't you just "dir" the files to a text file, send it to your soda account, write a script to change the names (DOS batch file), and viola. \_ ObCygwin \_ I'm looking for a one-liner that actually works... this gives me "i: Undefined variable.". This is on linux and I do have csh access. The perl suggestion below is a good idea but it's overkill for what I'm doing right now. -op \_ In Perl: #!/usr/local/bin/perl # # Usage: rename perlexpr [files] ($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n"; if (!@ARGV) { @ARGV = <STDIN>; chomp(@ARGV); } foreach $_ (@ARGV) { $old_name = $_; eval $regexp; die $@ if $@; rename($old_name, $_) unless $old_name eq $_; } exit(0); Use 's/DSCN/dscn/' for the regex at the commandline or just modify the $regex variable. \_ Your OS? \_ What you want is a nice perl script that renames it to YYYYMMDD_HHMMSS_xxxx.jpg. This is the way to archive images. Besides the image, the time is the next most important thing, but with Windows and day light saving time and time zone, and that sometime you forget to set the camera's clock correctly when you travel, relying on file timestamp and exif time is really not a good idea. Embed the picture time into the filename is a permanent way to record the time of a photo. \_ If you are using 4NT, just do "ren DSCN* Dscn*" \-ls | awk '{print "mv " $1" "$1}' | sed 's/ DSC/Dsc//' | sh \_ This works in NT Command Prompt. You don't need 4NT. \-ls | awk '{print "mv " $1" "$1}' | sed 's/ DSCN/Dscn//' | sh --psb \_ you should just use gsub in your awk. \- as i said last time this came up on the motd, anybody asking a question like this isnt going to be familiar with complicated awk or sed, backrefs etc. So it's best to make something easy to modify. i suppose i should have used the nth match for sed. i would personally just do this in emacs. --psb |
2004/9/22 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:33693 Activity:moderate |
9/22 I have a form that posts a heap of text from textarea box to a Perl script that puts the info into a flat database file. I'm using $in{'mytext'} =~ s/\</</g; to change any html tags to harmless <>s, but how do I replace newlines with <br>? I've tried: $in{'mytext'} =~ s/^M/\<br\>/g; $in{'mytext'} =~ s/\^M/\<br\>/g; $in{'mytext'} =~ s/\n/\<br\>/g; and I'm still getting ^Ms in my file. Help! \_ ^M is \r, not \n. -tom \_ Aren't HTML form lines ended with \r\n like Windows? And doesn't Perl::CGI deal with this? \_ (responding to myself) yes, it's \r\n (CR LF): http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.2 \_ what would you want Perl::CGI to do with a textarea that contains newlines, other than put the newlines in the variable? -tom \_ I couldn't remember if the newline was platform- independent, but if it wasn't that CGI would have a plantform-independent method of splitting/replacing/etc. \_ This did the trick, thank you. |
2004/9/16-17 [Computer/SW/Languages/Web, Computer/SW/Languages/Perl] UID:33560 Activity:low |
9/15 Are there any opensource website management systems that will let you create a site similar to http://cnn.com ? PHPNuke and Slashcode might be able to work but doesn't seem to be quite right. \_ PHP: Midgard: http://www.midgard-project.org Perl: Mason: http://www.masonhq.com --dbushong \_ Sorry, I used the wrong term. I'm not looking for a CMS. I'm looking for a tool/app? that let's me create nice frontend templates can nicely display entries from either flat files or possibly, a CMS. midgard and mason both seem like a good start though. tnx. |
2004/9/9-10 [Computer/SW/Languages/OCAML, Computer/SW/Languages/Perl] UID:33448 Activity:high |
9/9 Why are there so much politics on the motd? Isn't this the CSUA? Doesn't the C stands for something computer?? \_ Its stands for Computer Stuff and Unrelated Arguing \_ Golf clap. \_ I didn't know there even was such a thing as a golf ho, and you're telling me they've got their own VD's? \_ Yeah, let's talk about computer, or girls!! \_ When someone says something stupid, I feel I must succinctly show them the error of their ways, or at least show other reasonable people. Oh well, I'll just let stupid people keep thinking that way. \_ The CSUA as an organization doesn't manage or have anything to do with the contents of motd.public. Politics get discussed so often because it's one of those things that never ends. You never finish the argument. And unlike more esoteric subjects for debate, politics is something that anybody and everybody feels qualified to participate in. Politics is always in the news. Other things show up on motd many times but nothing more than politics. Or Perl. \_ Hey, I would talk about programming languages, but not a lot of people care. P.S. Perl is morally wrong. -- ilyas \_ Methinks he doth protest too much. --dbushong \_ SILENCE, SINNER! \_ what do you think of ocaml? \_ Ocaml is a language built around a type inference system, and I think that's like the tail wagging the dog. The bar for languages is set so low that if people see something with lambdas that's fast they get excited. It shouldn't be that way. -- ilyas \_ Have you ever looked over Java? I've generally found the structure of the language really presents itself for large SE projects. The string manipulation elements built directly into the language are pretty awesome also -- they really cut down on the dev cycle, I've found. \_ Pontification is preferable to work. \_ it wasn't like this from 1980s till the late 90s, when the failed jobless laid-off dotcomers got bitter and started to rant. \_ Obviously someone who doesn't remember the bitterness of joblessness of the early 90s... |
2004/9/9 [Computer/SW/Mail, Computer/SW/Languages/Perl] UID:33427 Activity:moderate |
9/8 So, I asked this a few years ago, it seems there should have been some progress on this front: A calendar server for linux? Would be nice if it could work with outlook clients but not mandatory, would be nice if people could update their Cals from the web, would be nice if it was free. I'm looking at calcium which seems like http://www.brownbearsw.com has just taken their popular but kind of klunky (and not free) ical and ported it to perl. [spelld] \_ There exist a number of commercial products for Linux including probably the ones from IBM, Oracle, and Sun/iPlanet but I don't think they work with Lookout. \_ Isn't there something from Ximian that apes all the nifty Exchange stuff? Look around, there's quite a few things along these lines. I believe Outlook is also fairly flexible in how it synchronizes with various apps. For a nice web-based groupware, look at phprojekt. I have some others lying around, mail me if you want me to dig them out. -John |
2004/9/2-3 [Computer/SW/Languages/Perl] UID:33302 Activity:kinda low |
9/2 How do I use a variable expansion in perl regex? Something like $PATTERN = ".*foofoofoo"; $_ =~ s/$PATTERN//g; Basically I'd like a C #define style expansion of $PATTERN. TIA \_ The above should work. You might want to add the "o" flag to the s/// operator for efficiency if your $PATTERN doesn't change. \_ Also, you don't need to say "$_ =~ "; it's implied. |
2004/8/27-29 [Computer/SW/Languages/Perl] UID:33194 Activity:low |
8/27 How do I get perl to read in a hex value from a file and store it as an int? I basically want strtol for perl \_ int(hex($value)) should give you what you want \_ hex($value) should give you what you want |
2004/8/17 [Computer/SW/Languages/Perl] UID:32967 Activity:nil |
8/17 Is there a Maildir compatible equivalent of frm? \_ Third hit on Google for: frm maildir Come _on_ people http://www.eyrie.org/~eagle/software/mdfrm |
2004/8/17-18 [Computer/SW/Languages/Perl] UID:32966 Activity:high |
8/17 My sister is looking to learn perl, but she's not really a professional programmer. Can anyone recommend a decent perl book which isn't too complicated? TIA. \_ Learning Perl, 3rd Ed \_ Seconded. You might be able to get it for free after mir from fry's this week. \_ Just curious. What for? \_ Not really a professional programmer? Perl sounds perfect! \_ Riiiight. Whatever, man. |
2004/8/13 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:32883 Activity:nil |
8/12 I am not a techie but I am trying to learn some perl to do some text manipulation for my research. I am having trouble with hashes. Can someone give me an example of how to read in something like the password file (say, user, directory, shell) into a hash? \_ The question belies a slight misunderstanding of hashes. A hash is a simple set of key value pairs, so reading a password file in would require a bit of thought to the structure. You could make the key be uid and the value be a pointer to an array of the passwd line, i.e. (username,pw,uid,gid,gcos,hdir,shell). You could alternately key on username. You could make an array of hash references where each array member is like username => 'root', pw => '*', uid => 0, gid => 0, etc. But using a single 1-dimensional hash on something like an entire passwd file would yield you the data from the last line in the file. \_What would be the right structure to use to read in the whole password table and hold it in a structure so I could refer to some arbitrary piece of data like "the shell of user user1"? Like if I wanted to merge the encrypted password from the shadow file with the login and shell fields from the password file? Thanks for your explanation. \_ Now that you could do with a hash, but easier would be to use (getpwnam('user1'))[8] to get the shell. But to do this for the whole passwd file (as an example) would be open PW,'/etc/passwd'; my %shells; foreach my $pwentry (<PW>) { chomp $pwentry; ($name,$shell) = (split /:/,$pwentry)[0,6]; $shells{$name} = $shell; } close PW; Oh wait. I didn't catch the part about shadow password, but this should give you an idea of where to start. |
2004/8/11 [Computer/SW/Languages/Perl] UID:32831 Activity:high |
8/11 Is there any way a shell or perl script can can input from keyboard without showing it on the screen, such as for a password? \_ man getpass/getpassphrase and write a helper program, or look into using a curses library or similar. \_ stty -echo |
2004/8/6 [Computer/SW/Languages/Perl, Computer/SW/Languages/Misc] UID:32750 Activity:high |
8/6 On Linux, how can I find out how much space a directory takes up? (Including all it's files and subdirs, etc.) \_ du -sk . -tom \_ try windirstat (ok, it's not linux), it's awesome!! \_ on Linux we just take such things for granted (hint, du -k | sort -rn ) \_ windirstat is a lot more advanced than du -k. come on, this is no longer the 80s. \_ For each file, type ls -l. Copy that down in notepad.exe. Then write a perl script to take the input you save in notepad.exe, put a plus sign "+" inbetween the numbers and pipe it through the 'bc' command, take the output from 'bc' and print it out, send a fax of the photocopy of your printout to your boss's secretary asking her to ask him to approve the numbers, and don't forget that at each stage you should have the security department double check everything so you're not in a state of policy violation. \_ ~jameslin/bin/dirstat is a lame awk script I made awhile back to calculate this. --jameslin |
2004/7/27 [Computer/SW/Languages/Perl] UID:32492 Activity:high |
7/26 In Perl, s/.*/foo/g will match twice and produce foofoo but s/.+/foo/g only once and produces foo. Why? \_ Maybe because .* means zero or more, so it matches the zero too? \_ .* first matches starting from the beginning of the string until end, consuming all the characters. Then it tries to match the empty string at the end of the string, and succeeds since it will match 0 characters. .+ does not match 0 characters, so it does not match the empty string at the end. |
2004/7/5 [Computer/SW/Languages/Perl] UID:31164 Activity:high |
7/4 Is there something like a macro in Perl? Couldn't find any in the Camel book. \_ If you truly need macros in Perl, you probably want AUTOLOAD. Of course, if you truly need macros, Perl is the wrong language for what you are doing. -- ilyas \_ I don't know perl, but don't almost all interpreted languages have some kind of eval function? If so, you don't really need macros; you can build up a string and evaluate it. \_ There is eval in perl, and yes I know I can use eval, but it is highly inefficient as the same code gets recompiled N times. \_ Standard motd answer: tell us what you're actually trying to do and we'll tell you the right way to do it instead of what you think you want to do. \_ What I want to do is pretty simple. Assume Perl had #define then what I want to do would be like #define myMacro(a) if (flagP) {a} else {foo} Basically I want macro as a time saving device, rather than than the all powerful macro featured in Lisp. \_ Why don't you just run your Perl source files through the c pre-processor? \_ Would cpp conflict with Perl's grammar? |
2004/6/29-30 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Perl] UID:31060 Activity:high |
6/29 I can't remember a bit of C syntax. I have funtion foo that returns a value that I need to put in a variable. If that value is not Null, I want to take some action. Will this work? int bar = 0; if(bar = foo()) do something; \_ Someone should save this for the Classic Trolls Of All Time Hall Of Fame. I wish I had thought of something so simple as asking an arcane C syntax question. --lesser troll than op \_ Maybe you should try an obscure Perl question. \_ How about: if(foo()) {something;} \_ foo() can return NULL, so it's returning a pointer. Therefore bar should be a pointer. Probably it's a char* pointer. So: char* bar = NULL; bar = foo(); if (bar != NULL) { // Do something. } , or, if (!bar) { // Do something.} (but I like the previous one) \_ The null pointer is just an integer equal to zero. If the declaration of foo is 'void foo()' then 'if(foo())' will fail. The NULL pointer evaluates to false. \_ op said he wanted to store the value of foo() in a variable, and also wants to check if it is NULL. (This is common for text-parsing functions.) Hence the code. \_ 1. if the declaration of foo is "void foo()", it can't even return anything, and "if(foo())" won't even compile. What are you trying to say? 2. There is nothing in the C specification that says NULL is necessarily 0. Its value is implementation dependent, although in almost all implementations it's 0. \_ Not exactly. The preprocessor symbol NULL is guaranteed to be 0, but it's not necessarily an integer type (it may be defined to be (void*) 0). NULL is not the same as the "null pointer"; the compiler transforms 0 in pointer contexts to the appropriate null pointer, which may not necessarily be all-bits-zero. --jameslin \_ The answer is yes. The syntax is: if (bar = foo()) | \_ Assign 'bar' to be the return value of foo(). | \_ The value passed to 'if' is the result of the assignment, which is the value of 'bar'. Any non-zero integral value will evaluate as true. \_ "if (bar = foo())" will work, but the compile will probably try to be nice and warn you that you might have mistyped "=" when you really wanted "==". To avoid such a warning, you can do "if ((bar = foo()) != NULL)". With compilers these days, it'll be optimized the same way as "if (bar = foo())" anyway if the value of NULL is 0. \_ And this compiler should be promptly thrown in the trash. In over 10 years of C/C++ development, I've only been bitten by this once or twice. Having to munge my code to avoid spurious warnings only helps newbies who should quickly exit the rank of newbie anyway. \_ Isn't this based on the assumption that NULL == 0 or some equiv. There is nothing in the standard (AFAIK) that requires this. \_ No. When a pointer converts to an int, it must convert to 0 if it is NULL, regardless of the actual bit pattern of the pointer. \_ ic. tnx. \_ Chill down. The compiler gives a warning, not an error. \_ Spurious warnings make it difficult to find real problems. Many software shops have a rule of compiling with no warnings and no errors, so warnings are a problem anyway. \_ Having to munge your code for spurious warnings is a bad thing. However, I challenge your determination that this particular one is spurious. I would want all my developers to NEVER have an "if (bar = foo())" statement. That's IMO, anyway. They can still do it if they want; I wouldn't complain too much if following the rule affected their productivity, what with good people being hard to find. \_ How many more coding guidelines do you want checked in your compiler? Check it in lint instead. Why should I have to avoid legal code because *your* software shop doesn't like that? It's a common idiom, and it takes all of 5 seconds to learn it. \_ I don't think you really read what I wrote. I believe if you got into a meeting with the top 5 coders in your organization, they would agree "if (bar = foo())" is bad form, but they wouldn't bash it over your head, which is what I've been saying. (Of course you can use whatever you like if you're not working with other programmers.) \_ I did read what you read. Your complaint is one of style, which is not what a compiler should check--or at least the complier should have a way to turn off all stylistic warnings. \_ I agree with you that the user should be able to turn off "stylistic warnings". \_ You want to throw gcc in the trash? \_ I was grateful of compiler warnings when I had a very sloppy programmer working on my team. Eventually he was let go after one year. \_ Which is the right thing to do with sloppy programmers: teach them or fire them. |
2004/6/27 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:31028 Activity:nil |
6/27 Stupid UNIX question: In a shell program, how do I read in standard input? I want the program to take standard input and manipulate it in some way and then output the result to a file. Once I have the program written, I know how to invoke it, but how do I, within the program, tell it to work with the standard input? \_ Read from fd 1: while read LINE ; do echo $LINE ; done <&1 \_ If you just want to pass stdin through various external commands, it's easy; just run them, and the first one will consume stdin if it needs it; e.g.: #!/bin/sh awk '{print $2}' | sed 's/a/b/g' > file will "just work". If you want to perform actual line by line shell script programming, you'll have to do like the previous post says. But really, if you're doing actual custom programming of this type (i.e. not lots of external program invocations), you almost certainly are better off using perl or <insert favorite text munging language here> --dbushong |
2004/6/24-26 [Computer/SW/Languages/Perl] UID:31002 Activity:moderate |
6/24 I defined a function in Perl sub myPrint { &print; } And perl complains that it main::print is undefined. How do I refer to the builtin print? \_ print; \_ But according to the camel book, &print; should pass the current @_ to print while print; does not (I have tried). \_ I don't believe that works for builtins \_ Right, and it's deprecated even for functions. Just say what you mean: print @_; \_ Isn't the whole spirot of PERL that there is > 1 way to code what you want? |
11/23 |