Re: Why doesn't this work: trinary operator?

2008-01-12 Thread davidfilmer
On Jan 11, 1:16 pm, [EMAIL PROTECTED] (Kevin Zembower) wrote:

 $type eq unknown ? $type=human : $type=both;

You're trying to use the trinary like you would an if-then-else.  You
want to instead use it in an assignment:

$type = ($type eq 'unknown') ? 'human' : 'both';


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-17 Thread davidfilmer
On Dec 17, 3:22 am, [EMAIL PROTECTED] (Pauld) wrote:
 my $var=0;my [EMAIL PROTECTED];
 while ($var$va_length)
 {
 print ${$daylistsorted[$var]}{TH} ;
 print   'from ';
 print ${$daylistsorted[$var]}{START};
 print ' to '.${$daylistsorted[$var]}{END_DS};
 printduration  ;print   int((${$daylistsorted[$var]}{END}-$
 {$daylistsorted[$var]}{START})/60);

It's unusual in Perl to need to access an array element by its index
number.  This is one of those times, though, when it is useful to use
an index because you need to peek ahead at the next item in the
array.  But you only need the index for the next item, not for the
current item, so you can clean up things a bit with something like
this (untested, and posted without much effort to parse or understand
the objective of the code, and using printf instead of a bunch of
concat'ed strings):

   my $index = 0;
   foreach my $day( @daylistsorted ) {
  printf (
 %s from $s to %s duration %s %s\n,
$day{'TH'},
UnixDate($day{'START'},  '%Y:%m:%d %H:%M'),
UnixDate($day{'END_DS'}, '%Y:%m:%d %H:%M'),
int(($day{END} - $day{START})/60);
(exists(  ${$daylistsorted[$index+1]}{TH} ) )
   ? \tinterval to next start 
 .int (( ${$daylistsorted[$index+1]}{START}
-$day{END} )/60)
   : ''
  );
  $index++;
   }


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: WWW::Search::Google--Service description 'file:' can't be loaded: 404 File `' does not exist

2007-10-17 Thread davidfilmer
 Use of uninitialized value in concatenation (.) or string at 
 /usr/lib/perl5/site_perl/5.8.8/Net/Google/Service.pm line 80.
 Service description 'file:' can't be loaded: 404 File `' does not exist

Hmmm.  FWIW, I tried to reproduce your problem, but I needed to
install Net::Google on my machine (a SuSe 10 box).  I got this exact
same error when trying to 'make test' (using my own Google key, but it
is a very old key - March 2006; do keys expire if you don't use them
for a long time?)

--
David Filmer (http://DavidFilmer.com)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Listing files and their sizes

2007-09-18 Thread davidfilmer
On Sep 18, 1:59 pm, [EMAIL PROTECTED] (Telemachus Odysseos)
wrote:

 The script works
 perfectly if I run it in the directory itself, but if the script is
 somewhere else in my system, it prints the filenames but not the sizes.

That's because readdir returns a plain filename.  You need to either
chdir() to the directory within your script, or fully qualify the
filename (ie, -s /path/to/my.file)


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/