From spikeh at mweb.co.za Mon Feb 9 04:15:21 2004 From: spikeh at mweb.co.za (Spike) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] returning values from a sub Message-ID: <5.2.1.1.2.20040209120833.03c81600@pop3.mweb.co.za> I have a sub (in module as it happens) that validates South African ID numbers and if the number is OK returns the DoB and sex. If not it populate an error string. I would like to use it like this: ($DoB, $sex) = said(1234567890123) || or die("$errstr"); My sub ends: return @results; @results is being successfully populated with '1955-12-25' 'Male' in the sub Any ideas? Spike Hodge UNIX Programmer M-Web Technology 021 596 8496 083 294 9593 Fax 0866721733 Click here and make M-Web your homepage http://homepage.mweb.co.za -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/za-pm/attachments/20040209/061f0789/attachment.htm From tvilliers at lastminute.com Mon Feb 9 04:29:33 2004 From: tvilliers at lastminute.com (Tielman de Villiers) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] returning values from a sub In-Reply-To: <5.2.1.1.2.20040209120833.03c81600@pop3.mweb.co.za> References: <5.2.1.1.2.20040209120833.03c81600@pop3.mweb.co.za> Message-ID: <1076322573.4261.50.camel@lmn10631.lastminute.com> On Mon, 2004-02-09 at 10:15, Spike wrote: > I have a sub (in module as it happens) that validates South African > ID numbers and if the number is OK returns the DoB and sex. > If not it populate an error string. > > > I would like to use it like this: > > ($DoB, $sex) = said(1234567890123) || or die("$errstr"); > > > My sub ends: > > return @results; ## return @results my ($dob,$sex) = @results; return ($dob,$sex); > > @results is being successfully populated with '1955-12-25' 'Male' in > the sub > > Any ideas? > > > > > > > Spike Hodge > > UNIX Programmer > M-Web Technology > 021 596 8496 > 083 294 9593 > Fax 0866721733 > > > Click here and make M-Web your homepage > http://homepage.mweb.co.za > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ > > > ______________________________________________________________________ > _______________________________________________ > Za-pm mailing list > Za-pm@mail.pm.org > http://mail.pm.org/mailman/listinfo/za-pm -- Tielman de Villiers Perl Developer: Post Sales lastminute.com Address: 4 Buckingham Gate, London SW1E 6JP Tel: +44(0)20.7802.4393 Fax: +44(0)20.7802.9302 email: tvilliers@lastminute.com From nick at cleaton.net Mon Feb 9 04:49:28 2004 From: nick at cleaton.net (Nick Cleaton) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] returning values from a sub In-Reply-To: <5.2.1.1.2.20040209120833.03c81600@pop3.mweb.co.za> References: <5.2.1.1.2.20040209120833.03c81600@pop3.mweb.co.za> Message-ID: <20040209104928.GX95181@lt1.cleaton.net> On Mon, Feb 09, 2004 at 12:15:21PM +0200, Spike wrote: > > I have a sub (in module as it happens) that validates South African ID > numbers and if the number is OK returns the DoB and sex. > If not it populate an error string. > > > I would like to use it like this: > > ($DoB, $sex) = said(1234567890123) || or die("$errstr"); You have an extra || there. Try: ($DoB, $sex) = said(1234567890123) or die("$errstr"); Nick -- $_=')=***** http://www.exonetric.com/ Telehouse UK colo *****19Pi'. 'TDX\@PT**** GBP40/month +VAT 40G BW no setup fee ****}4KGXC'. '~6K&2\6@**** ****(v';s/(.) (.*(.).(.))/$2.($1^chr((ord($3)+ord$4)%128))/exsuntil s/Wo.*oo//s;;print From spikeh at mweb.co.za Mon Feb 9 05:16:29 2004 From: spikeh at mweb.co.za (Spike) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] Passing values In-Reply-To: <200401091425.26056.ncoetzee1@fnb.co.za> References: <5.2.1.1.2.20040109085115.00aa12c8@pop3.mweb.co.za> <5.2.1.1.2.20040109085115.00aa12c8@pop3.mweb.co.za> Message-ID: <5.2.1.1.2.20040209131251.01be8ef8@pop3.mweb.co.za> Christiaan pointed this out to me: Spike - What dont you get right - I put this together and it works? It should also work if you stick with: return @results; Do you also make provision for the new "09" and "19" 11th and 12th digits? If I do ($DoB, $sex) = said(1234567890123) or die("$errstr"); (without ||) everything works If I do ($DoB, $sex) = said(1234567890123) || die("$errstr"); (with ||) things go awry Why? Christiaan He is right - when I use '||' it all goes wrong and with 'or' it does exactly what i wanted. what is the difference? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/za-pm/attachments/20040209/cbb7010c/attachment.htm From nick at cleaton.net Mon Feb 9 05:40:16 2004 From: nick at cleaton.net (Nick Cleaton) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] Passing values In-Reply-To: <5.2.1.1.2.20040209131251.01be8ef8@pop3.mweb.co.za> References: <5.2.1.1.2.20040109085115.00aa12c8@pop3.mweb.co.za> <5.2.1.1.2.20040109085115.00aa12c8@pop3.mweb.co.za> <5.2.1.1.2.20040209131251.01be8ef8@pop3.mweb.co.za> Message-ID: <20040209114016.GY95181@lt1.cleaton.net> On Mon, Feb 09, 2004 at 01:16:29PM +0200, Spike wrote: > Christiaan pointed this out to me: > > Spike - What dont you get right - I put this together and it works? > > It should also work if you stick with: return @results; > > Do you also make provision for the new "09" and "19" 11th and 12th digits? > > If I do ($DoB, $sex) = said(1234567890123) or die("$errstr"); (without ||) > everything works > > If I do ($DoB, $sex) = said(1234567890123) || die("$errstr"); (with ||) > things go awry > > Why? > > > Christiaan > > He is right - when I use '||' it all goes wrong and with 'or' it does > exactly what i wanted. > what is the difference? Because '||' has a higher precedence than '=', whereas 'or' has a lower precedence, so ($DoB, $sex) = said(1234567890123) || die("$errstr"); is the same as: ($DoB, $sex) = ( said(1234567890123) || die("$errstr") ); and the return value from said() is being ||ed with something else. Since || is a scalar operation, this calls said() in a scalar context, so it can't return a list. With 'or' however... ($DoB, $sex) = said(1234567890123) or die("$errstr"); is the same as: ( ($DoB, $sex) = said(1234567890123) ) or die("$errstr"); and the return value from said() is being assigned to a list, so said() will be called in a list context and it all works nicely. Nick -- $_=')=***** http://www.exonetric.com/ Telehouse UK colo *****19Pi'. 'TDX\@PT**** GBP40/month +VAT 40G BW no setup fee ****}4KGXC'. '~6K&2\6@**** ****(v';s/(.) (.*(.).(.))/$2.($1^chr((ord($3)+ord$4)%128))/exsuntil s/Wo.*oo//s;;print From ncoetzee1 at fnb.co.za Sun Feb 15 23:38:25 2004 From: ncoetzee1 at fnb.co.za (Nico Coetzee) Date: Mon Aug 2 21:40:02 2004 Subject: [Za-pm] New Local Open Source Site Message-ID: <200402160738.26559.ncoetzee1@fnb.co.za> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, For those into Open Source, I have now also added a dedicated OSS area at http://www.itfirms.co.za/html/index.php If you want to promote your own Perl modules or Perl related stuff, please contribute in the Perl section. Of course other contributions are also more then welcome. Cheers Nico - -- BOFH excuse : Forced to support NT servers; sysadmins quit. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFAMFdRlXERkPl0klQRAnHQAJ9fPGGrCl4QJ+E/jIH0x66dgG/x4wCfdS0P E+ViUtJklvirHlrbrOT3eEU= =Wihm -----END PGP SIGNATURE----- From kmf at pop.co.za Tue Feb 24 08:24:13 2004 From: kmf at pop.co.za (Karl Fischer) Date: Mon Aug 2 21:40:03 2004 Subject: [Za-pm] Writing a search replace script Message-ID: <1077632653.1595.4.camel@romulus.direqlearn.org> I'm trying to write a script to automate balsa config files I all ready created a default file for the script to use I want to replace the USERNAME value with $username value I enter from the command line. any suggestions? Karl #!/bin/bash echo "Enter a valid Unix Username :" read $username #USERNAME is unix name of the person perl -pi -w -e 's|USERNAME|$username|g;' .gnome2/balsa From ncoetzee1 at fnb.co.za Wed Feb 25 22:12:01 2004 From: ncoetzee1 at fnb.co.za (Nico Coetzee) Date: Mon Aug 2 21:40:03 2004 Subject: [Za-pm] Writing a search replace script In-Reply-To: <1077632653.1595.4.camel@romulus.direqlearn.org> References: <1077632653.1595.4.camel@romulus.direqlearn.org> Message-ID: <200402260612.06619.ncoetzee1@fnb.co.za> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 For thos ineterested, you can use the following as a learning exercise: 1 #!/usr/bin/perl 2 3 use strict; 4 use File::Copy; 5 6 my $file = "/tmp/temp.conf"; # the config file to parse 7 my $username; 8 9 if( -e $file ) { 10 11 # First, get a valid username 12 my $valid = 0; 13 while( $valid < 1 ) { 14 15 print "Enter the username: "; 16 $username = ; 17 print "\n"; 18 chomp( $username ); 19 20 # validate input 21 if( $username =~ /^\w{5,}/ ) { $valid++; } 22 23 print "Incorrect format for username - please enter it again.\n\n"; 24 25 } 26 27 # Search and replace in files 28 open( INF, "< $file" ) or die( "Cant open $file for reading\n" ); 29 open( OUTF, "> /tmp/balsa.tmp" ) or die( "Cant open $file for writing\n" ); 30 31 while( ) { 32 33 s/USERNAME/$username/eg; 34 print OUTF $_; 35 36 } 37 38 close( OUTF ); 39 close( INF ); 40 41 # move and overwrite the original file with the temp file 42 # but first make a backup copy: 43 my $bakfile= $file . ".bak"; 44 rename( $file, $bakfile ); 45 move( "/tmp/balsa.tmp", $file ); 46 if( -e $file ) { 47 48 print "Operation succesful\n"; 49 50 } else { 51 52 print "Operation failed\n"; 53 54 } 55 56 } else { 57 58 # file does not exists 59 print "Sorry, the file $file does not exists on this system.\n"; 60 61 } 62 63 exit; 64 65 1; I included a lot of error checking to demonstrate a couple of nice features. The 'move' command is NOT native to Perl, hence the 'use File::Copy'. Cheers Nico > On Tuesday 24 February 2004 16:24, Karl Fischer wrote: > I'm trying to write a script to automate balsa config files > I all ready created a default file for the script to use I want to > replace the USERNAME value with $username value I enter from the command > line. > > any suggestions? > > Karl > > > #!/bin/bash > echo "Enter a valid Unix Username :" > read $username > #USERNAME is unix name of the person > perl -pi -w -e 's|USERNAME|$username|g;' .gnome2/balsa > > > _______________________________________________ > Za-pm mailing list > Za-pm@mail.pm.org > http://mail.pm.org/mailman/listinfo/za-pm - -- BOFH excuse : ether leak -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFAPXIRlXERkPl0klQRAoRrAJ9+LT43EUlEvZZESF+Nwke7O81DnQCdEw2h ioduR7GoOyOu/nMb7Ocl5To= =2KAM -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: filerename.pl Type: text/x-perl Size: 1118 bytes Desc: not available Url : http://mail.pm.org/pipermail/za-pm/attachments/20040226/dab04b58/filerename.bin From spikeh at mweb.co.za Wed Feb 25 23:23:49 2004 From: spikeh at mweb.co.za (Spike) Date: Mon Aug 2 21:40:03 2004 Subject: [Za-pm] Writing a search replace script In-Reply-To: <200402260612.06619.ncoetzee1@fnb.co.za> References: <1077632653.1595.4.camel@romulus.direqlearn.org> <1077632653.1595.4.camel@romulus.direqlearn.org> Message-ID: <5.2.1.1.2.20040226072235.01df5b08@pop3.mweb.co.za> Why use move - couldn't you just use rename ("/tmp/balsa.tmp", $file )? At 2004/02/26 06:12 AM, Nico Coetzee wrote: ># but first make a backup copy: > 43 my $bakfile= $file . ".bak"; > 44 rename( $file, $bakfile ); > 45 move( "/tmp/balsa.tmp", $file ); > 46 if( -e $file ) { > 47 Spike Hodge UNIX Programmer M-Web Technology 021 596 8496 083 294 9593 Fax 0866721733 Click here and make M-Web your homepage http://homepage.mweb.co.za -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/za-pm/attachments/20040226/0066a2f1/attachment.htm From oskar at qualica.com Thu Feb 26 01:06:09 2004 From: oskar at qualica.com (Oskar Pearson) Date: Mon Aug 2 21:40:03 2004 Subject: [Za-pm] Writing a search replace script In-Reply-To: <5.2.1.1.2.20040226072235.01df5b08@pop3.mweb.co.za> References: <1077632653.1595.4.camel@romulus.direqlearn.org> <1077632653.1595.4.camel@romulus.direqlearn.org> <5.2.1.1.2.20040226072235.01df5b08@pop3.mweb.co.za> Message-ID: <20040226070609.GD11874@qualica.com> Hi > Why use move - couldn't you just use rename ("/tmp/balsa.tmp", $file )? Check out "man perlfunc". The "move" command will work across different mount points (so that if your /tmp directory is on a different filesystem to the files you are manipulating, it will still work in all cases on all systems). rename OLDNAME,NEWNAME Changes the name of a file; an existing file NEWNAME will be clobbered. Returns true for success, false other­ wise. Behavior of this function varies wildly depending on your system implementation. For example, it will usually not work across file system boundaries, even though the system mv command sometimes compensates for this. Other restrictions include whether it works on directories, open files, or pre-existing files. Check perlport and either the rename(2) manpage or equivalent system documentation for details. > At 2004/02/26 06:12 AM, Nico Coetzee wrote: > ># but first make a backup copy: > > 43 my $bakfile= $file . ".bak"; > > 44 rename( $file, $bakfile ); > > 45 move( "/tmp/balsa.tmp", $file ); > > 46 if( -e $file ) { > > 47 From spikeh at mweb.co.za Thu Feb 26 02:07:52 2004 From: spikeh at mweb.co.za (Spike) Date: Mon Aug 2 21:40:03 2004 Subject: [Za-pm] Writing a search replace script In-Reply-To: <20040226070609.GD11874@qualica.com> References: <5.2.1.1.2.20040226072235.01df5b08@pop3.mweb.co.za> <1077632653.1595.4.camel@romulus.direqlearn.org> <1077632653.1595.4.camel@romulus.direqlearn.org> <5.2.1.1.2.20040226072235.01df5b08@pop3.mweb.co.za> Message-ID: <5.2.1.1.2.20040226100725.02242950@pop3.mweb.co.za> I knew there had to be a reason! At 2004/02/26 09:06 AM, Oskar Pearson wrote: >Hi > > > > Why use move - couldn't you just use rename ("/tmp/balsa.tmp", $file )? > > >Check out "man perlfunc". The "move" command will work across >different mount points (so that if your /tmp directory is >on a different filesystem to the files you are manipulating, >it will still work in all cases on all systems). > >rename OLDNAME,NEWNAME >Changes the name of a file; an existing file NEWNAME will >be clobbered. Returns true for success, false other? wise. > >Behavior of this function varies wildly depending on your >system implementation. For example, it will usually not >work across file system boundaries, even though the system mv >command sometimes compensates for this. Other restrictions >include whether it works on directories, open files, or >pre-existing files. Check perlport and either the rename(2) >manpage or equivalent system documentation for details. > > > > At 2004/02/26 06:12 AM, Nico Coetzee wrote: > > ># but first make a backup copy: > > > 43 my $bakfile= $file . ".bak"; > > > 44 rename( $file, $bakfile ); > > > 45 move( "/tmp/balsa.tmp", $file ); > > > 46 if( -e $file ) { > > > 47 >_______________________________________________ >Za-pm mailing list >Za-pm@mail.pm.org >http://mail.pm.org/mailman/listinfo/za-pm Spike Hodge UNIX Programmer M-Web Technology 021 596 8496 083 294 9593 Fax 0866721733 Click here and make M-Web your homepage http://homepage.mweb.co.za -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/za-pm/attachments/20040226/9d8c357f/attachment.htm