[27494] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9089 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 25 14:06:04 2006

Date: Sat, 25 Mar 2006 11:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 25 Mar 2006     Volume: 10 Number: 9089

Today's topics:
    Re: Accesing lexical vars from XSUB (Anno Siegel)
        Concise idiom sought <daveandniki@ntlworld.com>
    Re: Concise idiom sought <Peter@PSDT.com>
    Re: Concise idiom sought (Anno Siegel)
    Re: Concise idiom sought <rvtol+news@isolution.nl>
    Re: Concise idiom sought <daveandniki@ntlworld.com>
    Re: Concise idiom sought lawrence@hummer.not-here.net
    Re: Concise idiom sought <abigail@abigail.nl>
    Re: Concise idiom sought <daveandniki@ntlworld.com>
    Re: Debugging with Speech: Issues and Work-arounds? <nospam-abuse@ilyaz.org>
    Re: file renamer... request feedback <rvtol+news@isolution.nl>
    Re: file renamer... request feedback (Anno Siegel)
    Re: file renamer... request feedback <rvtol+news@isolution.nl>
    Re: file renamer... request feedback <noone@nowhere.com>
    Re: short form for (defined $x and defined $y and ... ) <markus.dehmann@gmail.com>
    Re: short form for (defined $x and defined $y and ... ) <1usa@llenroc.ude.invalid>
    Re: short form for (defined $x and defined $y and ... ) lawrence@hummer.not-here.net
        simple mysql table browser with sort /  filter and edit <news1234@free.fr>
    Re: simple mysql table browser with sort /  filter and  <jds@myob.com>
    Re: XML::Simple and utf8 woes <dlking@cpan.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 25 Mar 2006 17:49:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Accesing lexical vars from XSUB
Message-Id: <48le5tFkbkshU1@news.dfncis.de>

Ferry Bolhar <bol@adv.magwien.gv.at> wrote in comp.lang.perl.misc:
> Hi,
> 
> still playing around with XSUBs, I use get_sv() to obtain the content of a
> global variable:
> 
> In test.pl
> 
> $a = "Test";
> 
> In test.xs (partially):
> 
> SV* my_sv;
> my_sv = get_sv("a",FALSE);
> if (!my_sv) croak("'a' does not exist!");
> printf(form("a = %_\n",my_sv));
> 
> Works as expected.
> 
> However, when inserting a "my" before the $a in test.pl, the XSUB croaks.
> Seems that get_sv can't acces lexical variables.
> So just for couriosity: is there a way to access the lexical variable $a?
> Or, generally
> spoken, how to access the contents of a scatch pad from a XSUB?

I don't know the answer, but PadWalker (on CPAN) does that (within the
scope of the caller).  Its code should be instructive.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Sat, 25 Mar 2006 15:14:15 +0100
From: "Dave" <daveandniki@ntlworld.com>
Subject: Concise idiom sought
Message-Id: <4425503f$0$6641$8fcfb975@news.wanadoo.fr>

I have the following code snippet:

if ( !defined $base_ref->{pl} ) {
    $base_ref->{pl} = 1;
}

following the 'Best practices' guidelines. Previously I had it as:

$base_ref->{pl} = 1 unless defined $base_ref->{pl};

which seems clearer to me...

In bash shell scripting there is the ${variable:=default} idiom. I 
understand that Perl 6 will have something similar. Is there anything in 
Perl 5 that is better than my three lines above and still within the Best 
Practices guidelines?

Thanks

Dave




------------------------------

Date: Sat, 25 Mar 2006 14:28:46 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Concise idiom sought
Message-Id: <pan.2006.03.25.14.28.46.61208@PSDT.com>

On Sat, 25 Mar 2006 15:14:15 +0100, Dave wrote:
> I have the following code snippet:
> 
> if ( !defined $base_ref->{pl} ) {
>     $base_ref->{pl} = 1;
> }
> 
> following the 'Best practices' guidelines. Previously I had it as:
> 
> $base_ref->{pl} = 1 unless defined $base_ref->{pl};
> 
> which seems clearer to me...

Then use it.  The PBP guidelines are suggestions, not straitjackets.

