From david at naturalpractice.com.au Wed Mar 4 19:28:34 2009 From: david at naturalpractice.com.au (David) Date: Thu, 05 Mar 2009 14:28:34 +1100 Subject: [Melbourne-pm] Contract work (urgent ) - web development Message-ID: <49AF46E2.8050106@naturalpractice.com.au> Hi All, My apologies for clogging up this list with something slightly off topic, but I know that there are a number of people on this list who dabble in other languages, and I've been caught a bit short on some urgent work. So, if you, or someone you know, has experience with php and perl, and are interested in some flexible contract work starting soon (ie next week), please read on. If not please delete this mail and I apologise for taking up your time. We have a client that is ready to launch into stage 2 of development for an online social media site. The site is an online video community dedicated to video games and gaming. The construction of the first phase is complete and the site will be launched within the next week, and the client now wants to move ahead with a number of changes and enhancements. We are looking for someone that is: based in Melbourne an inexperienced php / perl / mysql developer comfortable working on a linux platform You will be required to meet regularly with the client although the rest of the time you will work from your own home / office You will work with the client to scope out the new functionality and provide an estimation on development time for all work. Your services will be subcontracted through the web services company that is managing the client account. There is no definite length for this contract, although on past experience with the client the development may be ongoing for several months. If you are interested and available for the job, please reply to this email with your contact details and a brief resume, work history, etc. if you have it handy. I will get back in touch within 24 hours. Kind regards, David Baxter -------------- next part -------------- An HTML attachment was scrubbed... URL: From crshort at gmail.com Wed Mar 4 20:10:47 2009 From: crshort at gmail.com (Christopher Short) Date: Thu, 5 Mar 2009 15:10:47 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" Message-ID: Hmm ... I've been proven wrong ... (again!) I saw this regex in someone else's code (to check validity of an id field) /^(\w|\@|\.|\-)+$/ and decided that it wouldn't work properly, that what they'd meant was the character array /^[\w\@\.\-]+$/ Luckily I chucked it into Regex Coach and found both of them worked just as well. Thing is, when I look at /^(\w|\@|\.|\-)+$/ I automatically assume it will look for repeated occurences of the first character, as this would: /^(\w|\@|\.|\-)\1*$/ How should I remember that it doesn't work that way? That the "memory brackets" only get used where \1 , $1 etc are specifically mentioned? Turns out the long-term perl developer who wrote that code always uses "pipe brackets" instead of character arrays. Do they really function identically? Christopher From wigs at stirfried.org Wed Mar 4 21:02:34 2009 From: wigs at stirfried.org (wigs at stirfried.org) Date: Thu, 5 Mar 2009 16:02:34 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: References: Message-ID: <20090305050234.GA15279@stirfried.org> On Thu, Mar 05, 2009 at 03:10:47PM +1100, Christopher Short wrote: > I saw this regex in someone else's code (to check validity of an id field) > /^(\w|\@|\.|\-)+$/ > > and decided that it wouldn't work properly, that what they'd meant was > the character array > /^[\w\@\.\-]+$/ > > Luckily I chucked it into Regex Coach and found both of them worked > just as well. > Thing is, when I look at > /^(\w|\@|\.|\-)+$/ The '+' here means one or more repetion of the previous regex, not whatever it happens to match. > Turns out the long-term perl developer who wrote that code always uses > "pipe brackets" instead of character arrays. > Do they really function identically? The biggest difference between character arrays and the parens grouping is that the character array allows for a compact specification of ranges, eg: [a-z] is the same as (?:a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) As such, the hyphen has special meaning within the character set, this is often a source of surprise to some perl developers when the regex doesn't do what they expect. Regards, -- Aaron From toby.corkindale at strategicdata.com.au Wed Mar 4 21:25:40 2009 From: toby.corkindale at strategicdata.com.au (Toby Corkindale) Date: Thu, 05 Mar 2009 16:25:40 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: <20090305050234.GA15279@stirfried.org> References: <20090305050234.GA15279@stirfried.org> Message-ID: <49AF6254.1080403@strategicdata.com.au> wigs at stirfried.org wrote: > On Thu, Mar 05, 2009 at 03:10:47PM +1100, Christopher Short wrote: >> I saw this regex in someone else's code (to check validity of an id field) >> /^(\w|\@|\.|\-)+$/ >> >> and decided that it wouldn't work properly, that what they'd meant was >> the character array >> /^[\w\@\.\-]+$/ > >> Luckily I chucked it into Regex Coach and found both of them worked >> just as well. >> Thing is, when I look at >> /^(\w|\@|\.|\-)+$/ > > The '+' here means one or more repetion of the previous regex, not > whatever it happens to match. > >> Turns out the long-term perl developer who wrote that code always uses >> "pipe brackets" instead of character arrays. >> Do they really function identically? > > The biggest difference between character arrays and the parens grouping > is that the character array allows for a compact specification of ranges, > eg: > > [a-z] is the same as (?:a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) > > As such, the hyphen has special meaning within the character set, > this is often a source of surprise to some perl developers when the > regex doesn't do what they expect. Although it's useful to remember that if the first character in a character array is a hyphen, then it is matched literally, ie: 'foo-bar' =~ /[-a-z]/ ; # is true tjc. From crshort at gmail.com Wed Mar 4 22:04:34 2009 From: crshort at gmail.com (Christopher Short) Date: Thu, 5 Mar 2009 17:04:34 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: References: <20090305050234.GA15279@stirfried.org> Message-ID: Hmm I can never get the hang of MPM not setting the reply-to header!!! :-P ---------- Forwarded message ---------- From: Christopher Short Date: 2009/3/5 Subject: Re: [Melbourne-pm] basic regex - char array vs "pipe brackets" To: wigs at stirfried.org >> /^(\w|\@|\.|\-)+$/ > > The '+' here means one or more repetion of the previous regex, not > whatever it happens to match. cheers, thanks Aaron. I guess my mental parsing was to process the (\w|\@|\.|\-) which == 1 char, and then add the + , whereas the correct parsing is to regard the (\w|\@|\.|\-) and + as inseperable. Justin: > BTW both tests will be true for ids with multiple @s. eg > foo at bar@bah-bah.com. Did you want that behaviour? hehe yeah I know ... also accepts @@@ and --- and .... :-) It's not terribly crucial where it is, tho - it gets checked properly later. :-) Christopher From myfwhite at gmail.com Thu Mar 5 06:03:52 2009 From: myfwhite at gmail.com (Myf White) Date: Fri, 6 Mar 2009 01:03:52 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: <49AF6254.1080403@strategicdata.com.au> References: <20090305050234.GA15279@stirfried.org> <49AF6254.1080403@strategicdata.com.au> Message-ID: <14bb7600903050603k63403d3i29e713dd649a109e@mail.gmail.com> On Thu, Mar 5, 2009 at 4:25 PM, Toby Corkindale < toby.corkindale at strategicdata.com.au> wrote: > wigs at stirfried.org wrote: > >> On Thu, Mar 05, 2009 at 03:10:47PM +1100, Christopher Short wrote: >> >>> I saw this regex in someone else's code (to check validity of an id >>> field) >>> /^(\w|\@|\.|\-)+$/ >>> >>> and decided that it wouldn't work properly, that what they'd meant was >>> the character array >>> /^[\w\@\.\-]+$/ >>> >> >> Luckily I chucked it into Regex Coach and found both of them worked >>> just as well. >>> Thing is, when I look at >>> /^(\w|\@|\.|\-)+$/ >>> >> >> The '+' here means one or more repetion of the previous regex, not >> whatever it happens to match. >> >> Turns out the long-term perl developer who wrote that code always uses >>> "pipe brackets" instead of character arrays. >>> Do they really function identically? >>> >> >> The biggest difference between character arrays and the parens grouping >> is that the character array allows for a compact specification of ranges, >> eg: >> >> [a-z] is the same as >> (?:a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) >> >> As such, the hyphen has special meaning within the character set, >> this is often a source of surprise to some perl developers when the >> regex doesn't do what they expect. >> > > Although it's useful to remember that if the first character in a character > array is a hyphen, then it is matched literally, ie: > > 'foo-bar' =~ /[-a-z]/ ; # is true > > > tjc. Actually, that regex is only matching the first character, ie the 'f', so would be true without the initial hypen. I think you mean that every character in the string is in the character class, so 'foo-bar' =~ /[-a-z]{7}/ ; # is true You can also put the hyphen last in the character classe, ie 'foo-bar' =~ /[a-z-]{7}/ ; # is also true However, I thinks it's better to always put it first, because otherwise it's very easy to miss. -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby.corkindale at strategicdata.com.au Thu Mar 5 15:30:33 2009 From: toby.corkindale at strategicdata.com.au (Toby Corkindale) Date: Fri, 06 Mar 2009 10:30:33 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: <14bb7600903050603k63403d3i29e713dd649a109e@mail.gmail.com> References: <20090305050234.GA15279@stirfried.org> <49AF6254.1080403@strategicdata.com.au> <14bb7600903050603k63403d3i29e713dd649a109e@mail.gmail.com> Message-ID: <49B06099.90803@strategicdata.com.au> Myf White wrote: > On Thu, Mar 5, 2009 at 4:25 PM, Toby Corkindale > > wrote: > > wigs at stirfried.org wrote: > > On Thu, Mar 05, 2009 at 03:10:47PM +1100, Christopher Short wrote: > > I saw this regex in someone else's code (to check validity > of an id field) > /^(\w|\@|\.|\-)+$/ > > and decided that it wouldn't work properly, that what they'd > meant was > the character array > /^[\w\@\.\-]+$/ > > > Luckily I chucked it into Regex Coach and found both of them > worked > just as well. > Thing is, when I look at > /^(\w|\@|\.|\-)+$/ > > > The '+' here means one or more repetion of the previous regex, not > whatever it happens to match. > > Turns out the long-term perl developer who wrote that code > always uses > "pipe brackets" instead of character arrays. > Do they really function identically? > > > The biggest difference between character arrays and the parens > grouping > is that the character array allows for a compact specification > of ranges, > eg: > > [a-z] is the same as > (?:a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z) > > As such, the hyphen has special meaning within the character set, > this is often a source of surprise to some perl developers when the > regex doesn't do what they expect. > > > Although it's useful to remember that if the first character in a > character array is a hyphen, then it is matched literally, ie: > > 'foo-bar' =~ /[-a-z]/ ; # is true > > > tjc. > > > Actually, that regex is only matching the first character, ie the 'f', > so would be true without the initial hypen. Argh, yes! So much for my quick example. I think I meant to write /^[-a-z]+$/ but your example with {7} is clearer. Thanks for spotting it. > I think you mean that every > character in the string is in the character class, so > 'foo-bar' =~ /[-a-z]{7}/ ; # is true > > You can also put the hyphen last in the character classe, ie > 'foo-bar' =~ /[a-z-]{7}/ ; # is also true > > However, I thinks it's better to always put it first, because otherwise > it's very easy to miss. From pjf at perltraining.com.au Thu Mar 5 18:35:33 2009 From: pjf at perltraining.com.au (Paul Fenwick) Date: Fri, 06 Mar 2009 13:35:33 +1100 Subject: [Melbourne-pm] basic regex - char array vs "pipe brackets" In-Reply-To: References: Message-ID: <49B08BF5.2050301@perltraining.com.au> Christopher Short wrote: > Turns out the long-term perl developer who wrote that code always uses > "pipe brackets" instead of character arrays. > Do they really function identically? Conceptually, for the example given, they work the same. But under the hood? They're completely different. If you work with large amounts of data, then they're completely different in a very important way. Let's see what 'use re qw(debug)' has to say. This is under Perl 5.10: $ perl -wne'use re qw(debug); /^(\w|\@\.|\-)+$/;' Compiling REx "^(\w|\@\.|\-)+$" Final program: 1: BOL (2) 2: CURLYX[0] {1,32767} (17) 4: OPEN1 (6) 6: BRANCH (8) 7: ALNUM (14) 8: BRANCH (FAIL) 9: TRIE-EXACT[\-@] (14) <@.> <-> 14: CLOSE1 (16) 16: WHILEM[1/1] (0) 17: NOTHING (18) 18: EOL (19) 19: END (0) $ perl -wne'use re qw(debug); /^[\w at .-]+$/;' Compiling REx "^[\w at .-]+$" synthetic stclass "ANYOF[\-.0-9 at -Z_a-z+utf8::IsWord]". Final program: 1: BOL (2) 2: PLUS (15) 3: ANYOF[\-.0-9 at -Z_a-z+utf8::IsWord] (0) 15: EOL (16) 16: END (0) Without going into the guts too much, the important things to note here is that the first example both does capturing (which takes memory and time), and uses branches (which takes more time when matching your string). The second example builds a 'ANYOF' structure, which is MUCH faster[1]. So not only are character classes (square-brackets) more compact and easier to read, but they go faster, too! All the very best, Paul [1] On my mailserver, with Perl 5.8 and Benchmark, using a square character class approximately doubles the rate at which Perl finds all occurrences that match the regexp on /var/mail/mail.log, as compared to round brackets. Using non-capturing round brackets results in only about a 10% speed improvement. Your mileage may vary. -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From melbourne-pm at popcorn.cx Mon Mar 9 04:39:22 2009 From: melbourne-pm at popcorn.cx (Stephen Edmonds) Date: Mon, 09 Mar 2009 22:39:22 +1100 Subject: [Melbourne-pm] Next meeting: Wednesday 11th March 2009 Message-ID: <49B4FFEA.4080200@popcorn.cx> I'm hoping that these details are still correct for this week's meeting... When: Wednesday, 11th March, 6:30pm Where: Remasys Pty Ltd Level 1 180 Flinders St MELBOURNE VIC 3121 Talk: Perl scripting in Golly 2.0 (Tony) + your 20-30 minute talk goes here Stephen -- Stephen Edmonds Melbourne, Australia stephen at popcorn.cx http://popcorn.cx/ From ddick at aapt.net.au Mon Mar 9 13:40:45 2009 From: ddick at aapt.net.au (David Dick) Date: Tue, 10 Mar 2009 07:40:45 +1100 Subject: [Melbourne-pm] Next meeting: Wednesday 11th March 2009 In-Reply-To: <49B4FFEA.4080200@popcorn.cx> References: <49B4FFEA.4080200@popcorn.cx> Message-ID: <49B57ECD.3040601@aapt.net.au> Stephen Edmonds wrote: > > I'm hoping that these details are still correct for this week's > meeting... > > When: Wednesday, 11th March, 6:30pm > > Where: Remasys Pty Ltd > Level 1 > 180 Flinders St > MELBOURNE VIC 3121 This part sounds correct to me. From pjf at perltraining.com.au Tue Mar 10 17:27:43 2009 From: pjf at perltraining.com.au (Paul Fenwick) Date: Wed, 11 Mar 2009 11:27:43 +1100 Subject: [Melbourne-pm] Next meeting: TONIGHT! In-Reply-To: <49B4FFEA.4080200@popcorn.cx> References: <49B4FFEA.4080200@popcorn.cx> Message-ID: <49B7057F.7020603@perltraining.com.au> G'day Stephen / MPM, Stephen Edmonds wrote: > I'm hoping that these details are still correct for this week's meeting... Stephen, you're a hero. The details are indeed correct! Just to remind everyone, they are (courtesy of Stephen): > When: Wednesday, 11th March, 6:30pm > > Where: Remasys Pty Ltd > Level 1 > 180 Flinders St > MELBOURNE VIC 3121 > > Talk: Perl scripting in Golly 2.0 (Tony) > + your 20-30 minute talk goes here If you've got a 20-30 minute talk or topic you'd like to discuss, then drop a note to the list, or just bring it along. ;) As always, Melbourne Perl Mongers meetings are followed by an informal social gathering. See you all there! Paul -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From simon at unisolve.com.au Tue Mar 10 17:36:55 2009 From: simon at unisolve.com.au (Simon Taylor) Date: Wed, 11 Mar 2009 11:36:55 +1100 Subject: [Melbourne-pm] Next meeting: TONIGHT! In-Reply-To: <49B7057F.7020603@perltraining.com.au> References: <49B4FFEA.4080200@popcorn.cx> <49B7057F.7020603@perltraining.com.au> Message-ID: <49B707A7.5060009@unisolve.com.au> Hello all, >> When: Wednesday, 11th March, 6:30pm >> >> Where: Remasys Pty Ltd >> Level 1 >> 180 Flinders St >> MELBOURNE VIC 3121 >> To be followed by debriefing at Beer DeLuxe over in Fed square? - Simon From lex.lists at gmail.com Tue Mar 10 19:33:36 2009 From: lex.lists at gmail.com (Lex Hider) Date: Wed, 11 Mar 2009 13:33:36 +1100 Subject: [Melbourne-pm] Next meeting: TONIGHT! In-Reply-To: <49B7057F.7020603@perltraining.com.au> References: <49B4FFEA.4080200@popcorn.cx> <49B7057F.7020603@perltraining.com.au> Message-ID: <731bbd770903101933w7273fd0awccb56d0c860fa96@mail.gmail.com> Hi, Was thinking about attending if that's OK? What's involved? I'm a Perl newbie, almost finished "Learning Perl", just bought the Alpaca book. Studied some computer science in the past, run Linux on desktop for almost a decade, looking to start a career in programming eventually. Cheers, Lex. On Wed, Mar 11, 2009 at 11:27 AM, Paul Fenwick wrote: > G'day Stephen / MPM, > > Stephen Edmonds wrote: > > I'm hoping that these details are still correct for this week's > meeting... > > Stephen, you're a hero. The details are indeed correct! Just to remind > everyone, they are (courtesy of Stephen): > > > When: Wednesday, 11th March, 6:30pm > > > > Where: Remasys Pty Ltd > > Level 1 > > 180 Flinders St > > MELBOURNE VIC 3121 > > > > Talk: Perl scripting in Golly 2.0 (Tony) > > + your 20-30 minute talk goes here > > If you've got a 20-30 minute talk or topic you'd like to discuss, then drop > a note to the list, or just bring it along. ;) > > As always, Melbourne Perl Mongers meetings are followed by an informal > social gathering. > > See you all there! > > Paul > > -- > Paul Fenwick | http://perltraining.com.au/ > Director of Training | Ph: +61 3 9354 6001 > Perl Training Australia | Fax: +61 3 9354 2681 > _______________________________________________ > 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: From pjf at perltraining.com.au Tue Mar 10 20:08:42 2009 From: pjf at perltraining.com.au (Paul Fenwick) Date: Wed, 11 Mar 2009 14:08:42 +1100 Subject: [Melbourne-pm] Next meeting: TONIGHT! In-Reply-To: <731bbd770903101933w7273fd0awccb56d0c860fa96@mail.gmail.com> References: <49B4FFEA.4080200@popcorn.cx> <49B7057F.7020603@perltraining.com.au> <731bbd770903101933w7273fd0awccb56d0c860fa96@mail.gmail.com> Message-ID: <49B72B3A.2060607@perltraining.com.au> G'day Lex, Welcome to Melbourne Perl Mongers! Lex Hider wrote: > Was thinking about attending if that's OK? > What's involved? You turn up. ;) If you're feeling social, you may even talk to people. There's no signing in, no registration, no testing of knowledge. It's quite painless, really. > I'm a Perl newbie, almost finished "Learning Perl", just bought the > Alpaca book. > Studied some computer science in the past, run Linux on desktop for > almost a decade, looking to start a career in programming eventually. Excellent! You'll fit right in. I'd recommend sticking around for the social activities afterwards[1]. Melbourne.pm is filled with some very smart people, many of whom are doing some very cool things in Perl. I also like meeting new people, so if you get the chance, say hi to me. ;) Look forward to seeing you there! Paul [1] The social portion usually involves a place that serves beer, and I've seen Simon has already voted for Beer DeLuxe. ;) -- Paul Fenwick | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia | Fax: +61 3 9354 2681 From ddick at aapt.net.au Tue Mar 10 19:45:31 2009 From: ddick at aapt.net.au (David Dick) Date: Wed, 11 Mar 2009 13:45:31 +1100 Subject: [Melbourne-pm] Next meeting: TONIGHT! In-Reply-To: <49B707A7.5060009@unisolve.com.au> References: <49B4FFEA.4080200@popcorn.cx> <49B7057F.7020603@perltraining.com.au> <49B707A7.5060009@unisolve.com.au> Message-ID: <49B725CB.1050507@aapt.net.au> Simon Taylor wrote: > To be followed by debriefing at Beer DeLuxe over in Fed square? I thought we might experiment with Young and Jacksons? From ts at meme.com.au Wed Mar 18 16:54:24 2009 From: ts at meme.com.au (Tony Smith) Date: Thu, 19 Mar 2009 10:54:24 +1100 Subject: [Melbourne-pm] Links from my talk Message-ID: <3E17FF21-53D0-4F52-B765-AA1198C74158@meme.com.au> Yeah, I know it's already a week later. http://golly.sf.net/ http://www.TheWildCA.com/ forthcoming http://www.transforum.net/m.cgi?num=2779 http://www.youtube.com/watch?v=qh_DE_EXNGE Tony Smith 0405 499 718 TransForum Developer http://www.transforum.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gberner at intraspect.com.au Sat Mar 21 18:03:23 2009 From: gberner at intraspect.com.au (Gerd Berner) Date: Sun, 22 Mar 2009 12:03:23 +1100 Subject: [Melbourne-pm] Hash Containing Array Message-ID: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> Hello all I'm having a few problems with some basic object oriented methods. My constructor and set method works fine, but I'm struggling to read the keys back from the object once it is created. My methods are attached below along with a screen dump of the created object. Any help would be greatly appreciated. sub new { my $class=shift; my $self = {}; $self->{_DATASET}=undef; $self->{_RULE}=undef; $self->{_PRIVILEGE}=undef; $self->{_ACC_VIA_RULE}= {}; $self->{_ACC_VIA_PRIV}= []; $self->{_CAN_UPDATE_RULE} =[]; bless ($self,$class); return $self; } sub set_acc_via_rule { my $self = shift; my $key = shift; my @val = @_; foreach my $val (@val) { unshift @{$self->{_ACC_VIA_RULE}{$key}},$val; } return; } sub get_back_keys { my $self = shift; my ($key,$value); while (my ($key,$value) = each ($self->{_ACC_VIA_RULE})) {unshift @keys,$key;} return @keys; } Type of arg 1 to each must be hash (not hash element) at acf2_dataset.pm line 122, near "})" Regards Gerd -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Picture 2.png Type: image/png Size: 12877 bytes Desc: not available URL: From jarich at perltraining.com.au Sat Mar 21 18:48:26 2009 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Sun, 22 Mar 2009 12:48:26 +1100 Subject: [Melbourne-pm] Hash Containing Array In-Reply-To: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> References: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> Message-ID: <49C598EA.9020603@perltraining.com.au> I've expanded the code a little to include some scaffolding, so I'm working with: ########################################## package Foo; use strict; use warnings; sub new { my $class = shift; my $self = {}; $self->{_DATASET} = undef; $self->{_RULE} = undef; $self->{_PRIVILEGE} = undef; $self->{_ACC_VIA_RULE} = {}; $self->{_ACC_VIA_PRIV} = []; $self->{_CAN_UPDATE_RULE} = []; bless( $self, $class ); return $self; } sub set_acc_via_rule { my $self = shift; my $key = shift; my @val = @_; foreach my $val (@val) { unshift @{ $self->{_ACC_VIA_RULE}{$key} }, $val; } return; } sub get_back_keys { my $self = shift; my ( $key, $value ); while ( my ( $key, $value ) = each( $self->{_ACC_VIA_RULE} ) ) { unshift @keys, $key; } return @keys; } package main; use strict; use warnings; use Data::Dumper; my $foo = Foo->new(); $foo->set_acc_via_rule("bar", (1..10)); $foo->set_acc_via_rule("baz", ('a'..'j')); print Dumper $foo; ########################################## This still yields the same error you were getting: Type of arg 1 to each must be hash (not hash element) at test.pl line 31, near "} ) " and also: Global symbol "@keys" requires explicit package name at test.pl line 32. Global symbol "@keys" requires explicit package name at test.pl line 34. because you never declare @keys in your get_back_keys method. If we comment out get_back_keys and run this we get the following Data::Dumper structure: $VAR1 = bless( { '_RULE' => undef, '_CAN_UPDATE_RULE' => [], '_PRIVILEGE' => undef, '_ACC_VIA_PRIV' => [], '_ACC_VIA_RULE' => { 'bar' => [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ], 'baz' => [ 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a' ] }, '_DATASET' => undef }, 'Foo' ); Now I'm guessing from your code that what you want is a method that just returns 'bar' and 'baz'. For this, we don't need to use each, because we don't care about the values, only the keys. Thus we can write: sub get_back_keys { my $self = shift; my @keys; foreach my $key ( keys %{ $self->{_ACC_VIA_RULE} } ) { unshift @keys, $key; } return @keys; } The main mistake you were making was not telling Perl to dereference your hash. When you wrote: while ( my ( $key, $value ) = each( $self->{_ACC_VIA_RULE} ) ) you were passing a hash _reference_ to each when each expected a hash. To dereference this into a hash we need to change: $self->{_ACC_VIA_RULE} to: %{ $self->{_ACC_VIA_RULE} } which is what I did so that I passed the hash to keys, not the hash reference. Making this small change in your code (and adding "my @keys;" makes your code work). You are using "unshift" a lot, where most people would use "push". unshift adds something to the start of the array, whereas push adds it to the end of the array. The syntax is the same. I realise this might be a coding requirement, but if not, it's worth being aware that most people will expect to see push rather than unshift. The following two snippets achieve the same result: foreach my $val (@val) { unshift @{ $self->{_ACC_VIA_RULE}{$key} }, $val; } foreach my $val (reverse @val) { push @{ $self->{_ACC_VIA_RULE}{$key} }, $val; } By all means use unshift if it does what you require! All the best, Jacinta From daniel at rimspace.net Sat Mar 21 19:12:21 2009 From: daniel at rimspace.net (Daniel Pittman) Date: Sun, 22 Mar 2009 13:12:21 +1100 Subject: [Melbourne-pm] Hash Containing Array In-Reply-To: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> (Gerd Berner's message of "Sun, 22 Mar 2009 12:03:23 +1100") References: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> Message-ID: <878wmypapm.fsf@rimspace.net> Gerd Berner writes: > I'm having a few problems with some basic object oriented methods. Mostly, casting and referencing of data structures; the same issue would happen in a non-OO program. > My constructor and set method works fine, but I'm struggling to read > the keys back from the object once it is created. My methods are > attached below along with a screen dump of the created object. Any > help would be greatly appreciated. > > sub new { [...] > $self->{_ACC_VIA_RULE}= {}; Here you correctly set _ACC_VIA_RULE to a HASHREF. [...] > sub set_acc_via_rule [...] > unshift @{$self->{_ACC_VIA_RULE}{$key}},$val; You want '$self->{_ACC_VIA_RULE}->{$key}' Notice the extra '->' dereference? That is there because a hash value is a scalar, which means you can only store a HASHREF, not a HASH in it. [...] > sub get_back_keys [...] > while (my ($key,$value) = each ($self->{_ACC_VIA_RULE})) Here you want: %{ $self->{_ACC_VIA_RULE} } Notice the cast to a HASH? That is needed to turn the HASHREF back into a normal HASH, which each can operate on. Regards, Daniel From jarich at perltraining.com.au Sat Mar 21 19:21:00 2009 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Sun, 22 Mar 2009 13:21:00 +1100 Subject: [Melbourne-pm] Hash Containing Array In-Reply-To: <878wmypapm.fsf@rimspace.net> References: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> <878wmypapm.fsf@rimspace.net> Message-ID: <49C5A08C.6090204@perltraining.com.au> Daniel Pittman wrote: >> sub set_acc_via_rule > > [...] > >> unshift @{$self->{_ACC_VIA_RULE}{$key}},$val; > > You want '$self->{_ACC_VIA_RULE}->{$key}' FWIW, Perl allows the short-cut Gerd used above, and the two statements: $self->{_ACC_VIA_RULE}{$key} $self->{_ACC_VIA_RULE}->{$key} are equivalent. This is because if you're looking up an additional key (or so), the only thing the left can be returning is a reference and thus the second and further arrows can be omitted. The first arrow is of course still always required (when dealing with references). All the best, J From daniel at rimspace.net Sat Mar 21 21:17:15 2009 From: daniel at rimspace.net (Daniel Pittman) Date: Sun, 22 Mar 2009 15:17:15 +1100 Subject: [Melbourne-pm] Hash Containing Array In-Reply-To: <49C5A08C.6090204@perltraining.com.au> (Jacinta Richardson's message of "Sun, 22 Mar 2009 13:21:00 +1100") References: <8AF995BA-9092-4ED7-A604-CAF43E004B8E@intraspect.com.au> <878wmypapm.fsf@rimspace.net> <49C5A08C.6090204@perltraining.com.au> Message-ID: <87zlfenqd0.fsf@rimspace.net> Jacinta Richardson writes: > Daniel Pittman wrote: > >>> sub set_acc_via_rule >> >> [...] >> >>> unshift @{$self->{_ACC_VIA_RULE}{$key}},$val; >> >> You want '$self->{_ACC_VIA_RULE}->{$key}' > > FWIW, Perl allows the short-cut Gerd used above, and the two statements: > > $self->{_ACC_VIA_RULE}{$key} > $self->{_ACC_VIA_RULE}->{$key} > > are equivalent. Really? Well, I stand corrected, if surprised. Regards, Daniel From blmarsh at gmail.com Tue Mar 24 05:27:59 2009 From: blmarsh at gmail.com (Ben Marsh) Date: Tue, 24 Mar 2009 23:27:59 +1100 Subject: [Melbourne-pm] Using perl libraries to apply XSL to XML Message-ID: Hi, I am writing a www bot that gets xml from a website that includes a xsl stylesheet to apply to the xml to give html. Browsers seem to do this for us when browsing the site. WWW::Mechanize does not seem to. I wrote some code but hit a conundrum. How do I get the url of the xsl from the xml content, fetch it via http and apply it to the xml using XML::LibXSLT? Hi, Thanks for the reply. I realized that I need libxslt. But unless I am missing something I don't see how to pull the xsl uri out of the xml and feed it to libxslt (XML::LibXSLT). That is my problem. the xml starts with: ... Maybe I should just grep through the xml to find the stylesheet? Maybe I feed XML::LibXSLT a URL? Maybe I just feed the xml to XML::LibXSLT and it fetches the XSL stylesheet automagically? I don't know. I have not been able to figure out more than what I have below from the docos and examples. Can you help me? Thanks, Ben Marsh Here is my code: use lib qw|/home/blm/perl/lib|; use strict; use WWW::Mechanize; use XML::LibXML; use XML::LibXSLT; my $mech = WWW::Mechanize->new(agent => 'Mozilla/5.0 (X11; U; Linux i686; en-US;+ rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1' ); my $url = 'https://some.url.here/'; $mech->delete_header('accept-encoding'); $mech->get($url); $mech->update_html($mech->content()); print $mech->content; my $parser = XML::LibXML->new(); my $style_parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $doc = $parser->parse_string($mech->content()); print $doc->toString(); my $stylesheet_location = ***Here is my problem*** $mech->get($stylesheet_location); my $stylesheet_string = $mech->content(); my $styledoc = $style_parser->parse_string($stylesheet_string); my $stylesheet = $xslt->parse_stylesheet($styledoc); my $results = $xslt->transform($doc); print $results; -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel at rimspace.net Tue Mar 24 05:39:28 2009 From: daniel at rimspace.net (Daniel Pittman) Date: Tue, 24 Mar 2009 23:39:28 +1100 Subject: [Melbourne-pm] Using perl libraries to apply XSL to XML In-Reply-To: (Ben Marsh's message of "Tue, 24 Mar 2009 23:27:59 +1100") References: Message-ID: <87hc1jt7r3.fsf@rimspace.net> Ben Marsh writes: > I am writing a www bot that gets xml from a website that includes a > xsl stylesheet to apply to the xml to give html. Browsers seem to do > this for us when browsing the site. Well, modern ones do. I still remember the days before XSLT support was widespread. ;) > WWW::Mechanize does not seem to? No, although you could theoretically write a plugin... > I wrote some code but hit a conundrum.? How do I get the url of the > xsl from the xml content, fetch it via http and apply it to the xml > using XML::LibXSLT? [...] > the xml starts with: > > > See that line? That is a standard and all, so you can (reasonably) robustly rely on that stylesheet declaration together with the standard HTTP rules for URL combination to locate and fetch the stylesheet. Regards, Daniel From jarich at perltraining.com.au Wed Mar 25 17:15:25 2009 From: jarich at perltraining.com.au (jarich at perltraining.com.au) Date: Thu, 26 Mar 2009 11:15:25 +1100 (EST) Subject: [Melbourne-pm] SAGE-AU'2009 Last Call for Presentations Message-ID: <20090326001525.98AA9A84D1@teddybear.perltraining.com.au> Dear Melbourne Perl Mongers members, Please forward this invitation to anyone you feel would be interested. Proposals due: Friday 3rd April 2009! 17th Annual System Administrators' Conference (SAGE-AU 2009) ============================================================ The System Administrators' Guild of Australia Gold Coast, 10-14th August 2009 SAGE-AU was formed to advance the profession of System Administration by raising awareness of the need for System Administrators, and educating System Administrators in technical as well as professional issues. Our yearly conference provides a forum for System Administrators of all platforms and levels of experience to gather together and share their experiences. Further it provides an excellent opportunity to meet and network with acknowledged experts in the field. SAGE-AU 2009 will be held in the Gold Coast from the 10th-14th August. The theme this year has changed slightly to be based on the CIA model (Confidentiality, Integrity and Availability) with a particular focus on the effects of internet content filtering. Talks or tutorials covering this or related fields are particularly welcomed. Training Program: 10th - 12th August ------------------------------------ SAGE-AU 2009 will include three days of training sessions of both 3 hours and 6 hours duration. Previous years have included tutorials on topics such as: * Management practices for System Administrators * Disaster recovery and high availability * Computer and network security * High performance * Networking * Cross platform interoperability For more details and to submit your proposal(s), visit our Call for Technical Presentations. http://www.sage-au.org.au//x/cgAG Technical Program: 14th - 15th August ------------------------------------- Due to the huge success of last year's change in format, this year again there will be two parallel streams of talks running. If your job includes looking after systems, networks, or machines for which you are not the sole-user, we'd love to hear you speak! Previous years have included talks on topics such as: * Selling yourself/your team * Successful negotiation * Disasters recovered * Security issues * Tools, tricks and tips * Standards For more details and to submit your proposal(s), visit our Call for Technical Presentations. http://www.sage-au.org.au//x/cgAG If you have any questions or require assistance with your submission, please don't hesitate to ask! SAGE-AU 2009 Gold Coast ------------------- Call for Papers/Tutorials Issued 23rd February 2009 Proposals Due 3rd April 2009 Provisional Notification 27th April 2009 Draft Paper/Tutorials Due 1st June 2009 Confirmed Acceptance and Contracts 15th June 2009 Final Paper/Tutorial Materials Due 13th July 2009 For all information, contacts and updates, see the SAGE-AU conference web site at http://www.sage-au.org.au/display/conf/ From camillo.pereira at gmail.com Thu Mar 26 22:44:35 2009 From: camillo.pereira at gmail.com (Camillo Pereira) Date: Fri, 27 Mar 2009 16:44:35 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information Message-ID: Hi, I have the following scenario where I need to extract node name information based on certain conditions from an application, and write the data out to a file and HUP the process concerned. I have managed to get to a certain point however need some advise. Script output: #!/usr/bin/perl use strict; use warnings; ## Cut down version of regex list my @critical_device_def = ( [AAA => qr{...apb09} ], [BBB => qr{...avggd09} ], [CCC => qr{...uytwop09} ], [DDD => qr{...loupoi09} ] ); my @DEVICE_LIST; my $file = "rules.txt"; my @tokens; open(UPDATE, ">$file") || die "Can't open new file: $!\n"; @DEVICE_LIST=`/opt/OV/bin/ovtopodump | awk '\$3 ~ /^[a-z]+.*\.my\.domain\.com\.au/{print \$3}'| uniq`; foreach (@DEVICE_LIST) { for my $t (@critical_device_def) { my ($site, $device, $flag) = @$t; if ($_ =~ m/\G($device)/gc) { print UPDATE "$_" ; next; } } } ===== The problem I am having is that at the print UPDATE line, I need to append to the data a tab and the number 1. With the current code, the file output looks like this: cpploupoi09.my.domain.com.au cpqavggd09.my.domain.com.au however, I need the contents to be printed to the file in the format below where the hostname then a tab and the number one is printed: cpploupoi09.my.domain.com.au 1 cpqavggd09.my.domain.com.au 1 What is the best way to do this? Also what is the best way to send a HUP signal to a running Unix process? Appreciate your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mathew.robertson at netratings.com.au Thu Mar 26 23:35:48 2009 From: mathew.robertson at netratings.com.au (Mathew Robertson) Date: Fri, 27 Mar 2009 17:35:48 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information In-Reply-To: References: Message-ID: <49CC73C4.6040301@netratings.com.au> print UPDATE "$_\t1" "ps auxww" will give you a process list, from which you can get the PID, so that you can call "kill -HUP " Hope this helps, Mathew Robertson Camillo Pereira wrote: > Hi, > > I have the following scenario where I need to extract node name > information based on certain conditions from an application, and write > the data out to a file and HUP the process concerned. I have managed > to get to a certain point however need some advise. > > Script output: > > #!/usr/bin/perl > use strict; > use warnings; > > ## Cut down version of regex list > > my @critical_device_def = ( > [AAA => qr{...apb09} ], > [BBB => qr{...avggd09} ], > [CCC => qr{...uytwop09} ], > [DDD => qr{...loupoi09} ] > > ); > > my @DEVICE_LIST; > my $file = "rules.txt"; > my @tokens; > > open(UPDATE, ">$file") || die "Can't open new file: $!\n"; > > @DEVICE_LIST=`/opt/OV/bin/ovtopodump | awk '\$3 ~ > /^[a-z]+.*\.my\.domain\.com\.au/{print \$3}'| uniq`; > > foreach (@DEVICE_LIST) > { > for my $t (@critical_device_def) > { > my ($site, $device, $flag) = @$t; > if ($_ =~ m/\G($device)/gc) > { > > print UPDATE "$_" ; > next; > } > > } > > } > > ===== > > The problem I am having is that at the print UPDATE line, I need to > append to the data a tab and the number 1. With the current code, the > file output looks like this: > > cpploupoi09.my.domain.com.au > cpqavggd09.my.domain.com.au > > however, I need the contents to be printed to the file in the format > below where the hostname then a tab and the number one is printed: > > cpploupoi09.my.domain.com.au > 1 > cpqavggd09.my.domain.com.au > 1 > > What is the best way to do this? > > Also what is the best way to send a HUP signal to a running Unix process? > > Appreciate your help. > > ------------------------------------------------------------------------ > > _______________________________________________ > 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: From camillo.pereira at gmail.com Fri Mar 27 00:06:44 2009 From: camillo.pereira at gmail.com (Camillo Pereira) Date: Fri, 27 Mar 2009 18:06:44 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information In-Reply-To: <49CC73C4.6040301@netratings.com.au> References: <49CC73C4.6040301@netratings.com.au> Message-ID: Thanks for the reply. This is something that I had tried as well, however, the format of the file ends up looking like the following: cpploupoi09.my.domain.com.au 1cabloupoi08.my.domain.com.au 1cacloupoi07.my.domain.com.au 1cadloupoi06.my.domain.com.au 1caeloupoi05.my.domain.com.au 1cafloupoi06.my.domain.com.au 1 Thanks for HUP signal part. I will use the system() function to send the command. Any other hints in relation to the previous item? 2009/3/27 Mathew Robertson > print UPDATE "$_\t1" > > > "ps auxww" will give you a process list, from which you can get the PID, so > that you can call "kill -HUP " > > Hope this helps, > Mathew Robertson > > Camillo Pereira wrote: > > Hi, > > I have the following scenario where I need to extract node name information > based on certain conditions from an application, and write the data out to a > file and HUP the process concerned. I have managed to get to a certain > point however need some advise. > > Script output: > > #!/usr/bin/perl > use strict; > use warnings; > > ## Cut down version of regex list > > my @critical_device_def = ( > [AAA => qr{...apb09} ], > [BBB => qr{...avggd09} ], > [CCC => qr{...uytwop09} ], > [DDD => qr{...loupoi09} ] > > ); > > my @DEVICE_LIST; > my $file = "rules.txt"; > my @tokens; > > open(UPDATE, ">$file") || die "Can't open new file: $!\n"; > > @DEVICE_LIST=`/opt/OV/bin/ovtopodump | awk '\$3 ~ > /^[a-z]+.*\.my\.domain\.com\.au/{print \$3}'| uniq`; > > foreach (@DEVICE_LIST) > { > for my $t (@critical_device_def) > { > my ($site, $device, $flag) = @$t; > if ($_ =~ m/\G($device)/gc) > { > > print UPDATE "$_" ; > next; > } > > } > > } > > ===== > > The problem I am having is that at the print UPDATE line, I need to append > to the data a tab and the number 1. With the current code, the file output > looks like this: > > cpploupoi09.my.domain.com.au > cpqavggd09.my.domain.com.au > > however, I need the contents to be printed to the file in the format below > where the hostname then a tab and the number one is printed: > > cpploupoi09.my.domain.com.au 1 > cpqavggd09.my.domain.com.au 1 > > What is the best way to do this? > > Also what is the best way to send a HUP signal to a running Unix process? > > Appreciate your help. > > ------------------------------ > > _______________________________________________ > Melbourne-pm mailing listMelbourne-pm at pm.orghttp://mail.pm.org/mailman/listinfo/melbourne-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jarich at perltraining.com.au Fri Mar 27 02:58:12 2009 From: jarich at perltraining.com.au (Jacinta Richardson) Date: Fri, 27 Mar 2009 20:58:12 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information In-Reply-To: References: <49CC73C4.6040301@netratings.com.au> Message-ID: <49CCA334.5030005@perltraining.com.au> Camillo Pereira wrote: > This is something that I had tried as well, however, the format of the > file ends up looking like the following: > cpploupoi09.my.domain.com.au > 1cabloupoi08.my.domain.com.au > 1cacloupoi07.my.domain.com.au > 1cadloupoi06.my.domain.com.au > 1caeloupoi05.my.domain.com.au > 1cafloupoi06.my.domain.com.au > 1 This suggests that the lines with your domain names on them have newlines still attached. You'll need to chomp these newlines off (perldoc -f chomp). For example: foreach (@DEVICE_LIST) { foreach my $t (@critical_device_def) { my ($site, $device, $flag) = @$t; if ($_ =~ m/\G($device)/gc) { chomp; print UPDATE "$_\t1\n" ; next; } } } I'm a bit worried about this line: if ($_ =~ m/\G($device)/gc) (which we'd normally write: if( m/\G$device/gc ) because you don't seem to be using $1 and matches work on $_ by default). It's very rare to need to use \G and /g, and I can't think of any way you'd need to be using it if you're going to call next; straight after a match. \G allows you to restart the regular expression from the end of the last successful match and try to match again from there. For example this code, with the repeating \G match line commented out: my $str = "catsatmat"; foreach (1..3) { #if( $str =~ m{\G(\wat)}g ) { if( $str =~ m{(\wat)} ) { print "$1\n"; } } gives us: cat cat cat If we swap the if statements, then we get: cat sat mat Since you're calling next after your successful match, I'd rewrite your inner loop to be: foreach my $t (@critical_device_def) { my ($site, $device, $flag) = @$t; if ($_ =~ m/$device/) { chomp; print UPDATE "$_\t1\n" ; } } I'm assuming that since you don't appear to know what $device matched you don't need to capture it. If you've simplified your code a lot, I might be wrong. I'm also assuming that you won't now need the next, but if you're doing extra stuff after the if() that you don't want to do on a match, you'll need to put it back in. Finally, you define a bunch of patters: my @critical_device_def = ( [AAA => qr{...apb09} ], [BBB => qr{...avggd09} ], [CCC => qr{...uytwop09} ], [DDD => qr{...loupoi09} ], ); Using fat-comma here - while completely appropriate - may cause some people to misread this as a number of hash references. I just recommend to you that you keep that in mind. All the best, 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 hamish at hamishcarpenter.com Fri Mar 27 03:07:21 2009 From: hamish at hamishcarpenter.com (Hamish Carpenter) Date: Fri, 27 Mar 2009 21:07:21 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information In-Reply-To: References: <49CC73C4.6040301@netratings.com.au> Message-ID: <49CCA559.4080203@hamishcarpenter.com> Camillo, I believe the output you are getting has a newline at the end of each domain. You will need to chomp() each line of output to remove the newline and then manually append a new line. chomp; print UPDATE "$_\t1\n"; See `perldoc -f chomp` for more info on chomp. Hamish Camillo Pereira wrote: > Thanks for the reply. > > This is something that I had tried as well, however, the format of the > file ends up looking like the following: > > cpploupoi09.my.domain.com.au > cpqavggd09.my.domain.com.au > 1cabloupoi08.my.domain.com.au > 1cacloupoi07.my.domain.com.au > 1cadloupoi06.my.domain.com.au > 1caeloupoi05.my.domain.com.au > 1cafloupoi06.my.domain.com.au > 1 > > Thanks for HUP signal part. I will use the system() function to send > the command. > > Any other hints in relation to the previous item? > > > 2009/3/27 Mathew Robertson > > > print UPDATE "$_\t1" > > > "ps auxww" will give you a process list, from which you can get the > PID, so that you can call "kill -HUP " > > Hope this helps, > Mathew Robertson > > Camillo Pereira wrote: >> Hi, >> >> I have the following scenario where I need to extract node name >> information based on certain conditions from an application, and >> write the data out to a file and HUP the process concerned. I >> have managed to get to a certain point however need some advise. >> >> Script output: >> >> #!/usr/bin/perl >> use strict; >> use warnings; >> >> ## Cut down version of regex list >> >> my @critical_device_def = ( >> [AAA => qr{...apb09} ], >> [BBB => qr{...avggd09} ], >> [CCC => qr{...uytwop09} ], >> [DDD => qr{...loupoi09} ] >> >> ); >> >> my @DEVICE_LIST; >> my $file = "rules.txt"; >> my @tokens; >> >> open(UPDATE, ">$file") || die "Can't open new file: $!\n"; >> >> @DEVICE_LIST=`/opt/OV/bin/ovtopodump | awk '\$3 ~ >> /^[a-z]+.*\.my\.domain\.com\.au/{print \$3}'| uniq`; >> >> foreach (@DEVICE_LIST) >> { >> for my $t (@critical_device_def) >> { >> my ($site, $device, $flag) = @$t; >> if ($_ =~ m/\G($device)/gc) >> { >> >> print UPDATE "$_" ; >> next; >> } >> >> } >> >> } >> >> ===== >> >> The problem I am having is that at the print UPDATE line, I need >> to append to the data a tab and the number 1. With the current >> code, the file output looks like this: >> >> cpploupoi09.my.domain.com.au >> cpqavggd09.my.domain.com.au >> >> however, I need the contents to be printed to the file in the >> format below where the hostname then a tab and the number one is >> printed: >> >> cpploupoi09.my.domain.com.au >> 1 >> cpqavggd09.my.domain.com.au >> 1 >> >> What is the best way to do this? >> >> Also what is the best way to send a HUP signal to a running Unix >> process? >> >> Appreciate your help. >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Melbourne-pm mailing list >> Melbourne-pm at pm.org >> http://mail.pm.org/mailman/listinfo/melbourne-pm > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Melbourne-pm mailing list > Melbourne-pm at pm.org > http://mail.pm.org/mailman/listinfo/melbourne-pm From camillo.pereira at gmail.com Fri Mar 27 04:34:06 2009 From: camillo.pereira at gmail.com (Camillo Pereira) Date: Fri, 27 Mar 2009 22:34:06 +1100 Subject: [Melbourne-pm] Writing array data to file with appended information In-Reply-To: <49CCA334.5030005@perltraining.com.au> References: <49CC73C4.6040301@netratings.com.au> <49CCA334.5030005@perltraining.com.au> Message-ID: Hi Jacinta and Hamish, Thanks for pointing out to use the chomp function. That has done the trick. As I am fairly new to Perl, I could not for the life of me work this out. Jacinta, thanks also for explaining other items related to the code. I have modified it accordingly. Thanks for your assistance. 2009/3/27 Jacinta Richardson > Camillo Pereira wrote: > > > This is something that I had tried as well, however, the format of the > > file ends up looking like the following: > > > cpploupoi09.my.domain.com.au > > 1cabloupoi08.my.domain.com.au > > 1cacloupoi07.my.domain.com.au > > 1cadloupoi06.my.domain.com.au > > 1caeloupoi05.my.domain.com.au > > 1cafloupoi06.my.domain.com.au > > 1 > > This suggests that the lines with your domain names on them have newlines > still > attached. You'll need to chomp these newlines off (perldoc -f chomp). For > example: > > foreach (@DEVICE_LIST) > { > foreach my $t (@critical_device_def) > { > my ($site, $device, $flag) = @$t; > if ($_ =~ m/\G($device)/gc) > { > chomp; > print UPDATE "$_\t1\n" ; > next; > } > } > } > > I'm a bit worried about this line: > > if ($_ =~ m/\G($device)/gc) > > (which we'd normally write: > > if( m/\G$device/gc ) > > because you don't seem to be using $1 and matches work on $_ by default). > > It's very rare to need to use \G and /g, and I can't think of any way you'd > need > to be using it if you're going to call next; straight after a match. \G > allows > you to restart the regular expression from the end of the last successful > match > and try to match again from there. For example this code, with the > repeating \G > match line commented out: > > my $str = "catsatmat"; > > foreach (1..3) { > #if( $str =~ m{\G(\wat)}g ) { > if( $str =~ m{(\wat)} ) { > print "$1\n"; > } > } > > gives us: > > cat > cat > cat > > If we swap the if statements, then we get: > > cat > sat > mat > > Since you're calling next after your successful match, I'd rewrite your > inner > loop to be: > > foreach my $t (@critical_device_def) > { > my ($site, $device, $flag) = @$t; > if ($_ =~ m/$device/) > { > chomp; > print UPDATE "$_\t1\n" ; > } > } > > I'm assuming that since you don't appear to know what $device matched you > don't > need to capture it. If you've simplified your code a lot, I might be > wrong. > I'm also assuming that you won't now need the next, but if you're doing > extra > stuff after the if() that you don't want to do on a match, you'll need to > put it > back in. > > Finally, you define a bunch of patters: > > my @critical_device_def = ( > [AAA => qr{...apb09} ], > [BBB => qr{...avggd09} ], > [CCC => qr{...uytwop09} ], > [DDD => qr{...loupoi09} ], > ); > > Using fat-comma here - while completely appropriate - may cause some people > to > misread this as a number of hash references. I just recommend to you that > you > keep that in mind. > > All the best, > > J > > -- > ("`-''-/").___..--''"`-._ | Jacinta Richardson | > `6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia | > (_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 | > _..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au | > (il),-'' (li),' ((!.-' | www.perltraining.com.au | =============================================================== ---------- Forwarded message ---------- From: Hamish Carpenter Date: 2009/3/27 Subject: Re: [Melbourne-pm] Writing array data to file with appended information To: Camillo Pereira Cc: melbourne-pm at pm.org Camillo, I believe the output you are getting has a newline at the end of each domain. You will need to chomp() each line of output to remove the newline and then manually append a new line. chomp; print UPDATE "$_\t1\n"; See `perldoc -f chomp` for more info on chomp. Hamish -------------- next part -------------- An HTML attachment was scrubbed... URL: From scottp at dd.com.au Mon Mar 30 02:42:41 2009 From: scottp at dd.com.au (Scott Penrose) Date: Mon, 30 Mar 2009 20:42:41 +1100 Subject: [Melbourne-pm] Authentication ? Message-ID: Hey Guys If you wanted to do authentication on apache with the following basic features: * (optional) Ability to register your own account with email token validation * (optional) ability to use 3rd party accounts (ala OpenID) * Password recovery via email token * Apache Module for login & access control It seems that most open source code does authentication & registration internally. So I am collecting what people would use that is independent of framework or product - but can depend on Apache? Ta Scott From stephen at sydney.pm.org Mon Mar 30 02:53:50 2009 From: stephen at sydney.pm.org (Stephen Steneker) Date: Mon, 30 Mar 2009 20:53:50 +1100 Subject: [Melbourne-pm] Authentication ? In-Reply-To: References: Message-ID: > If you wanted to do authentication on apache with the following > basic features: > > * (optional) Ability to register your own account with email token > validation > * (optional) ability to use 3rd party accounts (ala OpenID) > * Password recovery via email token > * Apache Module for login & access control > > It seems that most open source code does authentication & > registration internally. > > So I am collecting what people would use that is independent of > framework or product - but can depend on Apache? Hi Scott, I'd suggest mod_auth_tkt : http://openfusion.com.au/labs/mod_auth_tkt/ "mod_auth_tkt hands off the authentication and authorisation problem to the URL of your choice. This means that you can use whatever technology (CGI, Perl, PHP, ASP, Java etc.) and whatever repositories (passwd files, LDAP, NIS, RDBMS, radius, or any combination thereof) you like - as long as the authorising page or script generates a valid ticket for a valid user everything should work just fine." Cheers, Stephen From scottp at dd.com.au Mon Mar 30 03:09:08 2009 From: scottp at dd.com.au (Scott Penrose) Date: Mon, 30 Mar 2009 05:09:08 -0500 (CDT) Subject: [Melbourne-pm] Authentication ? In-Reply-To: Message-ID: ----- "Stephen Steneker" wrote: > Hi Scott, > > I'd suggest mod_auth_tkt : > http://openfusion.com.au/labs/mod_auth_tkt/ > > "mod_auth_tkt hands off the authentication and authorisation problem > > to the URL of your choice. This means that you can use whatever > technology (CGI, Perl, PHP, ASP, Java etc.) and whatever repositories > > (passwd files, LDAP, NIS, RDBMS, radius, or any combination thereof) > > you like - as long as the authorising page or script generates a valid > > ticket for a valid user everything should work just fine." > > Cheers, > Stephen Hi Stephen The above looks perfect for the apache module. But to be frank that is the easiest part. I have written many of those, and there are a few CPAN modules to do it too (although I really like this one from my quick read, as it looks like it is done right, and many are not). The hard part (well maybe just for me because I know one bit and not the other) is the other parts: * Validated self registration * 3rd party login * Recover password * etc. Each bit of my problem is really not hard, and I have written them all before, but I don't want to write them again :-) But thanks for the link - I think it is a good choice for the Apache module. Ta Scott From daniel at rimspace.net Mon Mar 30 17:18:14 2009 From: daniel at rimspace.net (Daniel Pittman) Date: Tue, 31 Mar 2009 11:18:14 +1100 Subject: [Melbourne-pm] Authentication ? In-Reply-To: (Scott Penrose's message of "Mon, 30 Mar 2009 20:42:41 +1100") References: Message-ID: <873acuk0jd.fsf@rimspace.net> Scott Penrose writes: > If you wanted to do authentication on apache with the following basic > features: > > * (optional) Ability to register your own account with email token validation > * (optional) ability to use 3rd party accounts (ala OpenID) You are aware of the weaknesses in the current OpenID protocols, which render it a great mechanism for password theft, right? I certainly wouldn't trust it, until they resolve those, for anything requiring more security than you can get without a login. http://www.links.org/?p=187 http://www.links.org/?p=188 > * Password recovery via email token > * Apache Module for login & access control > > It seems that most open source code does authentication & registration > internally. It certainly does. When people move away from that the usually move to a central SSO solution that allows them to integrate well beyond the realm of the web. > So I am collecting what people would use that is independent of > framework or product - but can depend on Apache? I would probably pick up the Stanford SSO solution: http://webauth.stanford.edu/ Alternately, their features page compares them to a number of similar large scale authentication solutions. Debian package it, in unstable and possibly before, and it delivers the features you are talking about, more or less... If all that was too much, though, and given your constraints above, I would probably just deploy a random OpenID provider that did what I asked, then use only that for authentication. Regards, Daniel From scottp at dd.com.au Mon Mar 30 17:46:46 2009 From: scottp at dd.com.au (Scott Penrose) Date: Tue, 31 Mar 2009 11:46:46 +1100 Subject: [Melbourne-pm] Authentication ? In-Reply-To: <873acuk0jd.fsf@rimspace.net> References: <873acuk0jd.fsf@rimspace.net> Message-ID: On 31/03/2009, at 11:18 AM, Daniel Pittman wrote: > Scott Penrose writes: > >> If you wanted to do authentication on apache with the following basic >> features: >> >> * (optional) Ability to register your own account with email token >> validation >> * (optional) ability to use 3rd party accounts (ala OpenID) > > You are aware of the weaknesses in the current OpenID protocols, which > render it a great mechanism for password theft, right? > > I certainly wouldn't trust it, until they resolve those, for anything > requiring more security than you can get without a login. > > http://www.links.org/?p=187 > http://www.links.org/?p=188 Yes I am thanks. I want to put together/download a framework that has plug-able modules, so OpenID or something else, what ever :-) > >> * Password recovery via email token >> * Apache Module for login & access control >> >> It seems that most open source code does authentication & >> registration >> internally. > > It certainly does. When people move away from that the usually move > to > a central SSO solution that allows them to integrate well beyond the > realm of the web. > >> So I am collecting what people would use that is independent of >> framework or product - but can depend on Apache? > > I would probably pick up the Stanford SSO solution: > http://webauth.stanford.edu/ Thanks that looks good. It certainly has a good set of features. Of course I was not specifically after SSO, just user management, but will see. > Alternately, their features page compares them to a number of similar > large scale authentication solutions. > > Debian package it, in unstable and possibly before, and it delivers > the > features you are talking about, more or less... > > If all that was too much, though, and given your constraints above, > I would probably just deploy a random OpenID provider that did what > I asked, then use only that for authentication. Thanks Daniel Scott From scottp at dd.com.au Sun Mar 22 23:10:54 2009 From: scottp at dd.com.au (Scott Penrose) Date: Mon, 23 Mar 2009 17:10:54 +1100 Subject: [Melbourne-pm] TPF in Google Summer of Code! References: <200903211709.53023.scratchcomputing@gmail.com> Message-ID: FYI Begin forwarded message: > Subject: [pm_groups] TPF in Google Summer of Code! > > Hi all, > > Please forward this to your local groups. > > The Perl Foundation has been officially accepted into the Google > Summer > of Code 2009 program as a mentor organization! > > Hopefully some of you have identified some potential students already. > Now we need your help getting them to submit their proposals. > > http://leto.net/dukeleto.pl/2009/03/tpf-accepted-to-google-summer-of-code-2009.html > > The student application period begins Monday, March 23rd and runs > through April 3rd. (Students note: you can edit your proposal > throughout that 11-day period -- getting it started early and talking > to potential mentors greatly increases your chances vs throwing it > over > the wall at the deadline.) See this page for details: > > http://code.google.com/soc/ > > Interested students and potential mentors, please read the GSoC info > on > the Perl wiki: > > http://www.perlfoundation.org/perl5/index.cgi?gsoc > http://www.perlfoundation.org/perl5/index.cgi?gsoc_2009_projects > > If you're interested in mentoring or have a good project suggestion, > now > is the time to get your info up on the wiki so students will know > about > your code and where to find you. > > Thanks, > Eric > -- > 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: