Re: Date::manip query

2007-12-17 Thread pauld
im importing data from an excel spreadsheet into an array of hashes.
the date is initially converted using Date::Format::Excel.

for this bit

{START} = unix start time .{START_DS} = string that I use to convert
to unixtime with

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);

if (exists(  ${$daylistsorted[$var+1]}{TH}  )   )
 {
print \tinterval to next start ; print int ((${$daylistsorted[$var
+1]}{START}-${$daylistsorted[$var]}{END})/60);print  \n;
 }
$var++;
}}

Sat  04-08-2007
=
1 from 1186220100 to 2007:08:04 10:33   duration  58 interval to next
start 34
4 from 1186225620 to 2007:08:04 13:29   duration  142  interval to
next start 26

and when i change it to
#print ${$daylistsorted[$var]}{START};
print UnixDate(${$daylistsorted[$var]}{START}, '%Y:%m:%d %H:%M');

 I get this

Sat  04-08-2007
=
 1 from  to 2007:08:04 10:33   duration  58   interval to next start
34
 4 from  to 2007:08:04 13:29   duration  142  interval to next start
26


with both dates as strings


Sat  04-08-2007
=
1 from 2007:08:04 09:35 to 2007:08:04 10:33   duration  58   interval
to next start 34
4 from 2007:08:04 11:07 to 2007:08:04 13:29   duration  142  interval
to next start 26


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




Re: regex, 1 off...

2007-12-17 Thread Todd


Seems it's related to a more general question stated as `Given 2
sequences, find longest common sub sequence'. Many algorithm books
have materials about this one.

-Todd


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




Re: regex, 1 off...

2007-12-17 Thread Todd

 However much depends on the actual data and the variations that you are
 expecting.

 If you are searching for words like those used in the English language
 then you may want to look at how spell checking software works.

Seems related to the algorithm like `find the longest common sub
sequence of give 2 sequences'. Many algorithm books covers it.

-Todd


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




Can't use string as a symbol ref

2007-12-17 Thread ciwei2103
Can somebody enlighten me what I'm doing wrong?

I have a list in a file , test.dat

sh cat test1.dat
0039
0038

sh  cat test1.pl
#!/usr/bin/perl -w
use strict;
my $input = $ARGV[0];

my @devices =  $input  ;
print devices =  @devices \n;

__END__

now run it with
sh test.pl test1.dat

Can't use string (test1.dat) as a symbol ref while strict refs in
use at ./test.pl line xx.


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




Re: Can't use string as a symbol ref

2007-12-17 Thread Tom Phoenix
On 12/17/07, ciwei2103 [EMAIL PROTECTED] wrote:

 Can somebody enlighten me what I'm doing wrong?

 my $input = $ARGV[0];

 my @devices =  $input  ;

$input is a string, since it comes from @ARGV; but you're using it as
if it's a filehandle. Do you need open()? Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Can't use string as a symbol ref

2007-12-17 Thread yitzle
Maybe tell us what you are trying to do?
Try this:

 #!/usr/bin/perl -w
 use strict;
 my $input = $ARGV[0];

# File handle
my $FH;

# Check the file is a normal file and exists
die File does not exist\n if not -f $input;

# Open the file handle for read only, file named by $input
# Or die and print $! which is probably not the error message
# variable. perlvar would tell you the corrent variable.
open $FH, '', $input or die $!;

# Read from the file handle
my @devices =  $FH  ;

# The the array elements with a , 
 print devices =  , join (, , @devices),  \n;

 __END__

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




Re: Can't use string as a symbol ref

2007-12-17 Thread Chas. Owens
On Dec 17, 2007 10:19 AM, ciwei2103 [EMAIL PROTECTED] wrote:
 Can somebody enlighten me what I'm doing wrong?

 I have a list in a file , test.dat

 sh cat test1.dat
 0039
 0038

 sh  cat test1.pl
 #!/usr/bin/perl -w
 use strict;
 my $input = $ARGV[0];

 my @devices =  $input  ;
 print devices =  @devices \n;

 __END__

 now run it with
 sh test.pl test1.dat

 Can't use string (test1.dat) as a symbol ref while strict refs in
 use at ./test.pl line xx.

In addition to using open as others have suggested, if the only
arguments the script is expecting are files to process, you don't need
to use open; the  operator will automagically open files named in
@ARGV if given no file handle:

#!/usr/bin/perl

use strict;
use warnings;

my @devices = ;
print devices = @devices\n;

However, it is considered a bad idea to slurp all of a file into an
array (unless you are one hundred percent certain the files are
small).  It is better to write your code to handle things in pieces (a
line at a time).  A common way to do this is to use a while loop:

#!/usr/bin/perl

use strict;
use warnings;

while (my $device = ) {
#do something with each device
}

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




Re: regex, 1 off...

2007-12-17 Thread Jay Savage
On Dec 16, 2007 2:21 PM, namotco [EMAIL PROTECTED] wrote:
 Let's say I want to search some text for abc123.  However, we know
 people can make typos and so they could have entered avc123 or abc223
 or sbc123 or bc123 many other combinations...
 So I want to search for those possibilities as well.  So how would I
 go about creating the proper regex?

 Thanks!

How do you define a typo? How do you know whether it's a typo, or a
different string? Do you know, for instance, that only 'abc\d\d\d' is
valid, and 'avc\d\d\d' is never valid? If so, you could do something
like:

 if (/^abc\d\d\d$/ or s/^a.c(\d\d\d)$/abc$1/) {
# match!
 } else {
#no match!
 }

If you can't predict the input, though, you'll need some heavy duty
algorithmic logic. Take a look through CPAN and see if there isn't
something that meets your needs. String::Approx and
String::KeyboardDistance might be places to start. There are also a
number of things in the Text::* tree.

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!


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: regex, 1 off...

2007-12-17 Thread Rob Dixon

namotco wrote:

Let's say I want to search some text for abc123.  However, we know 
people can make typos and so they could have entered avc123 or abc223 or 
sbc123 or bc123 many other combinations...
So I want to search for those possibilities as well.  So how would I go 
about creating the proper regex?


I don't think a regex is appropriate in this case, but if you want to
write something that guesses at what a misspelled string should have
been then search the Web for Damerau-Levenshtein distance, which is very
effective and the algorithm codes up fairly simply.

Rob

--
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 John W . Krahn
On Monday 17 December 2007 15:40, [EMAIL PROTECTED] wrote:

 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 ) {

The way it is *usually* done is:

foreach my $index ( 0 .. $#daylistsorted ) {


   printf (
  %s from $s to %s duration %s %s\n,
 $day{'TH'},

An array element can hold a hash reference but not a hash itself:

  $day-{ TH },


 UnixDate($day{'START'},  '%Y:%m:%d %H:%M'),

   $day-{ START }


 UnixDate($day{'END_DS'}, '%Y:%m:%d %H:%M'),

   $day-{ END_DS }


 int(($day{END} - $day{START})/60);

   $day-{ END } - $day-{ START }


 (exists(  ${$daylistsorted[$index+1]}{TH} ) )
? \tinterval to next start 
  .int (( ${$daylistsorted[$index+1]}{START}
 -$day{END} )/60)

   $day-{ END }



: ''

   );
   $index++;
}


John
-- 
use Perl;
program
fulfillment

-- 
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 Chas. Owens
On Dec 18, 2007 1:05 AM, John W. Krahn [EMAIL PROTECTED] wrote:
snip
printf (
   %s from $s to %s duration %s %s\n,
snip

You missed the usage of $s instead of %s.  I always get bitten by that.

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