Personally, I would write it as

	$base_ref->{pl} ||= 1;

unless you have some need to distinguish between false and undefined
values.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/



------------------------------

Date: 25 Mar 2006 14:40:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Concise idiom sought
Message-Id: <48l32gFknr8iU1@news.dfncis.de>

Dave <daveandniki@ntlworld.com> wrote in comp.lang.perl.misc:
> I have the following code snippet:
> 
> if ( !defined $base_ref->{pl} ) {
>     $base_ref->{pl} = 1;
> }
> 
> following the 'Best practices' guidelines. Previously I had it as:
> 
> $base_ref->{pl} = 1 unless defined $base_ref->{pl};
> 
> which seems clearer to me...

If it seems clearer to you, by all means write it that way.  PBP isn't
meant to be binding for all Perl coders everywhere, it is a set of
guidelines to use when defining a coding style.

> In bash shell scripting there is the ${variable:=default} idiom. I 
> understand that Perl 6 will have something similar. Is there anything in 
> Perl 5 that is better than my three lines above and still within the Best 
> Practices guidelines?

Perl 5.10.x will have the //= operator for exactly that purpose.  (There
is also a patch available that adds it to current Perl.)

    $base_ref->{pl} //= 1;

Sometimes, depending on the range of values in the hash,

    $base_ref->{pl} ||= 1;

That works if all valid values are boolean true, for instance if they
are references.

Otherwise, these do the same thing:

    defined( $base_ref->{pl}) || $base_ref->{pl} = 1;
    defined || $_ = 1 for $base_ref->{pl};

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Sat, 25 Mar 2006 16:03:42 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Concise idiom sought
Message-Id: <e03plg.1ic.1@news.isolution.nl>

Dave schreef:

> I have the following code snippet:
>   C<if ( !defined $base_ref->{pl} ) { $base_ref->{pl} = 1 }>
> following the 'Best practices' guidelines. Previously I had it as:
>   C<$base_ref->{pl} = 1 unless defined $base_ref->{pl}>
> which seems clearer to me...
> 

(some whitespace compressed)

$ perl -MO=Deparse,-x7 -e 'if (!defined $x) {$x=1}'
not defined $x and do { $x = 1 };


$ perl -MO=Deparse,-x7 -e 'unless (defined $x) {$x=1}'
defined $x or do { $x = 1 };



$ perl -MO=Deparse,-x7 -e '$x = 1 unless defined $x'
defined $x or $x = 1;



> Is there anything
> in Perl 5 that is better than my three lines above and still within
> the Best Practices guidelines?

  $x ||= 1;
 
-- 
Affijn, Ruud

"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'


------------------------------

Date: Sat, 25 Mar 2006 18:11:54 +0100
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: Concise idiom sought
Message-Id: <442579e3$0$21305$8fcfb975@news.wanadoo.fr>


"Dr.Ruud" <rvtol+news@isolution.nl> wrote in message 
news:e03plg.1ic.1@news.isolution.nl...
> Dave schreef:
>
>> I have the following code snippet:
>>   C<if ( !defined $base_ref->{pl} ) { $base_ref->{pl} = 1 }>
>> following the 'Best practices' guidelines. Previously I had it as:
>>   C<$base_ref->{pl} = 1 unless defined $base_ref->{pl}>
>> which seems clearer to me...
>>
>
> (some whitespace compressed)
>
> $ perl -MO=Deparse,-x7 -e 'if (!defined $x) {$x=1}'
> not defined $x and do { $x = 1 };
>
>
> $ perl -MO=Deparse,-x7 -e 'unless (defined $x) {$x=1}'
> defined $x or do { $x = 1 };
>
>
>
> $ perl -MO=Deparse,-x7 -e '$x = 1 unless defined $x'
> defined $x or $x = 1;
>
>
>
>> Is there anything
>> in Perl 5 that is better than my three lines above and still within
>> the Best Practices guidelines?
>
>  $x ||= 1;
>
> -- 
> Affijn, Ruud
>
> "Gewoon is een tijger."
> echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'

Thanks everyone for these answers. In this case 0 is a valid value, so the 
||= construct is not suitable (although I think it is the clearest and most 
concise when it is). While waiting for //= to be implemented in mainstream 
Perl and become widespread I think I'll use:

defined $base_ref->{pl} or $base_ref->{pl} = 1;

Thanks again for all your suggestions




------------------------------

Date: 25 Mar 2006 09:12:40 -0800
From: lawrence@hummer.not-here.net
Subject: Re: Concise idiom sought
Message-Id: <87y7yy5tyv.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>

"Dave" <daveandniki@ntlworld.com> writes:

> I have the following code snippet:
> 
> if ( !defined $base_ref->{pl} ) {
>     $base_ref->{pl} = 1;
> }
> 
> following the 'Best practices' guidelines. Previously I had it as:

I think that is the *ONE* reccomendation[1] in PBP that every Perl
programmer I know revolt against.  Every one of the other
reccomendations I've found some who were for it, and some who were
against, but that is the one that every one unanimously decreed "What
was Damian smoking when he wrote THAT?" 

the "die unless good-to-go" and "assign unless defined" idioms are so
unbelievably common, that they should have been explicitly mentioned
as canon.

[1] Which is actually spread across two - the "don't use postfix
unless" and "don't use unless, ever"

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


------------------------------

Date: 25 Mar 2006 17:40:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Concise idiom sought
Message-Id: <slrne2b04u.c1.abigail@alexandra.abigail.nl>

Dave (daveandniki@ntlworld.com) wrote on MMMMDLXXXIX September MCMXCIII
in <URL:news:4425503f$0$6641$8fcfb975@news.wanadoo.fr>:
__  I have the following code snippet:
__  
__  if ( !defined $base_ref->{pl} ) {
__      $base_ref->{pl} = 1;
__  }
__  
__  following the 'Best practices' guidelines. Previously I had it as:
__  
__  $base_ref->{pl} = 1 unless defined $base_ref->{pl};
__  
__  which seems clearer to me...


Replacing something which is correct and not inefficient with something
else that's correct and also not inefficient, but less clear to yourself
is, IMO, very very stupid.

Doing something one way for no other reason it is in PBP is, IMO, very very
stupid, and a sign you didn't understand PBP.

You certainly didn't read, or didn't understand the introduction (chapter 1).


Go read the book again. Chapter 1. Middle paragraph of page 6.

Do not advance and certainly don't implement anything of the book until
you fully understand that paragraph.

It's the most important paragraph of the book.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'


------------------------------

Date: Sat, 25 Mar 2006 19:15:25 +0100
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: Concise idiom sought
Message-Id: <442588c9$0$19707$8fcfb975@news.wanadoo.fr>


"Abigail" <abigail@abigail.nl> wrote in message 
news:slrne2b04u.c1.abigail@alexandra.abigail.nl...
> Dave (daveandniki@ntlworld.com) wrote on MMMMDLXXXIX September MCMXCIII
> in <URL:news:4425503f$0$6641$8fcfb975@news.wanadoo.fr>:
> __  I have the following code snippet:
> __
> __  if ( !defined $base_ref->{pl} ) {
> __      $base_ref->{pl} = 1;
> __  }
> __
> __  following the 'Best practices' guidelines. Previously I had it as:
> __
> __  $base_ref->{pl} = 1 unless defined $base_ref->{pl};
> __
> __  which seems clearer to me...
>
>
> Replacing something which is correct and not inefficient with something
> else that's correct and also not inefficient, but less clear to yourself
> is, IMO, very very stupid.
>
> Doing something one way for no other reason it is in PBP is, IMO, very 
> very
> stupid, and a sign you didn't understand PBP.
>
> You certainly didn't read, or didn't understand the introduction (chapter 
> 1).
>
>
> Go read the book again. Chapter 1. Middle paragraph of page 6.
>
> Do not advance and certainly don't implement anything of the book until
> you fully understand that paragraph.
>
> It's the most important paragraph of the book.
>
>
>
> Abigail
> -- 
> perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
> 0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
> =>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
> !$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'

Mmm, I have read the whole book and am going through it again. I have not 
blindly implemented any of the guidelines. In this case I agree with the 
rationale given in PBP for avoiding both of the 'problems' with my original 
code. What I didn't like was the longwindedness of my own rewrite in terms 
of 'if (!defined...) {...}'. The 'defined...or...' construct fixes this 
perfectly. The //= operator is even better.

Dave




------------------------------

Date: Sat, 25 Mar 2006 18:50:43 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Debugging with Speech: Issues and Work-arounds?
Message-Id: <e043e3$1232$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Veli-Pekka Tätilä
<vtatila@mail.student.oulu.fi>], who wrote in article <e039oo$d7q$1@news.oulu.fi>:
> Ilya Zakharevich wrote:
> > So far I can remember 3 places in debugger you complain about:
> >  a) How dumpvar.pl/Dumpvar.pm dump an array;
> Yes, though as I said, this is easy enough to side step with some filtering 
> or printed code run with the p command, at least for non-nestedd structures. 
> That is so easy that it doesn't make too much sense, in my view, to even 
> modify the debugger for this.

As I said, no need to modify the debugger.  Just set compactDump
option.  (I never managed to make "deeply nested" stuff printed "nice",
but simple output should be handled reasonably well.)

> >  b) Pre-prompt "positional info" output;
> It is one of the more serious issues. I'm especially irked by the pakage and 
> file path prompt before the code. It is not that bad in virtual focus, a 
> screen reader specific navigation mode, as it is taken to be a single word. 
> However, If one would just like to get an idea of which line it is and so 
> use the automatic reading after an enter press, there's no easy way to skip 
> the package info in that case. THis is called reading in live focus in 
> Supernova, because no screen reader specific navigation commands are 
> involved and the reader tracks the OS's keyboard focus. I'll use the terms 
> live focus (LF) and virtual focus (VF) from now on.

I think most of your "Screen Readers are Stupid" complaints will be
satisfied by PerlDB "addons".  E.g., instead of navigating the
information already on screen via (unflexible) screen-read interface,
make PerlDB *repeat* the necessary information by printing something
new on screen.  This can be easily done by aliases (especially if
PerlDB provides enough helper functions to make writing the aliases easier).

> d) Inability of GUI-readers to distinguish multi-column layout in the 
> console.

You mean the "concise" help screen?  Will this be better:

List/search source lines:               Control script execution:
  l [ln|sub]  List source code          | T           Stack trace
  - or .      List previous/current line| s [expr]    Single step [in expr]
  v [line]    View around line          | n [expr]    Next, steps over subs
  f filename  View source in file       | <CR/Enter>  Repeat last n or s
  /pattern/ ?patt?   Search forw/backw  | r           Return from subroutine
  M           Show module versions      | c [ln|sub]  Continue until position
