From crashkat at gmail.com Tue Oct 7 17:08:49 2008 From: crashkat at gmail.com (Kat Grant) Date: Wed, 8 Oct 2008 11:08:49 +1100 Subject: [Melbourne-pm] Back to Perl.... Next meeting Wednesday 15th October In-Reply-To: <48DC348D.70305@perltraining.com.au> References: <48D8A0F6.4060903@perltraining.com.au> <48DC348D.70305@perltraining.com.au> Message-ID: <53ea12080810071708g395ea11fsfe85cf925fad0f0f@mail.gmail.com> So is there or isn't there a meeting tonight, folks? On Fri, Sep 26, 2008 at 12:02 PM, Jacinta Richardson wrote: > Bother. I've just been reminded that I'm also busy on Wednesday 15th. > > Perhaps I should just do my give-aways in November. :( I won't change the > meeting date again (but you can), and I'll see you all in November. > > Sorry about this! > > J > > -- > ("`-''-/").___..--''"`-._ | Jacinta Richardson | > `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | > (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | > _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | > (il),-'' (li),' ((!.-' | www.perltraining.com.au | > _______________________________________________ > Melbourne-pm mailing list > Melbourne-pm at pm.org > http://mail.pm.org/mailman/listinfo/melbourne-pm > From pjf at perltraining.com.au Tue Oct 7 18:07:41 2008 From: pjf at perltraining.com.au (Paul Fenwick) Date: Wed, 08 Oct 2008 12:07:41 +1100 Subject: [Melbourne-pm] Back to Perl.... Next meeting THURSDAY 16th October In-Reply-To: <53ea12080810071708g395ea11fsfe85cf925fad0f0f@mail.gmail.com> References: <48D8A0F6.4060903@perltraining.com.au> <48DC348D.70305@perltraining.com.au> <53ea12080810071708g395ea11fsfe85cf925fad0f0f@mail.gmail.com> Message-ID: <48EC07DD.3070108@perltraining.com.au> Ahoy m'hearties, Kat Grant wrote: > So is there or isn't there a meeting tonight, folks? I'm going to say there's no meeting tonight, because I'm in Sydney, and I'll be jealous if you have a meeting without me. I'm also going to unilaterally try changing the date of the next meeting to: Thursday, 16th October Why? Because: * Jacinta can attend on the 16th, she has give-aways (T-shirts!) * I can give a talk on what's new in Perl 5.8.9 All the best, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From crashkat at gmail.com Tue Oct 7 18:14:33 2008 From: crashkat at gmail.com (Kat Grant) Date: Wed, 8 Oct 2008 12:14:33 +1100 Subject: [Melbourne-pm] Back to Perl.... Next meeting THURSDAY 16th October In-Reply-To: <48EC07DD.3070108@perltraining.com.au> References: <48D8A0F6.4060903@perltraining.com.au> <48DC348D.70305@perltraining.com.au> <53ea12080810071708g395ea11fsfe85cf925fad0f0f@mail.gmail.com> <48EC07DD.3070108@perltraining.com.au> Message-ID: <53ea12080810071814t4e2dc8b4vedd6284ba153e149@mail.gmail.com> On Wed, Oct 8, 2008 at 12:07 PM, Paul Fenwick wrote: > I'm also going to unilaterally try changing the date of the next meeting to: > > Thursday, 16th October That actually suits me perfectly :) From alecclews at gmail.com Tue Oct 7 20:32:52 2008 From: alecclews at gmail.com (Alec Clews) Date: Wed, 8 Oct 2008 14:32:52 +1100 Subject: [Melbourne-pm] Back to Perl.... Next meeting THURSDAY 16th October Message-ID: <48ec29e5.16048e0a.4488.fffff006@mx.google.com> It does clash with the OSIA meeting (at which *cough* I am presenting) Probably not an issue for many :-) alec -----Original Message----- From: "Kat Grant" To: "Melbourne Perlmongers" Sent: 08/10/2008 12:14 Subject: Re: [Melbourne-pm] Back to Perl.... Next meeting THURSDAY 16th October On Wed, Oct 8, 2008 at 12:07 PM, Paul Fenwick wrote: > I'm also going to unilaterally try changing the date of the next meeting to: > > Thursday, 16th October That actually suits me perfectly :) _______________________________________________ Melbourne-pm mailing list Melbourne-pm at pm.org http://mail.pm.org/mailman/listinfo/melbourne-pm From jarich at perltraining.com.au Wed Oct 8 23:34:34 2008 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Thu, 09 Oct 2008 17:34:34 +1100 Subject: [Melbourne-pm] Perl Monger give-aways and October/November meetings Message-ID: <48EDA5FA.30900@perltraining.com.au> G'day folk, Whenever the next meeting should happen to be; if I can manage to get there: next Tuesday: clashes with SAGE-AU Vic next Wednesday: I'm busy next Thursday (CURRENT NOMINATION) clashes with OSIA Melb next Friday: ... people have lives ... I have these things to give away: T-shirts OSDC 2004 (long sleeves, sponsors on back, white, coloured sleeves) ------------------------------------------------------------------------ 1 small regular (blue sleeves) 7 medium regular " " 1 large helper (red sleeves) T-shirts OSDC 2005 (short sleeves, thicker material, no sponsors, black) ------------------------------------------------------------------- 1 small regular (all black) 1 medium helper (red sleeves) 4 large regular (all black) 1 large helper (red sleeves) Proceedings & Schwag bags ------------------------- Some left over 2004 bags (empty). Simple tote bag, calico, printed 1 side. 3 copies of 2005 proceedings 4 2005 schwag bags complete with proceedings, firefox secrets etc & 3 year old chocolates. I'm not sure what's the fairest way to do this, since some of our regulars will be busy no matter what night we pick; so I'm very happy to wait until the November meeting for these give-aways and instead have you all turn up to Alec's OSIA talk for this month's meeting (followed by a trip to the pub afterwards of course) What do other's suggest? J From ddick at aapt.net.au Thu Oct 9 01:51:10 2008 From: ddick at aapt.net.au (David Dick) Date: Thu, 09 Oct 2008 19:51:10 +1100 Subject: [Melbourne-pm] Perl Monger give-aways and October/November meetings In-Reply-To: <48EDA5FA.30900@perltraining.com.au> References: <48EDA5FA.30900@perltraining.com.au> Message-ID: <48EDC5FE.4040604@aapt.net.au> Jacinta Richardson wrote: > What do other's suggest? The premises will be available either night. And personally i don't mind either way. -Dave From jarich at perltraining.com.au Thu Oct 9 17:38:57 2008 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Fri, 10 Oct 2008 11:38:57 +1100 Subject: [Melbourne-pm] [Sydney-pm] Open Source Developers' Conference 2008 (OSDC 2008) Registrations now open Message-ID: <48EEA421.1020307@perltraining.com.au> OSDC 2008 Early Bird Registration is now open! Tuesday 2nd - Friday 5th December 2008 SMC Conference and Function centre in the Sydney CBD Early bird finishes: 27th October 2008. Book now: http://www.osdc.com.au/2008/registration/ Early Bird Registration for The Open Source Developers' Conference 2008 is now open. OSDC 2008 is a conference run by open source developers, for developers and business people. It covers numerous programming languages across a range of operating systems, and related topics such as business processes, licensing, and strategy. Talks vary from introductory pieces through to the deeply technical. This year we have an exciting selection of presenters and keynote speakers including: * Larry Wall, the creator of Perl * Chris DiBona, Open Source Progams Manager for Google * Andrew Tridgell, Founder, Samba Team * Anthony Baxter, Python Evangelist * Pia Waugh, Consultant, Waugh Partners Check out the draft program: http://www.osdc.com.au/2008/papers/ The conference will be in Sydney during the first week of December (2nd - 5th), and will be held at the SMC conference venue located in the Sydney CBD. Please visit http://www.osdc.com.au/2008/registration/ to register. Earlybird registration closes 27th October, 2008. For more information about this event, please visit: http://www.osdc.com.au/. Regards, OSDC 2008 Organising Committee _______________________________________________ Sydney-pm mailing list Sydney-pm at pm.org http://mail.pm.org/mailman/listinfo/sydney-pm From pjf at perltraining.com.au Mon Oct 13 00:09:03 2008 From: pjf at perltraining.com.au (Paul Fenwick) Date: Mon, 13 Oct 2008 18:09:03 +1100 Subject: [Melbourne-pm] Next meeting, THURSDAY 16th October Message-ID: <48F2F40F.1070904@perltraining.com.au> Because there seems to be an irresolvable set of conflicts for this week's meeting, we're going to hijack^Wcrash^Wjoin our friends at the OSIA meeting, which already has a Perl Monger presenting (albeit not about Perl): OSIA Melbourne ^^^^^^^^^^^^^^ When: Thursday Week - 7pm October 16th. What: Alec Clews of Voga Consulting is presenting "Building a Business Value Demo" Where: Innovation @ 257 Level One, Emirates House, 257 Collins Street, Melbourne CBD. Details: http://osia.net.au/mel-oct-2008 Cheerio, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From alec.clews at gmail.com Wed Oct 15 01:16:00 2008 From: alec.clews at gmail.com (Alec Clews) Date: Wed, 15 Oct 2008 19:16:00 +1100 Subject: [Melbourne-pm] Next meeting, THURSDAY 16th October In-Reply-To: <48F2F40F.1070904@perltraining.com.au> References: <48F2F40F.1070904@perltraining.com.au> Message-ID: <1224058560.7010.67.camel@k10> So I'd better see how many references to Perl and Perl culture I can slip into the presentation :-) On Mon, 2008-10-13 at 18:09 +1100, Paul Fenwick wrote: > Because there seems to be an irresolvable set of conflicts for this week's > meeting, we're going to hijack^Wcrash^Wjoin our friends at the OSIA meeting, > which already has a Perl Monger presenting (albeit not about Perl): > > OSIA Melbourne > ^^^^^^^^^^^^^^ > When: Thursday Week - 7pm October 16th. > What: Alec Clews of Voga Consulting is presenting > "Building a Business Value Demo" > Where: Innovation @ 257 Level One, > Emirates House, 257 Collins Street, Melbourne CBD. > Details: http://osia.net.au/mel-oct-2008 > > Cheerio, > > Paul > -- ?Alec Clews Personal Melbourne, Australia. Jabber: alecclews at jabber.org.au PGPKey ID: 0x9BBBFC7C Blog http://alecthegeek.wordpress.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: From scottp at linux.dd.com.au Wed Oct 15 20:29:50 2008 From: scottp at linux.dd.com.au (Scott Penrose) Date: Thu, 16 Oct 2008 13:29:50 +1000 (EST) Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <32712495.10821224127318525.JavaMail.root@zimbra> Message-ID: <81601.10841224127790481.JavaMail.root@zimbra> Hey Guys I am writing a module at the moment to capture IO::File open to allow me to work out the difference in file size at the start and end of an operation. My code basically works, but it is a huge hack, and requires a hack on the call to make it work. Firstly let me show you how I would expect the code to work: (NOTE: This is not thread safe, it is demonstration code, not final) #!/usr/bin/perl use IO::File::Quota; # Set the call back - just print the new size $IO::File::Quota::quotaaction = sub { print "New size = ", @_, "\n" }; # Open a file for append my $fh = new IO::File::Quota ">> /tmp/testfile1"; # Print to the file print $fh "This is a new line\n"; # Three methods of closing a file $fh->close; #close $fh; #undef $fh; Above is code that works, but only if you use $fh->close before the object is destroyed. To get around this I added in a tiny hack to keep the file name. my $fh = new IO::File::Quota ">> /tmp/testfile1"; $IO::File::Quota::filecache{$fh} = "/tmp/testfile1"; Now all three close methods work - $fh->close; close $fh; undef $fh - and in any order. So before my questions, here is the actual module: package IO::File::Quota; use base qw/IO::File/; # Keep a local copy of the size at the start our %sizecache = (); # Keep a local copy of the filename at the start our %namecache = (); # Callback function our $quotaaction; # Capture current size (maybe zero if not used) sub open { my ($self, @rest) = @_; print STDERR "Open: " . $rest[0] . "\n"; my $ret = $self->SUPER::open(@rest); $sizecache{$ret} = -s $ret; return $ret; } sub close { my ($self, @rest) = @_; print STDERR "Close\n"; my $new = -s $self; if ($sizecache{$self} != $new && ref($quotaaction)) { $quotaaction->($new - $sizecache{$self}); } delete $sizecache{$self}; delete $filecache{$self}; return $self->SUPER::close(@rest); } sub DESTROY { my $self = shift; my $new = -s $self; if (!defined($new) && exists($filecache{$self})) { $new = -s $filecache{$self}; } print STDERR "DESTROY - $new\n"; if (exists($sizecache{$self}) && $sizecache{$self} != $new && ref($quotaaction)) { $quotaaction->($new - $sizecache{$self}); } delete $sizecache{$self}; delete $filecache{$self}; } 1; Note that close and DESTROY are partially duplicates for the moment. I would probably complete the work by using a separate method based on the filename (after sync) called from close & destroy. The reason close is important is that it may be used while the object still exists and we want to know as close to closing time as possible. ALSO NOTE - this captures the wrong size using "-s" as it is before the file is flushed - I can fix those problems easily later. Right down to my questions: 1) Is there anyway of getting from a file handle: - That it is a file on disk, rather than Socket or Pipe - The filename of that file 2) What else would you change - in functions, calls and purpose to make this a useful CPAN module 3) Is there already something like this you know of? I feel like I am going about this all wrong, but I am a little stuck and in need of help. Thanks Scott From scottp at dd.com.au Wed Oct 15 20:34:59 2008 From: scottp at dd.com.au (Scott Penrose) Date: Thu, 16 Oct 2008 13:34:59 +1000 (EST) Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <81601.10841224127790481.JavaMail.root@zimbra> Message-ID: <8479488.10901224128099399.JavaMail.root@zimbra> I forgot to mention - don't think of this in terms of Disk Quota - if I had it all my way we would use disk quota, but that is another very long story. Think of it as - I want to capture the file size before open and after close. Scott From toby.corkindale at strategicdata.com.au Wed Oct 15 20:39:53 2008 From: toby.corkindale at strategicdata.com.au (Toby Corkindale) Date: Thu, 16 Oct 2008 14:39:53 +1100 Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <81601.10841224127790481.JavaMail.root@zimbra> References: <81601.10841224127790481.JavaMail.root@zimbra> Message-ID: <48F6B789.5090108@strategicdata.com.au> Scott Penrose wrote: > Hey Guys > > I am writing a module at the moment to capture IO::File open to allow me to work out the difference in file size at the start and end of an operation. > > My code basically works, but it is a huge hack, and requires a hack on the call to make it work. > > Firstly let me show you how I would expect the code to work: [snip code] > > Note that close and DESTROY are partially duplicates for the moment. I would probably complete the work by using a separate method based on the filename (after sync) called from close & destroy. The reason close is important is that it may be used while the object still exists and we want to know as close to closing time as possible. > > ALSO NOTE - this captures the wrong size using "-s" as it is before the file is flushed - I can fix those problems easily later. > > Right down to my questions: > > 1) Is there anyway of getting from a file handle: > - That it is a file on disk, rather than Socket or Pipe > - The filename of that file fstat() works upon filehandles directly, avoiding the needing to keep the filename around. Might make life easier for you, and also allow you to work with temporary files that were created and unlinked after open. > 2) What else would you change - in functions, calls and purpose to make this a useful CPAN module The name of the module implies that it is meant to be performing quota management, but the actual action seems to be more like performing a generic call-back upon close.. If you're actually looking to enforce quotas, wouldn't you need to check the data written at every write, rather than upon close? In that case, rather than use '-s' (or fstat()) to get the size, you could use the return from fnprintf() or similar, which gives you the number of bytes written.. then you can do something like: die "Quota exceeded!" unless ($bytes_written <= $remaining_quota); $remaining_quota -= $bytes_written; -Toby -- Strategic Data Pty Ltd Ph: 03 9340 9000 From scottp at dd.com.au Wed Oct 15 20:52:31 2008 From: scottp at dd.com.au (Scott Penrose) Date: Thu, 16 Oct 2008 13:52:31 +1000 (EST) Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <48F6B789.5090108@strategicdata.com.au> Message-ID: <918192.10981224129151025.JavaMail.root@zimbra> ----- "Toby Corkindale" wrote: > fstat() works upon filehandles directly, avoiding the needing to keep > the filename around. Might make life easier for you, and also allow > you > to work with temporary files that were created and unlinked after > open. Sorry I forgot to mention the problem. If someone uses undef $fh; - which is the norm. or close $fh which is also common - then the file handle is closed before it gets to DESTORY, and I can't use fstat. That is why $fh->close works, but undef $fh and close $fh does not, until I kept a copy of the filename. > > 2) What else would you change - in functions, calls and purpose to > make this a useful CPAN module > > The name of the module implies that it is meant to be performing quota > management, but the actual action seems to be more like performing a > generic call-back upon close.. > If you're actually looking to enforce quotas, wouldn't you need to > check > the data written at every write, rather than upon close? Yes :-) this is lazy quota :-) (p.s. don't worry about the quota side - it is horrible but must be the way it is). I agree about the name, it might be something like IO::File::Hook::Size - or something similar. Maybe IO::File::Stat if I can get more info. > In that case, rather than use '-s' (or fstat()) to get the size, you > could use the return from fnprintf() or similar, which gives you the > number of bytes written.. then you can do something like: > die "Quota exceeded!" unless ($bytes_written <= $remaining_quota); > $remaining_quota -= $bytes_written; Unfortunately after the open I have no control over the code. If it uses print, fprintf, or syswrite or what ever I am not sure. It may even pass the file handle to a C library to do the work. All I have is the open call. Scott From pjf at perltraining.com.au Wed Oct 15 20:53:26 2008 From: pjf at perltraining.com.au (Paul Fenwick) Date: Thu, 16 Oct 2008 14:53:26 +1100 Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <81601.10841224127790481.JavaMail.root@zimbra> References: <81601.10841224127790481.JavaMail.root@zimbra> Message-ID: <48F6BAB6.7070401@perltraining.com.au> G'day Scott, Scott Penrose wrote: > 1) Is there anyway of getting from a file handle: > - That it is a file on disk, rather than Socket or Pipe I imagine yes. The stat() call returns the device number, inode number, and file mode. For a network socket, I imagine the device and inode number will be set to funny values. For a named pipe on the disk, I imagine the file mode will contain a hint. > - The filename of that file As far as I know, no, at least not on Unix-flavoured systems. After the file has been opened, the file can be renamed, or even deleted. In fact, after you've opened it, you can't even rely upon a file of the same name referring to the same file; for example, when the file gets rotated and a new file dropped in its place. Luckily, the stat() call will give you both size and inode number. If the inode number has changed, you know that the file have been roated/moved/deleted/etc. Of course, if you're passing filehandles to stat, you'll always be examining the correct file, even if the name has changed. > 2) What else would you change - in functions, calls and purpose to make > this a useful CPAN module I don't like the idea of a global callback, I'm much fonder of having per-object callbacks: IO::File::Quota->new('>> /tmp/example', \&callback); If something doesn't have a callback (or even if it does), I'd change the returns of close to return the change in size in bytes, or "0 but true" or some equivalent value if the close was successful, but the file didn't change in length. That allows for code like: my $fh = IO::File::Quote->new('>> /tmp/example'); while () { $fh->print($_); } my $bytes_read = $fh->close or die "Uh oh! $!"; I'd also add a '->count' method, so I can tell how many bytes have been added (or removed) to the file so far. This can just be syntactic sugar for flushing the file and counting its size. I'd also change the name. If we're not trying to enforce a quota, we just want a change in size, then I'd consider IO::File::SizeDelta or similar as a name. > 3) Is there already something like this you know of? Nope, but I haven't looked. I usually ask modules at perl.org such things. Cheerio, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From daniel at rimspace.net Wed Oct 15 21:04:31 2008 From: daniel at rimspace.net (Daniel Pittman) Date: Thu, 16 Oct 2008 15:04:31 +1100 Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <48F6B789.5090108@strategicdata.com.au> (Toby Corkindale's message of "Thu, 16 Oct 2008 14:39:53 +1100") References: <81601.10841224127790481.JavaMail.root@zimbra> <48F6B789.5090108@strategicdata.com.au> Message-ID: <87ljwpi3sg.fsf@rimspace.net> Toby Corkindale writes: >> I am writing a module at the moment to capture IO::File open to allow >> me to work out the difference in file size at the start and end of an >> operation. [...] >> 1) Is there anyway of getting from a file handle: >> - That it is a file on disk, rather than Socket or Pipe >> - The filename of that file > > fstat() works upon filehandles directly, avoiding the needing to keep > the filename around. Moreover, it avoids the exploit that a user can create a file with two hard links, open with your tool, then replace the link used as the open name with a small file, fooling your quota code. fstat() also allows you to query the nature of the file, and will inform you of "is it a regular file" or, you know, something else. [...] >> 2) What else would you change - in functions, calls and purpose to >> make this a useful CPAN module > > The name of the module implies that it is meant to be performing quota > management, but the actual action seems to be more like performing a > generic call-back upon close.. *nod* With additional hooks you could make this a generic mechanism for implementing file policy, ala IO::AtomicFile, or non-standard stores such as a user-space HSM implementation. That would require significantly more hooks, though, and would probably be harder for many people than just subclassing the module directly. Are you sure that your needs wouldn't be better served with using Module::Replace (or the open-coded equivalent) to inject your code into the target module? > If you're actually looking to enforce quotas, wouldn't you need to > check the data written at every write, rather than upon close? Not necessarily, in their use. In general, this has sufficient weak spots that it would be hard to say it was generically useful to a wide range of environments, I suspect. Regards, Daniel From scottp at dd.com.au Wed Oct 15 21:04:57 2008 From: scottp at dd.com.au (Scott Penrose) Date: Thu, 16 Oct 2008 14:04:57 +1000 (EST) Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <48F6BAB6.7070401@perltraining.com.au> Message-ID: <7366317.11061224129897064.JavaMail.root@zimbra> Howdy Paul. ----- "Paul Fenwick" wrote: > G'day Scott, > > Scott Penrose wrote: > > > 1) Is there anyway of getting from a file handle: > > - That it is a file on disk, rather than Socket or Pipe > > I imagine yes. The stat() call returns the device number, inode > number, and > file mode. For a network socket, I imagine the device and inode > number will > be set to funny values. For a named pipe on the disk, I imagine the > file > mode will contain a hint. > > > - The filename of that file > > As far as I know, no, at least not on Unix-flavoured systems. After > the > file has been opened, the file can be renamed, or even deleted. In > fact, > after you've opened it, you can't even rely upon a file of the same > name > referring to the same file; for example, when the file gets rotated > and a > new file dropped in its place. > > Luckily, the stat() call will give you both size and inode number. If > the > inode number has changed, you know that the file have been > roated/moved/deleted/etc. Of course, if you're passing filehandles to > stat, > you'll always be examining the correct file, even if the name has > changed. Hmm... I could get the size from the inode, assuming of course unix. I also found a hack where you can go to /proc/$$/fh/$fid to get the filename, but again linux only. But if the reference count is 0 on the inode (e.g. temp file) it would be wrong. Two ways I can think of at the moment to get around the problem. 1) Require a special call to IO::File (by special, that could just be the 3 parameter entries) 2) Regular expression over the input string (ahhhhhh) > > 2) What else would you change - in functions, calls and purpose to > make > > this a useful CPAN module > > I don't like the idea of a global callback, I'm much fonder of having > per-object callbacks: > > IO::File::Quota->new('>> /tmp/example', \&callback); Yes I agree - not only does the above fix problems like threading it means you can have multiple callbacks depending on file open etc. So I think combining 1&2 above I could do: my $fh = IO::File::Quota->new('/tmp/example', 'w+', \&callback); - or similar Although therefore the open command is different, it means the rest of your code is just a file handle. But one question - I think I have to use a hash (what ever method, inside out objects etc) as the $fh is just that - a file handle, so I can't store it in there. Which means of course that it is not thread safe - maybe that doesn't matter. > If something doesn't have a callback (or even if it does), I'd change > the > returns of close to return the change in size in bytes, or "0 but > true" or > some equivalent value if the close was successful, but the file > didn't > change in length. That allows for code like: > > my $fh = IO::File::Quote->new('>> /tmp/example'); > > while () { > $fh->print($_); > } > > my $bytes_read = $fh->close or die "Uh oh! $!"; > > I'd also add a '->count' method, so I can tell how many bytes have > been > added (or removed) to the file so far. This can just be syntactic > sugar for > flushing the file and counting its size. > > I'd also change the name. If we're not trying to enforce a quota, we > just > want a change in size, then I'd consider IO::File::SizeDelta or > similar as a > name. Yes I like that name. > > 3) Is there already something like this you know of? > > Nope, but I haven't looked. I usually ask modules at perl.org such > things. I will finish off the working module now, but the question will remain open for a while if I should publish it - it may be too much of a local hack that would add confusion in the real world. Thanks everyone Scott From pjf at perltraining.com.au Wed Oct 15 21:31:36 2008 From: pjf at perltraining.com.au (Paul Fenwick) Date: Thu, 16 Oct 2008 15:31:36 +1100 Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <918192.10981224129151025.JavaMail.root@zimbra> References: <918192.10981224129151025.JavaMail.root@zimbra> Message-ID: <48F6C3A8.7020100@perltraining.com.au> (Ooops, originally sent only to Scott, sending to MPM as well) Scott Penrose wrote: > Sorry I forgot to mention the problem. If someone uses undef $fh; - which > is the norm. or close $fh which is also common - then the file handle is > closed before it gets to DESTORY, and I can't use fstat. You *may* be able to get around this by stashing your filehandle away where undef can't get to it. Change the object from being a reference to a glob to a reference to something else, and store the glob inside. Then overload *{} (the globification operator) to return the glob. You may also wish to overload the ${} (scalarification operator) to return the glob as well. That way it looks and feels like a glob, but you *should* be able to get access to your open filehandle when someone undef's your object. However I don't think any of this protects you in the close of a close($fh), where a built-in is being handed your filehandle, and all the tricks I can think of to catch this are fallible, except one. You *can* dup your file after it's been opened. Provided you know the mode, you *should* be able to: use autodie qw(open); open(my $dup_fh, "$mode&", $existing_filehandle); You now have $dup_fh which *should* remain open even if your original filehandle closes. If you can then catch that close (left as an exercise to the reader), you can stat($dup_fh) to determine the new file size without needing its name, and without race conditions. This will also get you around the problems with undef($fh), for the same reasons. So, I guess the steps on object creation should be: * Create the object. * Dup the object using the same mode and stash it. On object destruction: * Grab the dup'ed filehandle from the stash. * Get its size. * Close the dup'ed filehandle and remove it from the stash. The stash could live inside the object itself, which would the contain two filehandles. The original, which it regularly exposes to the rest of the world, and the dup, which is kept as insurance. If you do all this, then it's a really good candidate for a CPAN release. Cheerio, Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From scottp at dd.com.au Wed Oct 15 22:32:16 2008 From: scottp at dd.com.au (Scott Penrose) Date: Thu, 16 Oct 2008 15:32:16 +1000 (EST) Subject: [Melbourne-pm] IO::File with Capture for Quota In-Reply-To: <48F6C3A8.7020100@perltraining.com.au> Message-ID: <1209346.11151224135136678.JavaMail.root@zimbra> ----- "Paul Fenwick" wrote: > You *can* dup your file after it's been opened. Provided you know the > mode, Since you can get the mode from state - wouldn't that be ok? Scott From lsharpe at pacificwireless.com.au Thu Oct 16 18:30:05 2008 From: lsharpe at pacificwireless.com.au (Leigh Sharpe) Date: Fri, 17 Oct 2008 11:30:05 +1000 Subject: [Melbourne-pm] Strange behaviour from Net::TFTP Message-ID: <96CF49BD8B56384395D698BA99007FA32FA455@exchange.pacwire.local> Hi guys, I'm seeing what I consider to be odd behaviour using Net::TFTP to copy some files to a remote machine. The part of the code giving me problems is this: use strict; use warnings; use Net::TFTP; my $ip="1.2.3.4"; # Insert IP address of your TFTP server here. my $tftp=Net::TFTP->new($ip); $tftp->put("file1", "file1") or print "Problem saving file1: ".$tftp->error()."\n"; $tftp->put("file2", "file2") or print "Problem saving file2: ".$tftp->error()."\n"; $tftp->put("file3", "file3") or print "Problem saving file3: ".$tftp->error()."\n"; $tftp->put("file4", "file4") or print "Problem saving file4: ".$tftp->error()."\n"; If all 4 files exist, all is OK. However, if file3 does not exist, I get the following: >perl tftp_test.pl Problem saving file3: file3: No such file or directory Problem saving file4: file3: No such file or directory Now, I can understand that the error message reported by $tftp->error() contains the last error encountered, ie that file3 doesn't exist, but there is no reason why copying file4 should fail, because it does exist. Worse still, file4 is created on the TFTP server, but is empty. So the non-existence of file3 is causing the copy of file4 to fail. Anyody care to comment on why? Should I be calling some other method in between put()'s? I considered just DESTROYing the object after each put(), and creating a new one, but that just seems wrong. I could of course test for the existence of each file first, but the docs for Net::TFTP indicate that the above should work, and I'd like to know what I'm missing. Regards, Leigh Leigh Sharpe Network Systems Engineer Pacific Wireless Ph +61 3 9584 8966 Mob 0408 009 502 Helpdesk 1300 300 616 email lsharpe at pacificwireless.com.au web www.pacificwireless.com.au -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby.corkindale at strategicdata.com.au Thu Oct 16 17:59:15 2008 From: toby.corkindale at strategicdata.com.au (Toby Corkindale) Date: Fri, 17 Oct 2008 11:59:15 +1100 Subject: [Melbourne-pm] Strange behaviour from Net::TFTP In-Reply-To: <96CF49BD8B56384395D698BA99007FA32FA455@exchange.pacwire.local> References: <96CF49BD8B56384395D698BA99007FA32FA455@exchange.pacwire.local> Message-ID: <48F7E363.7080403@strategicdata.com.au> Leigh Sharpe wrote: > Hi guys, > I'm seeing what I consider to be odd behaviour using Net::TFTP to copy > some files to a remote machine. The part of the code giving me problems > is this: > > use strict; > use warnings; > use Net::TFTP; > > my $ip="1.2.3.4"; # Insert IP address of > your TFTP server here. > my $tftp=Net::TFTP->new($ip); > $tftp->put("file1", "file1") or print "Problem saving file1: > ".$tftp->error()."\n"; > $tftp->put("file2", "file2") or print "Problem saving file2: > ".$tftp->error()."\n"; > $tftp->put("file3", "file3") or print "Problem saving file3: > ".$tftp->error()."\n"; > $tftp->put("file4", "file4") or print "Problem saving file4: > ".$tftp->error()."\n"; > If all 4 files exist, all is OK. However, if file3 does not exist, I get > the following: > >>perl tftp_test.pl > Problem saving file3: file3: No such file or directory > Problem saving file4: file3: No such file or directory > > > Now, I can understand that the error message reported by $tftp->error() > contains the last error encountered, ie that file3 doesn't exist, but > there is no reason why copying file4 should fail, because it does exist. > Worse still, file4 is created on the TFTP server, but is empty. So the > non-existence of file3 is causing the copy of file4 to fail. > Anyody care to comment on why? > Should I be calling some other method in between put()'s? > I considered just DESTROYing the object after each put(), and creating a > new one, but that just seems wrong. > I could of course test for the existence of each file first, but the > docs for Net::TFTP indicate that the above should work, and I'd like to > know what I'm missing. It smells quite similar to this bug report: http://rt.cpan.org/Public/Bug/Display.html?id=37700 Perhaps try applying the patches from there and see if it solves the problem? -- Strategic Data Pty Ltd Ph: 03 9340 9000 From lsharpe at pacificwireless.com.au Thu Oct 16 19:24:06 2008 From: lsharpe at pacificwireless.com.au (Leigh Sharpe) Date: Fri, 17 Oct 2008 12:24:06 +1000 Subject: [Melbourne-pm] Strange behaviour from Net::TFTP Message-ID: <96CF49BD8B56384395D698BA99007FA32FA456@exchange.pacwire.local> Thanks Toby, It does sound similar, but as far as I can tell, Net::TFTP isn't going to be calling any Net::FTP functions, so I don't think the patch there is going to help me any. -----Original Message----- From: Toby Corkindale [mailto:toby.corkindale at strategicdata.com.au] Sent: Friday, 17 October 2008 10:59 AM To: Leigh Sharpe Cc: melbourne-pm at pm.org Subject: Re: [Melbourne-pm] Strange behaviour from Net::TFTP Leigh Sharpe wrote: > Hi guys, > I'm seeing what I consider to be odd behaviour using Net::TFTP to copy > some files to a remote machine. The part of the code giving me problems > is this: > > use strict; > use warnings; > use Net::TFTP; > > my $ip="1.2.3.4"; # Insert IP address of > your TFTP server here. > my $tftp=Net::TFTP->new($ip); > $tftp->put("file1", "file1") or print "Problem saving file1: > ".$tftp->error()."\n"; > $tftp->put("file2", "file2") or print "Problem saving file2: > ".$tftp->error()."\n"; > $tftp->put("file3", "file3") or print "Problem saving file3: > ".$tftp->error()."\n"; > $tftp->put("file4", "file4") or print "Problem saving file4: > ".$tftp->error()."\n"; > If all 4 files exist, all is OK. However, if file3 does not exist, I get > the following: > >>perl tftp_test.pl > Problem saving file3: file3: No such file or directory > Problem saving file4: file3: No such file or directory > > > Now, I can understand that the error message reported by $tftp->error() > contains the last error encountered, ie that file3 doesn't exist, but > there is no reason why copying file4 should fail, because it does exist. > Worse still, file4 is created on the TFTP server, but is empty. So the > non-existence of file3 is causing the copy of file4 to fail. > Anyody care to comment on why? > Should I be calling some other method in between put()'s? > I considered just DESTROYing the object after each put(), and creating a > new one, but that just seems wrong. > I could of course test for the existence of each file first, but the > docs for Net::TFTP indicate that the above should work, and I'd like to > know what I'm missing. It smells quite similar to this bug report: http://rt.cpan.org/Public/Bug/Display.html?id=37700 Perhaps try applying the patches from there and see if it solves the problem? -- Strategic Data Pty Ltd Ph: 03 9340 9000 From scottp at dd.com.au Fri Oct 17 15:08:39 2008 From: scottp at dd.com.au (Scott Penrose) Date: Sat, 18 Oct 2008 09:08:39 +1100 Subject: [Melbourne-pm] Fwd: [pm_groups] CulturedPerl.org References: <48F8892E.1080804@pm.org> Message-ID: <3623FEAD-7F72-4698-818E-9DF21B92AC49@dd.com.au> FYI from PM Groups. Scott Begin forwarded message: > From: Dave Cross > Date: 17 October 2008 11:46:38 PM > To: pm_groups at pm.org > Subject: [pm_groups] CulturedPerl.org > > > Those of you who follow use.perl might have seen the article[1] > yesterday where I was trying to drum up some authors to help me out > on a couple of Perl blogs. > > I've had a pretty good response to the call for help with > proudtouseperl.org, but I also need help with culturedperl.org. > > Culturedperl.org is intended to be a blog about Perl culture. I > don't have any strong ideas of exactly what that covers except that > it should promote what we think is best about the Perl community. > > And as a huge part of the Perl community (and culture) is Perl > Mongers, I wondered if some PM group leaders would be interested in > writing the occasional article for the site. > > If you're interested then please drop me a mail. > > Cheers, > > Dave... > > [1] http://use.perl.org/article.pl?sid=08/10/16/095251 > -- > Request pm.org Technical Support via support at pm.org > > pm_groups mailing list > pm_groups at pm.org > http://mail.pm.org/mailman/listinfo/pm_groups -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at jumbuk.com Tue Oct 21 21:16:44 2008 From: dan at jumbuk.com (Dan Tyrrell) Date: Wed, 22 Oct 2008 16:16:44 +1200 Subject: [Melbourne-pm] Fwd: Strange behaviour from Net::TFTP In-Reply-To: References: <96CF49BD8B56384395D698BA99007FA32FA455@exchange.pacwire.local> Message-ID: ---------- Forwarded message ---------- From: Dan Tyrrell Date: 2008/10/22 Subject: Re: [Melbourne-pm] Strange behaviour from Net::TFTP To: Leigh Sharpe Hi, I sent something similar to his on Friday but it seems it never arrived (I checked the archives - apologies if this is a repeat.) http://rt.cpan.org/Public/Bug/Display.html?id=40243 Dan 008/10/17 Leigh Sharpe : > Hi guys, > I'm seeing what I consider to be odd behaviour using Net::TFTP to copy some > files to a remote machine. The part of the code giving me problems is this: > > use strict; > use warnings; > use Net::TFTP; > > my $ip="1.2.3.4"; # Insert IP address of your > TFTP server here. > my $tftp=Net::TFTP->new($ip); > $tftp->put("file1", "file1") or print "Problem saving file1: > ".$tftp->error()."\n"; > $tftp->put("file2", "file2") or print "Problem saving file2: > ".$tftp->error()."\n"; > $tftp->put("file3", "file3") or print "Problem saving file3: > ".$tftp->error()."\n"; > $tftp->put("file4", "file4") or print "Problem saving file4: > ".$tftp->error()."\n"; > If all 4 files exist, all is OK. However, if file3 does not exist, I get the > following: > >>perl tftp_test.pl > Problem saving file3: file3: No such file or directory > Problem saving file4: file3: No such file or directory > > > Now, I can understand that the error message reported by $tftp->error() > contains the last error encountered, ie that file3 doesn't exist, but there > is no reason why copying file4 should fail, because it does exist. Worse > still, file4 is created on the TFTP server, but is empty. So the > non-existence of file3 is causing the copy of file4 to fail. > Anyody care to comment on why? > Should I be calling some other method in between put()'s? > I considered just DESTROYing the object after each put(), and creating a new > one, but that just seems wrong. > I could of course test for the existence of each file first, but the docs > for Net::TFTP indicate that the above should work, and I'd like to know what > I'm missing. > > Regards, > Leigh > > Leigh Sharpe > Network Systems Engineer > Pacific Wireless > Ph +61 3 9584 8966 > Mob 0408 009 502 > Helpdesk 1300 300 616 > email lsharpe at pacificwireless.com.au > web www.pacificwireless.com.au > > _______________________________________________ > Melbourne-pm mailing list > Melbourne-pm at pm.org > http://mail.pm.org/mailman/listinfo/melbourne-pm > -- Cheers, Dan Tyrrell 24 Jackson St, Northcote, 3070 Australia. Mobile: +61 409 964 694 dan at jumbuk.com -- Cheers, Dan Tyrrell 24 Jackson St, Northcote, 3070 Australia. Mobile: +61 409 964 694 dan at jumbuk.com From mathew.robertson at netratings.com.au Wed Oct 22 16:26:44 2008 From: mathew.robertson at netratings.com.au (Mathew Robertson) Date: Thu, 23 Oct 2008 10:26:44 +1100 Subject: [Melbourne-pm] creating useful package metadata Message-ID: <48FFB6B4.9090802@netratings.com.au> Hi folks, this is just a little idea that I came up with once... I'm not sure if it has been used anywhere before, but I thought I'd share it anyway. Here is some example code for a MyPackage.pm and a test program: package MyPackage; our @EXPORT_OK = qw ( blah ); sub blah {...} 1; use strict; use warnings; use Data::Dumper; my $x; eval { $x = require "MyPackage.pm"; } print Dumper($x); Running the test program will print: $VAR0 = 1; I had seen this: __PACKAGE__; So I figured that we could the '1;' to: return bless({ EXPORT_OK => [sort { uc($a) cmp uc ($b) } @EXPORT_OK], },__PACKAGE__); The new result is: $VAR0 = bless({ EXPORT_OK => [ blah ] }, 'MyPackage'); In both cases we can use the returned value in boolean context to determine if the module loaded. The second case however gives us a useful metadata, which could include the version, exported stuff, etc. Other ideas include: - rather than simply blessing a returned result, we could create a Contextual::Return object instead - we could return a reference to some private data - return a coderef to the initialisation function (as opposed to just calling 'import') - return MyPackage's symbol cheers, Mathew -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgc294 at internode.on.net Mon Oct 27 03:37:11 2008 From: sgc294 at internode.on.net (Andrew Dent) Date: Mon, 27 Oct 2008 21:37:11 +1100 Subject: [Melbourne-pm] Strange things about '0' Message-ID: <490599D7.6070607@internode.on.net> G'day I have a problem with zero ('0'), and I'm hoping someone could please help. Sorry in advance for the long explanation. I've written a sub called sql_engine that I would like to put into a module. But before I do, I have two separate problems I'd like to solve. One is when a scalar has the value of 0 and the other is with HTML::Template. The HTML::Template problem I'll put in a separate thread. sql_engine takes a number of parameters to help control it. Its main job is to execute the query and return the results to the calling sub in the required data structure. sql_engine can be called like this my $data = sql_engine($entity, 'array_hash', 'asset_data', 1, $foocode); I've put the first part of the code at the end of the email. It calls prep_query to obtain the correct SQL code based on $query_name. This SQL code is stored in $query. Some queries will be returned with a ? inside them for the where clause. When these queries are required, $var_num and $query_var are also needed, other wise the code will break at the $report->execute() line. sql_engine is given the return type required using the $ret_type variable so I can select a scalar, array, hash, array of hashes etc as the data structure. The database type I am connecting to is Ingres, though I'm not sure if this makes a difference to this problem or not. An example of the query I see the problem with is. select code_descr from c_table where foocode = ? The table called c_table in an Ingres database with only two columns in it. Lets call them 'foocode' and 'description'. The current values of 'foocode' are A, D, S, 0, 1..8. These codes are used in other much larger tables and I sometimes need to filter on those larger tables by using a mixture of codes from the c_table and codes from other tables. Now, if $query_var is a 0 then the ? in the above sql there are no results returned from the query, but the Perl code doesn't break. The Ingres db system must get passed a false value. If I change $query_var to be '0' to try and get the right string into the query in the $report->execute statement it doesn't work. Again the Perl code doesn't break, but I still don't get any results. As the I see the Camel book mentions, Perl equates 0 and '0' both to be false. I think this is why there ar no results of both 0 and '0'. The workaround is to use the ---> if ($query_var... <--- block to modify the SQL code in $query and replace the ? with the string '0'. This is fine at the moment, but if in the future I have SQL code in $query that has more than one ? and I want only one of them to be '0' I'll be in trouble. Is there another way to approach this problem so I can deal with the value of foocode when it is 0, but keeping the sql_engine sub flexible so it can make use of any number of ? in the SQL code, and not have to predict in advance which ? is for foocode. sub sql_engine { my $entity = shift @_; # Used to select the database and all required inside the queries my $ret_type = shift @_; # Determines if this sub should return a scaler, array, hash, array of hashes etc my $query_name = shift @_; # A place to hold the query that will be run my $var_num = shift @_; my $query_var = shift @_; # place to put variables for the SQL query my $dbh = DBI->connect( "DBI:Ingres:database_$entity", 'username' ); my $report; my $query = prep_query($query_name,$entity); # The disp of 0 had to be passed in as '0' because a scaler with the value # of 0 will not be passed in properly to the query if ($query_var eq "'0'") { $var_num = 0; $query =~ s/\?/'0'/; } $report = $dbh->prepare($query); unless ($var_num > 0) { $report->execute(); } else { $report->execute($query_var) } Cheers Andrew Dent From sgc294 at internode.on.net Mon Oct 27 03:41:37 2008 From: sgc294 at internode.on.net (Andrew Dent) Date: Mon, 27 Oct 2008 21:41:37 +1100 Subject: [Melbourne-pm] Looping with HTML::Template Message-ID: <49059AE1.3030406@internode.on.net> G'day Further to the thread about the sub called 'Strange things about '0'. I have the section of Perl below to build up an array of hashes that will get used by HTML::Template after sql_engine finishes. At the moment it is hardcoded to only produce 6 fields in the row. How do I make the .html file flexible so that in the Perl code I can replace the 6 with a variable like $Num_of_fields allowing me to choose at run time how wide the HTML table is? Or is there a different module/technique I should use to get this type of functionality? BTW: That 'FooCode' field below is where one of values of foocode from the other thread will appear and may get filtered on. sub sql_engine { . . . elsif ($ret_type eq 'array_hash') { my $cnt = 0; my @loop_data; while (my @data = $report->fetchrow_array) { my $cell = 0; # This number is used as a temp variable name in the .html file my %row_data; # use a hash to hold the data for each row that HTML::Template will display. # populate the hash. while ($cell < 6) { $row_data{$cell} = shift @data; $cell++; } push (@loop_data, \%row_data); $cnt++; } $report->finish(); $dbh->disconnect; return \@loop_data; } Contents of the .html file
Model Serial Number Customer Number Asset ID FooCode Standard Code
Cheers Andrew Dent From mathew.robertson at netratings.com.au Mon Oct 27 15:20:36 2008 From: mathew.robertson at netratings.com.au (Mathew Robertson) Date: Tue, 28 Oct 2008 09:20:36 +1100 Subject: [Melbourne-pm] Strange things about '0' In-Reply-To: <490599D7.6070607@internode.on.net> References: <490599D7.6070607@internode.on.net> Message-ID: <49063EB4.30601@netratings.com.au> > I have a problem with zero ('0'), and I'm hoping someone could please > help. Sorry in advance for the long explanation. > > I've written a sub called sql_engine that I would like to put into a > module. But before I do, I have two separate problems I'd like to > solve. One is when a scalar has the value of 0 and the other is with > HTML::Template. The HTML::Template problem I'll put in a separate thread. > > sql_engine takes a number of parameters to help control it. Its main > job is to execute the query and return the results to the calling sub > in the required data structure. > sql_engine can be called like this > > my $data = sql_engine($entity, 'array_hash', 'asset_data', 1, $foocode); > > I've put the first part of the code at the end of the email. > It calls prep_query to obtain the correct SQL code based on > $query_name. This SQL code is stored in $query. > Some queries will be returned with a ? inside them for the where > clause. When these queries are required, $var_num and $query_var are > also needed, other wise the code will break at the $report->execute() > line. > sql_engine is given the return type required using the $ret_type > variable so I can select a scalar, array, hash, array of hashes etc as > the data structure. > The database type I am connecting to is Ingres, though I'm not sure if > this makes a difference to this problem or not. > > An example of the query I see the problem with is. > > select code_descr from c_table where foocode = ? > > The table called c_table in an Ingres database with only two columns > in it. Lets call them 'foocode' and 'description'. The current values > of 'foocode' are A, D, S, 0, 1..8. These codes are used in other much > larger tables and I sometimes need to filter on those larger tables by > using a mixture of codes from the c_table and codes from other tables. > > Now, if $query_var is a 0 then the ? in the above sql there are no > results returned from the query, but the Perl code doesn't break. The > Ingres db system must get passed a false value. > If I change $query_var to be '0' to try and get the right string into > the query in the $report->execute statement it doesn't work. Again the > Perl code doesn't break, but I still don't get any results. > As the I see the Camel book mentions, Perl equates 0 and '0' both to > be false. I think this is why there ar no results of both 0 and '0'. Its not Perl's fault -> it (aka DBI) will be passing the literal value to the database - the database should automatically quote numeric values. What you can do is try a simple SQL statement directly to your db, eg: SELECT * FROM some_table WHERE some_column = 0; If this doesn't fail with a bad-statement error, then your db install (like most databases), automatically quotes numeric values. > > The workaround is to use the ---> if ($query_var... <--- block to > modify the SQL code in $query and replace the ? with the string '0'. > This is fine at the moment, but if in the future I have SQL code in > $query that has more than one ? and I want only one of them to be '0' > I'll be in trouble. This approach is dubious... you should be using the bind_param() feature of DBI, which internally uses the corresponding database's specific implementation or the generic DBI implementation. You shouldn't be doing your own placeholder transpositions (unless you are a uber geek). > > Is there another way to approach this problem so I can deal with the > value of foocode when it is 0, but keeping the sql_engine sub flexible > so it can make use of any number of ? in the SQL code, and not have to > predict in advance which ? is for foocode. > > sub sql_engine { > my $entity = shift @_; # Used to select the database and all > required inside the queries > my $ret_type = shift @_; # Determines if this sub should return a > scaler, array, hash, array of hashes etc > my $query_name = shift @_; # A place to hold the query that will be > run > my $var_num = shift @_; > my $query_var = shift @_; # place to put variables for the SQL query > my $dbh = DBI->connect( "DBI:Ingres:database_$entity", 'username' ); > my $report; > my $query = prep_query($query_name,$entity); > # The disp of 0 had to be passed in as '0' because a scaler with > the value > # of 0 will not be passed in properly to the query > if ($query_var eq "'0'") { > $var_num = 0; > $query =~ s/\?/'0'/; > } > > $report = $dbh->prepare($query); > unless ($var_num > 0) { > $report->execute(); > } else { $report->execute($query_var) > } Sounds like you want something like: sub sql_engine { my ($entity,$query_name) = (shift,shift); my $dbh = ...connect(...$entity); my $qry = prep_query($query_name,$entity); my $sth = $dbh->prepare($qry); // one of these: my $max = scalar(@_); for my $p_num (1..$max) { $sth->bind_params($p_num,$_[$p_num-1]); } return $sth->execute; // or return $sth->execute(@_); // or use Contextual::Return; $sth->execute(@_); return ( SCALAR { scalar($sth->fetchall_arrayref()) } LIST { $sth->fetchall_arrayref() } HASHREF { $sth->fetchall_hashref() } VOID { print scalar($sth->fetchall_arref)." rows found" } ); } I'd suggest not passing in the 'array_hash' argument (or any other variation). Either: - use the returned $sth by calling the appropriate method. - try using a contextual return as shown here. Hope this helps, Mathew PS: your post was a little hard to follow - if you post the actual code, it might give some more insight as to what you are trying to do. From mathew.robertson at netratings.com.au Mon Oct 27 15:30:52 2008 From: mathew.robertson at netratings.com.au (Mathew Robertson) Date: Tue, 28 Oct 2008 09:30:52 +1100 Subject: [Melbourne-pm] Looping with HTML::Template In-Reply-To: <49059AE1.3030406@internode.on.net> References: <49059AE1.3030406@internode.on.net> Message-ID: <4906411C.30703@netratings.com.au> > Further to the thread about the sub called 'Strange things about '0'. > I have the section of Perl below to build up an array of hashes that > will get used by HTML::Template after sql_engine finishes. > At the moment it is hardcoded to only produce 6 fields in the row. > > How do I make the .html file flexible so that in the Perl code I can > replace the 6 with a variable like $Num_of_fields allowing me to > choose at run time how wide the HTML table is? > Or is there a different module/technique I should use to get this type > of functionality? > > BTW: That 'FooCode' field below is where one of values of foocode from > the other thread will appear and may get filtered on. > > sub sql_engine { > . > . > . > elsif ($ret_type eq 'array_hash') { > my $cnt = 0; > my @loop_data; > while (my @data = $report->fetchrow_array) { > my $cell = 0; # This number is used as a temp variable name > in the .html file > my %row_data; # use a hash to hold the data for each row > that HTML::Template will display. > # populate the hash. > while ($cell < 6) { > $row_data{$cell} = shift @data; > $cell++; } > push (@loop_data, \%row_data); > $cnt++; > } > $report->finish(); > $dbh->disconnect; > return \@loop_data; } > > Contents of the .html file > > > > > > > > > > > > > > > > > > > > >
ModelSerial NumberCustomer NumberAsset IDFooCodeStandard Code
The simplest solution (albeit, not elegant...) is that the template needs to check if the TMPL_VAR is defined for that cell, as in: ... and so on... Mathew From sgc294 at internode.on.net Mon Oct 27 21:08:07 2008 From: sgc294 at internode.on.net (Andrew Dent) Date: Tue, 28 Oct 2008 15:08:07 +1100 Subject: [Melbourne-pm] Strange things about '0' In-Reply-To: <49063EB4.30601@netratings.com.au> References: <490599D7.6070607@internode.on.net> <49063EB4.30601@netratings.com.au> Message-ID: <49069027.5040307@internode.on.net> Mathew Robertson wrote: >> >> Now, if $query_var is a 0 then the ? in the above sql there are no >> results returned from the query, but the Perl code doesn't break. The >> Ingres db system must get passed a false value. >> If I change $query_var to be '0' to try and get the right string into >> the query in the $report->execute statement it doesn't work. Again >> the Perl code doesn't break, but I still don't get any results. >> As the I see the Camel book mentions, Perl equates 0 and '0' both to >> be false. I think this is why there ar no results of both 0 and '0'. > Its not Perl's fault -> it (aka DBI) will be passing the literal value > to the database - the database should automatically quote numeric > values. What you can do is try a simple SQL statement directly to > your db, eg: > > SELECT * FROM some_table WHERE some_column = 0; > > If this doesn't fail with a bad-statement error, then your db install > (like most databases), automatically quotes numeric values. Yep, I knew it wouldn't be Perl's fault. But I wasn't sure if it was my own or not. :) The above SQL does fail with an error. It is on an old Ingres 2.6 installation. The later versions might handle numeric character to integer conversion better. * select * from valid_disp where disp = 0 \g Executing . . . E_US1130 illegal character to integer conversion or non-numeric character in money field. (Tue Oct 28 11:55:48 2008) >> >> The workaround is to use the ---> if ($query_var... <--- block to >> modify the SQL code in $query and replace the ? with the string '0'. >> This is fine at the moment, but if in the future I have SQL code in >> $query that has more than one ? and I want only one of them to be '0' >> I'll be in trouble. > This approach is dubious... you should be using the bind_param() > feature of DBI, which internally uses the corresponding database's > specific implementation or the generic DBI implementation. You > shouldn't be doing your own placeholder transpositions (unless you are > a uber geek). Oh, I suspected it was dubious. :) but I couldn't find another way to make it work. I'll give the bind_param() feature a try. > > I'd suggest not passing in the 'array_hash' argument (or any other > variation). Either: > - use the returned $sth by calling the appropriate method. > - try using a contextual return as shown here. > Thanks. That code and those ideas look much better. Cheers Andrew Dent From mathew.robertson at netratings.com.au Mon Oct 27 21:26:15 2008 From: mathew.robertson at netratings.com.au (Mathew Robertson) Date: Tue, 28 Oct 2008 15:26:15 +1100 Subject: [Melbourne-pm] Strange things about '0' In-Reply-To: <49069027.5040307@internode.on.net> References: <490599D7.6070607@internode.on.net> <49063EB4.30601@netratings.com.au> <49069027.5040307@internode.on.net> Message-ID: <49069467.8060801@netratings.com.au> >>> Now, if $query_var is a 0 then the ? in the above sql there are no >>> results returned from the query, but the Perl code doesn't break. >>> The Ingres db system must get passed a false value. >>> If I change $query_var to be '0' to try and get the right string >>> into the query in the $report->execute statement it doesn't work. >>> Again the Perl code doesn't break, but I still don't get any results. >>> As the I see the Camel book mentions, Perl equates 0 and '0' both to >>> be false. I think this is why there ar no results of both 0 and '0'. >> Its not Perl's fault -> it (aka DBI) will be passing the literal >> value to the database - the database should automatically quote >> numeric values. What you can do is try a simple SQL statement >> directly to your db, eg: >> >> SELECT * FROM some_table WHERE some_column = 0; >> >> If this doesn't fail with a bad-statement error, then your db install >> (like most databases), automatically quotes numeric values. > Yep, I knew it wouldn't be Perl's fault. But I wasn't sure if it was > my own or not. :) > The above SQL does fail with an error. It is on an old Ingres 2.6 > installation. The later versions might handle numeric character to > integer conversion better. > > * select * from valid_disp where disp = 0 \g > Executing . . . > > E_US1130 illegal character to integer conversion or non-numeric character > in money field. well what do you know... :) it might be worthwhile sending an email to the DBD::Ingres driver developer, suggesting he adds a tech-note to the perldoc, about this quirk. It might even be possible that the driver could be made to automatically handle the conversion for you... eg: detecting when a literal number is used, then converting it to a string. cheers, Mathew From stephen at sydney.pm.org Tue Oct 28 03:03:12 2008 From: stephen at sydney.pm.org (Stephen Steneker) Date: Tue, 28 Oct 2008 21:03:12 +1100 Subject: [Melbourne-pm] Open Source Developers' Conference 2008 -- Earlybird registration closing this Friday In-Reply-To: <48EEA421.1020307@perltraining.com.au> References: <48EEA421.1020307@perltraining.com.au> Message-ID: OSDC 2008 Earlybird registration is closing this Friday! Book by THIS FRIDAY to take advantage of earlybird pricing and be part of the "best" open source developers conference of the year. http://www.osdc.com.au/2008/registration/index.html?ebc=1 The facts: 31st October Earlybird registration closing 2nd December Google Hackathon 3rd - 5th December Conference Program 3rd December Conference Dinner Where is it: SMC Conference and Function Centre 66 Goulburn St Sydney NSW 2000 The Main Conference The Open Source Developers' Conference 2008 is a conference run by open source developers, for developers and business people. This year we have talks covering Apache, Java, Ruby, Perl, PHP, Python, Testing and much more. Our keynote speakers this year are: * Larry Wall, the creator of Perl * Chris DiBona, Open Source Programs Manager for Google * Anthony Baxter, Python Evangelist * Pia Waugh, Consultant, Waugh Partners * Andrew Tridgell, Founder, Samba Team Check out the program for more information: http://www.osdc.com.au/2008/papers/index.html?ebc=1 Google Hackathon The day before the main conference, there will be an optional event. The Google Hackathon will consist of 3 coding workshops during the day with attendance limited to a maximum of 100 people/workshop. To register for any of the workshops, you must have registered for the 3 day OSDC 2008 main conference. Thanks to our sponsors: Google, Corporate Express, Sun Microsystems, Strategic Data, Obsidian Consulting Group, IBM, Zacware/Freeway, ACS, Net Logistics, GROX, UTBox, Internode, Linux Magazine Regards Stephen Steneker OSDC 2008 Committee http://www.osdc.com.au/2008/ From jarich at perltraining.com.au Tue Oct 28 19:21:31 2008 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Wed, 29 Oct 2008 13:21:31 +1100 Subject: [Melbourne-pm] Flyers advertising local PM groups Message-ID: <4907C8AB.7040202@perltraining.com.au> G'day folk, Perl Training Australia teaches Perl to about 100 people a year, scattered over Melbourne, Sydney and Canberra (and occasionally elsewhere - Perth, Adelaide). We *always* mention the appropriate local user group, but I don't get the impression that we ever gain any new members for the groups. One thing I'd really like is to start handing out flyers for groups which might be of interest to our students at the end of the class. I'm planning on mentioning SAGE-AU, the local LUG, the local PM group and the OSDC. What I don't want to have to do is create the flyers. For the PM groups, which are all non-registered informal groups with no funds, we can cover the costs of printing the flyers - in full colour - one or may be 2-sided, for our course purposes. I would hope that having a few flyer designs would also prove useful to the group for things like Software Freedom Day, user group events etc. If you have the skills to make a pretty flyer to advertise your group, mentioning: * PM group name * Website * Meeting schedule (i.e. "2nd Wednesday of the month") * Meeting location * Why people should come (what should they expect?) then please send it to your local list for feedback. etc. We're next training in Canberra (18th - 21st November) and then Sydney (8th - 12th December), so if there is material by then I'd be happy to pass it out. All the best, Jacinta PS: I've sent the reply-to to me so that responses don't spam all three lists. Please direct group responses back to your local list. ;) -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From scottp at dd.com.au Tue Oct 28 19:24:55 2008 From: scottp at dd.com.au (Scott Penrose) Date: Wed, 29 Oct 2008 13:24:55 +1100 (EST) Subject: [Melbourne-pm] Flyers advertising local PM groups In-Reply-To: <4907C8AB.7040202@perltraining.com.au> Message-ID: <33493706.27541225247095007.JavaMail.root@zimbra> Great idea. May I suggest that OSDC would also help pay. We have funds for that sort of purpose. A submission just needs to be made with an estimate of costs to the OSDC Executive. Scott ----- "Jacinta Richardson" wrote: > G'day folk, > > Perl Training Australia teaches Perl to about 100 people a year, > scattered over > Melbourne, Sydney and Canberra (and occasionally elsewhere - Perth, > Adelaide). > We *always* mention the appropriate local user group, but I don't get > the > impression that we ever gain any new members for the groups. > > One thing I'd really like is to start handing out flyers for groups > which might > be of interest to our students at the end of the class. I'm planning > on > mentioning SAGE-AU, the local LUG, the local PM group and the OSDC. > What I > don't want to have to do is create the flyers. For the PM groups, > which are all > non-registered informal groups with no funds, we can cover the costs > of printing > the flyers - in full colour - one or may be 2-sided, for our course > purposes. I > would hope that having a few flyer designs would also prove useful to > the group > for things like Software Freedom Day, user group events etc. > > If you have the skills to make a pretty flyer to advertise your group, > mentioning: > > * PM group name > * Website > * Meeting schedule (i.e. "2nd Wednesday of the month") > * Meeting location > * Why people should come (what should they expect?) > > then please send it to your local list for feedback. etc. We're next > training > in Canberra (18th - 21st November) and then Sydney (8th - 12th > December), so if > there is material by then I'd be happy to pass it out. > > All the best, > > Jacinta > > PS: I've sent the reply-to to me so that responses don't spam all > three lists. > Please direct group responses back to your local list. ;) > > -- > ("`-''-/").___..--''"`-._ | Jacinta Richardson | > `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | > (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | > _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | > (il),-'' (li),' ((!.-' | www.perltraining.com.au | > _______________________________________________ > Melbourne-pm mailing list > Melbourne-pm at pm.org > http://mail.pm.org/mailman/listinfo/melbourne-pm From jarich at perltraining.com.au Tue Oct 28 20:33:17 2008 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Wed, 29 Oct 2008 14:33:17 +1100 Subject: [Melbourne-pm] Talk for next meeting: 12th November Message-ID: <4907D97D.3080600@perltraining.com.au> G'day folk, I haven't heard any suggestions for a talk for our next meeting. At this stage, I don't think Paul will be able to tell you what's going to be new in 5.8.9, and my give-aways won't take all night, so is there anyone burning to tell us something? Perhaps you'd like to practice your OSDC talk? Or give us a talk on what you've been up to recently? J -- ("`-''-/").___..--''"`-._ | Jacinta Richardson | `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | (il),-'' (li),' ((!.-' | www.perltraining.com.au | From tjc at wintrmute.net Thu Oct 30 23:03:36 2008 From: tjc at wintrmute.net (Toby Corkindale) Date: Fri, 31 Oct 2008 17:03:36 +1100 Subject: [Melbourne-pm] feelers Message-ID: <20081031060336.GI21779@roseberry> Hi all, I'm just putting some feelers out on behalf of a friend who has come over to Melbourne from London, and is looking for work. She has a strong Linux background, and a little Perl and coding knowledge, although her strengths are in interface design and QA/testing within open-source development environments. I thought I'd just put the word out in case I could put her in contact with any prospects. Cheers, Toby PS. She's also looking for a house-share to move into.. From alfiejohn at gmail.com Fri Oct 31 03:35:27 2008 From: alfiejohn at gmail.com (Alfie John) Date: Fri, 31 Oct 2008 21:35:27 +1100 Subject: [Melbourne-pm] feelers In-Reply-To: <20081031060336.GI21779@roseberry> References: <20081031060336.GI21779@roseberry> Message-ID: Hey Toby, I can't help on the work front, but you can check out a cool website I know of :) http://www.share-house.com.au Alfie On Fri, Oct 31, 2008 at 5:03 PM, Toby Corkindale wrote: > Hi all, > I'm just putting some feelers out on behalf of a friend who has come over > to > Melbourne from London, and is looking for work. > > She has a strong Linux background, and a little Perl and coding knowledge, > although her strengths are in interface design and QA/testing within > open-source development environments. > > I thought I'd just put the word out in case I could put her in contact with > any > prospects. > > Cheers, > Toby > PS. She's also looking for a house-share to move into.. > _______________________________________________ > Melbourne-pm mailing list > Melbourne-pm at pm.org > http://mail.pm.org/mailman/listinfo/melbourne-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: