|
It's like we need to hold workshops on how to write well-formatted Perl... Less is more. You need less parenthesis, shorter synonyms, and more strategic use of whitespace. Also, a two-space tab indent. Did you know you're popping off the first line of the filehandle before the while loop?
|
# ? May 14, 2008 14:03 |
|
|
# ? May 19, 2024 16:24 |
|
syntax error at ipcsv.pl line 27, near "$csvfile (" syntax error at ipcsv.pl line 30, near ""$csv_dir$csvfile";" syntax error at ipcsv.pl line 35, near "$logfile (" syntax error at ipcsv.pl line 38, near "<$log>;" syntax error at ipcsv.pl line 51, near "}" syntax error at ipcsv.pl line 54, near "}" Execution of ipcsv.pl aborted due to compilation errors.
|
# ? May 14, 2008 14:11 |
|
Triple Tech posted:It's like we need to hold workshops on how to write well-formatted Perl... Less is more. You need less parenthesis, shorter synonyms, and more strategic use of whitespace. Also, a two-space tab indent. Yes, the first line of the file is the headers, which I don't want.
|
# ? May 14, 2008 14:12 |
|
Among a bunch of other things, you should concatenate with a period (.) not a comma (,) so the first I'm going to say is to replace: open $out, ">", "$log_dir$csvfile"; with: open $out, ">" . "$log_dir$csvfile"; if not: open $out, ">$log_dir$csvfile"; or even better: open($out, '>' . $log_dir . $csvfile); Couple of suggestions: 1. As has been said use strict; though I generally use #!/usr/bin/perl -w instead of use warnings; thought that's all a matter of taste. 2. If you're declaring variables as the same value (in this case, undefined), you can declare them like my ($foo, $bar, $baz) = 'whatever'; or just my ($foo, $bar, $baz); 3. Also, another useful thing to use for getting a file list is glob() so instead of code:
code:
|
# ? May 14, 2008 14:12 |
|
Fenderbender posted:Among a bunch of other things, you should concatenate with a period (.) not a comma (,) so the first I'm going to say is to replace: I'd suggest the very opposite! The way he already has it is perfect. Separating the mode from the filename is a really good idea. What if his filename started with a >? Or any other character the mode parser looks for. Concatenation versus interpolation is really a preference thing - Perl transforms interpolation to concatenation in the compile phase. The error is here: foreach (my $csvfile (@csvfiles)){ The correct syntax is: foreach my $csvfile (@csvfiles) {
|
# ? May 14, 2008 14:17 |
|
Wow.
|
# ? May 14, 2008 14:33 |
|
LightI3ulb posted:Yes, the first line of the file is the headers, which I don't want. It should be annotated as such for clarity and great justice. code:
|
# ? May 14, 2008 14:43 |
|
Just because I get some sick joy out of reformatting and condensing code, I took a swing (not that I've tested it, just really reformatted and changed a few things). Do not take this as a lesson in how to write code, this is more for me than it is for you, but it can give you some idea of how it can be done differently. Perl has a lot of stylistic measures that are purely preferential so don't think you're doing something wrong because I'm doing something slightly different. I agree with Triple Tech that we need to write a style guide.code:
Fenderbender fucked around with this message at 15:16 on May 14, 2008 |
# ? May 14, 2008 15:13 |
|
Fenderbender posted:Just because I get some sick joy out of reformatting and condensing code... I see you and I raise you. Untested. Main problems (with the original code) include not knowing interpolation/parsing tricks and excessive scope. code:
|
# ? May 14, 2008 15:38 |
|
Triple Tech posted:I see you and I raise you. Untested. Main problems (with the original code) include not knowing interpolation/parsing tricks and excessive scope. Though you condense the code, there is an amount of readability lost. If you're going for less lines, I think this would save you a few. code:
|
# ? May 14, 2008 16:03 |
|
Fenderbender posted:Though you condense the code, there is an amount of readability lost. If you're going for less lines, I think this would save you a few. I disagree, actually. I find that as a seasoned Perl guy (and not someone who just uses Perl on the side), less is more. I'm not saying it's a golfing contest. Clearly, I would have lost some strokes (and performance) by introducing those concept scalars. But the way the OP wrote it, those scalars tell you nothing of what business logic is going on. And poo poo like this always bubbles up and turns into maintenance nightmares. My heuristic is as follows * Write code the way it speaks to you in your head, with maximum inclusion of business concepts * When possible, take away excessive punctuation/parenthesis ** If this rule introduces ANY sort of confusion or disambiguity, introduce punctuation and parenthesis tastefully Obviously that last part will depend on the programmer, but I think shorter code is much more powerful and easier to understand than long code. Long code doesn't automatically mean good code.
|
# ? May 14, 2008 16:39 |
|
Triple Tech posted:I disagree, actually. I find that as a seasoned Perl guy (and not someone who just uses Perl on the side), less is more. I'm not saying it's a golfing contest. Clearly, I would have lost some strokes (and performance) by introducing those concept scalars. But the way the OP wrote it, those scalars tell you nothing of what business logic is going on. And poo poo like this always bubbles up and turns into maintenance nightmares. Oh, I agree. That is pretty much what goes on in my head as I'm coding. I just see far too often people that have tried to do too much on one line that can be handled more concisely. I completely agree that your way is more concise, I guess I misunderstood what you were attempting to go for. For example, just a few minutes ago I was able to bring 7 lines of someone else's code down to just 3 with a simple open($fh_conf, $conf_file) or die "Couldn't open file $conf_file: $!\n"; my $conf_vars = { map { chomp;split('|') } <$fh_conf> }; close($fh_conf); and lost little readability. I think we're mostly agreeing in different ways.
|
# ? May 14, 2008 17:00 |
|
Triple Tech posted:
I've got one minor quibble with this. I personally prefer moving the last / to when $csv_dir and $log_dir are used rather than sticking it in the config string: code:
2) If someone changes the directories (especially if you were to move their definition to a config file or something), they won't shoot themselves in the foot regardless of whether or not they include a final slash (since an extra slash gets ignored but a missing slash causes everything to break). Yes, I've put way, way too much thought into this.
|
# ? May 14, 2008 19:22 |
|
Erasmus Darwin posted:I've got one minor quibble with this. I personally prefer moving the last / to when $csv_dir and $log_dir are used rather than sticking it in the config string: Once again, I completely agree, I was more trying to reformat and clean than change values. I think I might start a Perl style guide thread in the next couple of days based on some of the stuff I've seen in this thread, if anybody would like that.
|
# ? May 14, 2008 19:49 |
|
YAPC::Asia is streaming their talks at http://live.yapcasia.org/. Right now I'm listening to Ingy talk about pQuery. The schedule of talks will also be useful.
|
# ? May 15, 2008 06:12 |
|
I have a question regarding basic IO::Socket usage. We use these card printers at my work and I'd like to automate some of our repetitive card-printing tasks with perl. From perl, I'm able to connect to the card printer and send commands, and they work. I have not been able to receive the responses from the printer, which I'd like to figure out. Here is my code currently:code:
|
# ? May 19, 2008 21:33 |
|
Cock Democracy posted:If I change $command to the "print a test card" command, the test card will indeed print. But regardless of the command I never get a response. Any ideas? Do the responses have a terminating newline? Can you run something like wireshark and see what's actually going over the wire?
|
# ? May 19, 2008 23:43 |
|
EDIT: gently caress, never mind, I just noticed that this question was answered at the top of the page.
|
# ? May 20, 2008 01:21 |
|
ShoulderDaemon posted:Do the responses have a terminating newline? Can you run something like wireshark and see what's actually going over the wire? Not quite sure what's going on here... after I make the initial connection, it looks like the printer is trying to open a new connection with me every second or so. Cock Democracy fucked around with this message at 02:02 on May 20, 2008 |
# ? May 20, 2008 01:56 |
|
The angle brackets read until they find $/, which is usually set to \n. Your best bet is to keep calling getc and passing it to ord() so you can see what the printer is returning (untested):code:
|
# ? May 20, 2008 07:32 |
|
Cock Democracy posted:Not quite sure what's going on here... after I make the initial connection, it looks like the printer is trying to open a new connection with me every second or so. Maybe the printer isn't trying to use your socket, but instead connect back? This may require you to keep a listening socket open to accept connections from the printer after the command has been sent. edit: ok, I'll be honest, I didn't actually look at the screenshot, so ignore that. more falafel please fucked around with this message at 16:43 on May 20, 2008 |
# ? May 20, 2008 15:53 |
|
I don't think you're reading that right, it's not trying to create new connections, those are just ACK's on the existing connection. [Edit: forget this, it's just the window update and dupe acks...] What's happening is, you're initiating the connection, sending a segment with 6 bytes of data, which the printer responds to with 7 empty segments before you finally terminate the connection from the client end (the FIN). In short, it's just not sending you anything back. The next step for you would be to look at the contents of the segment with the 6 bytes and see if you're actually transmitting what you should be. Having all of those duplicate ACK segments makes me wonder if there's something sketchy on the printer end of things, but first find out if you're sending the right data. npe fucked around with this message at 16:15 on May 20, 2008 |
# ? May 20, 2008 16:09 |
|
yaoi prophet posted:In short, it's just not sending you anything back. The next step for you would be to look at the contents of the segment with the 6 bytes and see if you're actually transmitting what you should be. Having all of those duplicate ACK segments makes me wonder if there's something sketchy on the printer end of things, but first find out if you're sending the right data. Once I found the "Follow TCP stream" feature in Wireshark and viewed the stream in hex, I quickly realized I was not sending commands in the proper format. Weird that it would perform the commands and just not respond in that situation, but whatever, it's working now. Thanks for the help.
|
# ? May 20, 2008 20:26 |
|
I have a large file (>4GB), and when I do a tell() on it, I get negative values since I'm on a 32-bit Linux. Is there a way to use 64-bit file offsets in Perl without installing a 64-bit OS or recompiling the binary?
Stabby McDamage fucked around with this message at 15:40 on May 22, 2008 |
# ? May 22, 2008 00:24 |
|
Okay, I've been pounding my head against this for like an hour and I don't know what I'm doing wrong. I'm trying to use SOAP::Lite to create a SOAP formatted response, that needs to contain a relatively simple series of elements. Basically, there needs to be a status and then an element named history, which is an array of elements named pointHistory that are of type PointHistory. Yeah, making the names and types so similar is confusing. Here's an example of what it should look like: XML for example, not SOAP but you get the point... code:
Here's what I'm getting back right now: code:
Here is the pertinent part of my WSDL: code:
code:
|
# ? May 22, 2008 23:22 |
|
ashgromnies posted:
I'm in a rush and not familiar with SOAP or this module, so sorry for posting, but two things to check.... 1) $elem may not be getting what you think (list of individual nodes), and you're dumping that here via list context. How about using the SOAP::Data->name('thing')->value(); form instead? 2) I think you are wanting to supply SOAP::Data->name("history") with a list of "pointHistory" nodes, but it looks like you are supplying just one with @credit_arr as its value/children. Either way, bust out Data::Dumper, check out what is going into $elem & @credit_arr and have a look at the SOAP::Lite source and make sure those methods expect/return what you expect. I only glanced, but the docs seem to suck.
|
# ? May 23, 2008 04:31 |
|
genericadmin posted:1) $elem may not be getting what you think (list of individual nodes), and you're dumping that here via list context. How about using the SOAP:ata->name('thing')->value(); form instead? It does seem to be getting what I want, it even shows it being enclosed in an element named pointHistory. Making that change didn't affect the results. genericadmin posted:2) I think you are wanting to supply SOAP:ata->name("history") with a list of "pointHistory" nodes, but it looks like you are supplying just one with @credit_arr as its value/children. @credit_arr is an array of PointHistory nodes when I Data:umper it. genericadmin posted:Either way, bust out Data:umper, check out what is going into $elem & @credit_arr and have a look at the SOAP::Lite source and make sure those methods expect/return what you expect. I only glanced, but the docs seem to suck. Yep, the docs are pretty bad. I have access to the O'Reilly bookshelf and all the books there that reference SOAP::Lite have like two pages where they make a Hello World example and then say, "Have fun!" EDIT: Ah, fixed it! I needed to replace $elem with: code:
ashgromnies fucked around with this message at 15:31 on May 23, 2008 |
# ? May 23, 2008 15:19 |
|
Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending.
|
# ? May 23, 2008 19:24 |
|
Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending.
|
# ? May 23, 2008 19:25 |
|
code:
code:
What the sub probably expects is: code:
|
# ? May 23, 2008 19:38 |
|
LightI3ulb posted:Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending. How do you define "receiving"? opening a port and listening to it? You're better off with letting a proper mail demon handling the receiving and a perl module reading a mbox file or Maildir frequently.
|
# ? May 23, 2008 19:40 |
|
LightI3ulb posted:Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending. Are you talking about a module to interface POP3 or IMAP protocol to access mail attachments? Sending mail is SMTP, storage and access of mail are other animals in a different part of the zoo.
|
# ? May 23, 2008 20:09 |
|
I want to be able to access my mailbox, download the email message with the attachment (which I think will be CSV), and then use the CSV like a normal file.
|
# ? May 23, 2008 21:42 |
|
LightI3ulb posted:Does anyone know of any modules that would allow me to receive mail and work with the attachments? The ones I've found on google are typically just for sending. search.cpan.org is a much better resource for finding modules than any other search engine. If you search there for "pop3", there are a bunch of modules returned. I've used Mail::POP3 client before and it worked alright. I ended up using one of the MIME modules to decode and process attachments, but I don't remember what or how I did it. I'm sure there are similar modules for IMAP.
|
# ? May 24, 2008 00:18 |
|
Net::IMAP::Simple makes IMAP access really easy, if your mail server speaks it. To parse the emails once you've gotten them, install MIME::Tools, and then:code:
Mario Incandenza fucked around with this message at 08:24 on May 24, 2008 |
# ? May 24, 2008 08:16 |
|
Is anyone else going to be at YAPC::NA in Chicago next month?
|
# ? May 25, 2008 05:35 |
|
Sartak posted:Is anyone else going to be at YAPC::NA in Chicago next month? The plan is to ask my boss^2 for clearance... Worst case scenario, I take those days off as vacation. For some reason I'm feeling a little ehh about it... Is YAPC really that fun/worth it?
|
# ? May 25, 2008 05:51 |
|
Triple Tech posted:For some reason I'm feeling a little ehh about it... Is YAPC really that fun/worth it? It'll be my first YAPC, so I can't say for sure. But I am very excited about it. There are so many talks I want to see and people I want to meet. You should definitely come by. It's only $100. I think you'll get your money's worth.
|
# ? May 25, 2008 05:59 |
|
Wow, that looks awesome. Make sure you go see Adam Kennedy, his talks at YAPC::AU are entertaining and informative.
|
# ? May 25, 2008 15:28 |
|
|
# ? May 19, 2024 16:24 |
|
I'm going to be there on and off throughout. My work isn't paying for it so I am taking a few half days to see the talks I am interested in.
|
# ? May 25, 2008 18:06 |