Debugger controls:                      | L           List break/watch/actions
  o [...]     Set debugger options      | t [expr]    Toggle trace [trace expr]
 <[<]|{[{]|>[>] [cmd] Do pre/post-prompt| b [ln|event|sub] [cnd] Set breakpoint
  ! [N|pat]   Redo a previous command   | B ln|*      Delete a/all breakpoints
  H [-num]    Display last num commands | a [ln] cmd  Do cmd before line
  = [a val]   Define/list an alias      | A ln|*      Delete a/all actions
  h h         Complete help page        | W expr|*    Delete a/all watch exprs
  |[|]db_cmd  Send output to pager      | ![!] syscmd Run cmd in a subprocess
  q or ^D     Quit                      | R           Attempt a restart
Data Examination:     expr     Execute perl code, also see: s,n,t expr
  x|m expr     Evals expr in list context, dumps the result or lists methods.
  p expr       Print expression expr (uses script's current package).
  S [[!]pat]   List subroutine names [not] matching pattern pat.
  X [Vars]     List Variables in current package.  Vars can be ~pattern or !pat
  V [Pk [Vars]] Same as X for package Pk.  Type h y for access to lexicals.
For more help, type h cmd_letter, or run perldoc perldebug for all docs.

For seeing customers, we can add some color for the added "|" line to
make it stnd out better.

Yours,
Ilya




------------------------------

Date: Sat, 25 Mar 2006 15:05:00 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: file renamer... request feedback
Message-Id: <e03mfo.1i0.1@news.isolution.nl>

TOC schreef:

>    $new =~ s/\.mpeg$/\.mpg/;            # fix odd extensions

Why escape harmless characters in the replacement part?

-- 
Affijn, Ruud

"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'


------------------------------

Date: 25 Mar 2006 16:14:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: file renamer... request feedback
Message-Id: <48l8ieFkepe5U2@news.dfncis.de>

Dr.Ruud <rvtol+"`ls -al .`"@isolution.nl> wrote in comp.lang.perl.misc:
> TOC schreef:
> 
> >    if (rename $o, $_)
> >    {
> >       print "\n $File::Find::name -> \n $File::Find::dir/$_\n";
> >    }
> >    else
> >    {
> >       print "failed: $!\n"; die "faild to rename $o to $_, left as
> >    $o"; }
> 
>     if    ($_ eq $o)      {...}
>     elsif (rename $o, $_) {...}
>     else                  {...}
> 
> And maybe, with some clever tricks, you could write it as
> 
>     if    ($o.eq)  {...}
>     elsif ($o.mv)  {...}
>     else           {...}

Huh?  What are those dots in the conditionals?  Perl 6 method calls?

> And I still forgot to test $_ for pre-existance.

Another mystery remark, given the non-context :)

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Sat, 25 Mar 2006 18:24:11 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: file renamer... request feedback
Message-Id: <e0429c.fg.1@news.isolution.nl>

Anno Siegel schreef:
> Dr.Ruud:

>> And maybe, with some clever tricks, you could write it as
>>
>>     if    ($o.eq)  {...}
>>     elsif ($o.mv)  {...}
>>     else           {...}
>
> Huh?  What are those dots in the conditionals?  Perl 6 method calls?

Close, they are from the next neighbourhood, where they worship $_ but
can't refer to Her by Her name.


>> And I still forgot to test $_ for pre-existance.
>
> Another mystery remark, given the non-context :)

    if ($_ ne $o)
    {
      if (-e $_)            {...} # pre-existance
      elsif (rename $o, $_) {...} # try rename
      else                  {...} # failed
    }

-- 
Affijn, Ruud

"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'



------------------------------

Date: Sat, 25 Mar 2006 18:33:23 GMT
From: TOC <noone@nowhere.com>
Subject: Re: file renamer... request feedback
Message-Id: <T1gVf.116308$NN1.24372@fe12.news.easynews.com>

"Dr.Ruud" <rvtol+news@isolution.nl> wrote in news:e0429c.fg.1
@news.isolution.nl:

> Anno Siegel schreef:
>> Dr.Ruud:
> 
>>> And maybe, with some clever tricks, you could write it as
>>>
>>>     if    ($o.eq)  {...}
>>>     elsif ($o.mv)  {...}
>>>     else           {...}
>>
>> Huh?  What are those dots in the conditionals?  Perl 6 method calls?
> 
> Close, they are from the next neighbourhood, where they worship $_ but
> can't refer to Her by Her name.
> 
> 
>>> And I still forgot to test $_ for pre-existance.
>>
> 
>     if ($_ ne $o)
>     {
>       if (-e $_)            {...} # pre-existance
>       elsif (rename $o, $_) {...} # try rename
>       else                  {...} # failed
>     }
> 



ok, first of all I don't understand the ...  can you give me a link to 
where it is documented?


here is the current state of the script, is this what you had in mind?


!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Fatal;
use File::Find;

finddepth(\&f, ".");
sub f
{
   return if /^\./ or /lost\+found/;
   my $o = $_ ;
   y/A-Z/a-z/;
   y/a-z0-9._/_/c;
   s/^_+//;
   s/\.mpeg$/.mpg/;
   s/\.ram$/.rm/;
   s/\.qt$/.mov/;
   s/\.jpeg$/.jpg/;
   s/_\././g;
   s/\._/_/g;
   y/_//s;
   y/.//s;
   if ($_ ne $o)
   {
     if (-e $_) {print "\n $File::Find::dir/$_ already exists \n";}
     elsif (rename $o, $_) {print "\n $File::Find::name -> \n 
$File::Find::dir/$_\n";}
     else {print "\n failed to rename $o to $_, left as $o\n ";}
   }
}


------------------------------

Date: Sat, 25 Mar 2006 09:53:46 -0500
From: Markus Dehmann <markus.dehmann@gmail.com>
Subject: Re: short form for (defined $x and defined $y and ... )?
Message-Id: <48l3ruFk074eU1@individual.net>

Uri Guttman wrote:
>>>>>>"MD" == Markus Dehmann <markus.dehmann@gmail.com> writes:
> 
> 
>   MD> I often find myself typing
>   >> unless(defined $x and defined $y and defined $z){ # ... many variables
>   >> # ...
>   >> }
> 
> then don't type that! i suspect a poor design that makes you check many
> variables for defined. i have never seen that in quality code.
> 
> what that means is to solve the real problem (why are you doing that)
> rather than the 'how do i do this?' problem.
> 
> post (a short complete program) that shows why you do all those defined
> calls.

my ($x,$y,$z) = $userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/;
die("wrong input format") unless(defined $x and defined $y and defined $z);

I write lots of little scripts like that match user input like this. 
Sure, it's not "quality code", but it's definitely not worth to spend 
more code on the user input error checking for my purposes. So, if I 
grep, say, 10 variables from the user input this (defined $x and defined 
 ...) can be a little longish. I'd just like to say (defined ($x,$y,$z,...))

Okay, but you're right, maybe I could change the design. Maybe something 
like this:

if( $userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ ){
   ($x,$y,$z) = ($1,$2,$2);
}
else{
   die("wrong input format");
}

But again, this is longer, and I find my first version more intuitive.

Markus


------------------------------

Date: Sat, 25 Mar 2006 15:25:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: short form for (defined $x and defined $y and ... )?
Message-Id: <Xns97916A2C35C9asu1cornelledu@127.0.0.1>

Markus Dehmann <markus.dehmann@gmail.com> wrote in
news:48l3ruFk074eU1@individual.net: 

> if( $userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ ){
>    ($x,$y,$z) = ($1,$2,$2);
> }
> else{
>    die("wrong input format");
> }
> 
> But again, this is longer, and I find my first version more intuitive.

$userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ or die "...";
my ($x, $y, $z) = ($1, $2, $3);

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 25 Mar 2006 09:03:09 -0800
From: lawrence@hummer.not-here.net
Subject: Re: short form for (defined $x and defined $y and ... )?
Message-Id: <874q1m78z6.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>

Markus Dehmann <markus.dehmann@gmail.com> writes:
> my ($x,$y,$z) = $userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/;
> die("wrong input format") unless(defined $x and defined $y and defined $z);
> 
> I write lots of little scripts like that match user input like
> this. Sure, it's not "quality code", but it's definitely not worth to
> spend more code on the user input error checking for my purposes. So,
> if I grep, say, 10 variables from the user input this (defined $x and
> defined ...) can be a little longish. I'd just like to say (defined
> ($x,$y,$z,...))
> 
> Okay, but you're right, maybe I could change the design. Maybe
> something like this:
> 
> if( $userInput =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ ){
>    ($x,$y,$z) = ($1,$2,$2);
> }
> else{
>    die("wrong input format");
> }
> 

So, why not do it the first way 

  unless (my ($x, $y, $z) = $user_input =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ ) {
    die "Wrong input format: $user_input";
  } else { 
    do_something($x, $y, $z);
  }

If you move the scope of the ($x, $y, $z) out of the if block, 
you can do it a little more straight line

  my ($x, $y, $z);

  die "Wrong input format: $user_input"
    unless (($x, $y, $z) = $user_input =~ m/(.+?)\s\+\s(.+?)\s=\s(.+)/ );

  do_something($x, $y, $z);


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


------------------------------

Date: Sat, 25 Mar 2006 17:27:11 +0100
From: news reader <news1234@free.fr>
Subject: simple mysql table browser with sort /  filter and edit option
Message-Id: <44256f57$0$21524$626a54ce@news.free.fr>

Hi,



Does anoone of you know if there is already a simple application doing 
something like this.
I would enhance / tune the missing features, but would like to avoid to 
start from scratch or to start from something, that has far too many 
features and is difficult to setup.


Usecase:  a group sheet as collabortation tool.

Currently we're having a simple Excel file with one table and about 10 
columns.
The process of downloading the table, modifying one or two entries and 
uploading it again is not very efficient. Especially if multiple users 
could try to modify different rows at the same time.


The table / sheet should be modifiable by any member.
(security is no issue, the data is non critical, the DB contains no 
other data, the server could only be accessed by authorized users)


I thought, that having a MYSQL table with a simple web front end (PHP or 
perl CGI) would be a nice idea.

PhPMyAdmin looks a little too complex and does not do exactly what I need.

Requirements:


filtering entries (pregenerated filters)
------------------------------------------
it should be possible to choose a 'where' conditions.
The idea would be to select pregenerated 'where' conditions from a list
(and perhaps even to  enter conditions manually

selectable columns (pregenerated column views)
------------------------------------------------------
It should be possible to select which columns should be displayed.
(A list box should contain certain pre-created combinations of column 
combinations).


sortable
----------
It should be possible to sort by columns (e.g. like in phpMyAdmin when 
clicking on a column title)

Sorting by onbly one columns should be fine



editing a cell/row while having the default table view
--------------------------------------------------------

The look and feel of editing should be as close as possible to editing
an Excel spread sheet. (no formatting needed, no formulas needed, only 
text and number entries)

Whether updates occur after every cell change or only when confirming a 
row change is not that important.


very basic collision detection
---------------------------------

Very basic collision detection would be enough as described here:
  When two users try to change the same table row at the same time, then 
the user who 'submitted' first will win and the other one will get a 
warning.


Thanks in advance for any suggestions and bye



N



------------------------------

Date: Sat, 25 Mar 2006 16:43:00 GMT
From: "Julia De Silva" <jds@myob.com>
Subject: Re: simple mysql table browser with sort /  filter and edit option
Message-Id: <oqeVf.277200$YJ4.247977@fe2.news.blueyonder.co.uk>


> Does anoone of you know if there is already a simple application doing
> something like this.

Have you looked at http://www.navicat.com/ ?

I can't do without it !

J




------------------------------

Date: Sat, 25 Mar 2006 12:34:40 -0600
From: Donald King <dlking@cpan.org>
Subject: Re: XML::Simple and utf8 woes
Message-Id: <33gVf.1192$IG.933@dukeread01>

[Whoops, I did the post-vs-mail thing again.  Bad coder, no cookie.]

corff@zedat.fu-berlin.de wrote:
> Chronos Tachyon <chronos@chronos-tachyon.net> wrote:
> 
> : The problem seems to be the absence of a "use utf8;" pragma.  Perl is
> : assuming that your code (including the __DATA__ section) is in ISO-8859-1.
> 
> No, I don't think so, as inserting the utf8 pragma doesn't change anything.
> I tried it, and the output is still not in utf8.
> 

FWIW, I've taken your original test case from the top of the thread and
fixed it up.  It's now properly encoded in UTF-8, it uses both "use
utf8" and "binmode(STDOUT, ':utf8')" to fix the problem, and I fixed it
to run under "use strict" and "use warnings" while I was in there.  You
can download it at <http://chronos-tachyon.net/~chronos/corff.pl>.

BTW, during my testing, I found that, if script.pl has a "#!perl -CS"
shebang line, "./script.pl" uses the -CS but "perl script.pl" doesn't.
I guess I was so used to -w and -T being automatically picked up from
the shebang line, I didn't realize that Perl doesn't interpret *all* the
flags there.  I'd recommend explicit binmode() calls or the "open"
pragma instead of the -C flag, due to the confusion it can cause.

-- 
Donald King, a.k.a. Chronos Tachyon
http://chronos-tachyon.net/


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9089
***************************************


home help back first fref pref prev next nref lref last post