Re: Date::manip query
im sorting it on a key of the hash my @daylistsorted = sort { $$a{'START_DS'} <=> $$b{'START_DS'} } @daylist; generates a Argument "2007:09:30 13:41" isn't numeric in numeric comparison (<=>) at ./518573 error my @daylistsorted = sort { $$a{'START'} <=> $$b{'START'} } @daylist; works -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Date::manip query
the END_DS field is the date field that I want - but as I couldnt get it back from the seconds since epoch field I included it. IMHO it would be tideir to just use the (numerical) date-seconds and convert it back as necessary . i used the Date::Manip function Date_SecsSince1970($m,$d,$y,$h,$mn,$s); to get the date& time into a format I can sort it by. i was wanting to use Date::manip to extract the bits i want ( HH:MM) for the final display. i can do it by splitting the text formatted value (START_DS) but i thought it would be neater ( and i'd learnt something ) by doing it using the module -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Date::manip query
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}; print " duration ";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/
Date::manip query
im using Date::Manip to convert dates and times eg 2007:08:02 12:23 to allow me to sort them, which it does . but I cant see how to get the number back into a human -readable format print scalar localtime($var{STARTTIME}); prints the long string . is there a better way to get just the bits I want , or do I have to parse the string I get from print scalar localtime output ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
getting data from excel
i want to extract data from an excel spreadsheet into a hash of hashes so row 1 @headings= [col0,col1,col2 etc ] then i can loop through the rest ,extract the data a row at a time then i can for each row @columns = [col0,col1,col2 etc ] @[EMAIL PROTECTED]@columns; and then $alldata{rownumber}=\%hash; (i think this is it !) using the example in e Spreadsheet::ParseExcel gives me an output of the data and cell references but i cant see how toget it a row at a time toput it into a hash looking at the excel object with Data::Dumper there is something called 'PkgStr' that contains what i want - buit i dont know enough about it to go there. is there a way of extracting the data from within the loop into an array ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: why "cant execute " error ?
thank you . this is why it cant execute Can't execute: called with 1 bind variables when 0 are needed my $sql="SELECT value,text FROM res_prior"; has no bound variables - or has it ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
why "cant execute " error ?
# now connect and get a database handle my $dbh = DBI->connect($dsn, $user, $pass) or die "Cant connect to the DB: $DBI::errstr\n"; my $sql="SELECT value FROM res_prior"; my $sth = $dbh->prepare($sql) or die "cant prepare"; $sth->execute($sql) or die "cant execute"; and i get a "cant execute" error from cgi script thats running the query. I can connect to mysql and the query is OK mysql> SELECT value FROM res_prior; +---+ | value | +---+ | M | | H | | R | | N | | U | | O | | P | +---+ 7 rows in set (0.06 sec) mysql> how do i sort out what the problem is ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl sort query
> $ perl -le' > print for @x = qw/200610011733 200610012057 200610011029 200610010928 > 200610011220/, ""; > > print for sort @x; > ' > 200610011733 > 200610012057 > 200610011029 > 200610010928 > 200610011220 > the time is the last 4 digits (hhmm) so the first is 17:33 then 20:57 then 10:29 then 09:28 i want them chronologically ie 09:28 10:29 17:33 20:57 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
perl sort query
I want to sort a hash of hash by date&time and then extract some of the data. >From the data ive got i can contruct a key that is mmddhhmm and i do this ##error trap absent entries if ($endan=~m/\d{2}:\d{2}\s+\d{2}/ && $stan=~m/\d{2}:\d{2}\s+\d{2}/ ) {my %daylist; ##split start and end date and time my ($endhour,$endmin,$endday,$endmonth,$endyear)=split(/[\ |:|\/]/, $endan); my($sthour,$stmin,$stday,$stmonth,$styear)=split(/[\ |:|\/]/,$stan); ##if its at weekends ( for instance ) my $day = (Date_DayOfWeek($stmonth,$stday,$styear)*1); if ($day>5 ) { my $fd="$styear$stmonth$stday$sthour$stmin"; $daylist{$fd}=\%$br; } foreach $key (sort (keys(%daylist))) { print "$key ";print $daylist{$key};print "\n"; } print "---\n"; } gives me output like this for 1 Oct --- 200610011733 HASH(0x8510560) --- 200610012057 HASH(0x85b3434) --- 200610011029 HASH(0x85732a0) --- 200610010928 HASH(0x86268a4) --- 200610011220 HASH(0x86270fc) so th print out is in the order 17:33 20:57 10:29 09:28 12:20 and my data for the 7th oct 2006 --- 200610071321 HASH(0x859cfdc) --- 200610071156 HASH(0x85a17e8) --- 200610071514 HASH(0x85a2034) --- which is 13:21 HASH(0x859cfdc) 11:56 HASH(0x85a17e8) 15:14 HASH(0x85a2034) so its not sorted as I want -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: accesing a hash of an array of hashes
thanks for the help - im looking up hash slices - but id like to get something that works and then i can add new ideas etc so im going to leave it as it for the time being. Data::Dumper has helped sort out where an error is coming #!/usr/bin/perl -w use strict; use warnings; open O, "<$file" or die "could not open $file - $!"; undef $/; my $whole_file = ; close O; $whole_file=~s/\x0D\x0A1/\x0D\x0AABC1/g;my @rows=split(/\x0D\x0AABC/, $whole_file); ##splits in the correct place after looking at the CSV file with a hex editor - ugly but it seems to work ATM## my %hash; my @headings=split(/,/,$rows[0]) for (my $j=1;$j<=2;$j++) { my @columns = $csv->fields (); for (my $i=0;$i<=$#columns;$i++) {$hash{$headings[$i]}=$columns[$i];} print Dumper(%hash); push (@{$Hofdates{$hash{OPDATE}}},\%hash); print Dumper (%Hofdates); } and i get this output #1st record $VAR1 = 'STANTIME'; $VAR2 = '06:04'; $VAR3 = 'T3_AN2no'; $VAR4 = ''; $VAR5 = 'DESC3'; $VAR6 = ''; $VAR7 = 'T1_ANSNAME'; etc etc to the end then -01/10/2006---BROWN--- $VAR1 = '01/10/2006'; $VAR2 = [ { 'STANTIME' => '06:04', 'T3_AN2no' => '', 'DESC3' => '', 'T1_ANSNAME' => 'SMITH', 'P3_STANDTIME' => '', 'T2_AN2name' => '', 'CANCREASON' => '', 'RN2_NO' => '', 'T2_SUSDuty' => '' } ]; ###2nd record from file $VAR1 = 'STANTIME'; $VAR2 = '17:39'; $VAR3 = 'T3_AN2no'; $VAR4 = ''; $VAR5 = 'DESC3'; $VAR6 = ''; $VAR347 = 'CANCREASON'; $VAR348 = ''; $VAR349 = 'RN2_NO'; $VAR350 = ''; $VAR351 = 'T2_SUSDuty'; $VAR352 = ''; --01/10/2006---JONES-- $VAR1 = '01/10/2006'; $VAR2 = [ { 'STANTIME' => '17:39', 'T3_AN2no' => '', 'DESC3' => '', 'T1_ANSNAME' => '', 'P3_STANDTIME' => '', 'P4_OPCS4_3' => '', 'STANDATE' => '01/10/2006', 'CANCREASON' => '', 'RN2_NO' => '', 'T2_SUSDuty' => '' }, $VAR2->[0] ]; grenada tmp # so its pushing the second hash onto the array and overwriting the 1st -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
accesing a hash of an array of hashes
ive read a load of data in from a CSV file with Text::CSV and ended up with a hash (%hash) where the keys are the column labels. my @headings=split(/,/,$rows[0]) and then for (my $j=1;$j<$#rows;$j++) { my $status = $csv->parse ($rows[$j]); # parse a CSV string into fields my @columns = $csv->fields (); # get the parsed fields for (my $i=0;$i<$#columns;$i++) {$hash{$headings[$i]}=$columns[$i];} I want to process the data once its grouped by the date field present in $hash. So i think I want a hash of dates where the key is that date field I push onto the value the hashes of the records that contain the date push @{$Hofdates{$hash{DATE}}},\%hash; but im having a problem working out how to access the individual items in the hashes that are elements of the array -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
regex and pattern matching
Hi All, Trying to figure out something that should be easy.. If $value_a contains $value_b then Problem is I don't know how to escape the entire variable $value_a so that the . is not considered a quantifier. $value_a = ".com"; $vaue_b = "mycom.org"; if ( $value_a =~ $value_b ) { print "true\n" } I tried m/$value_b/ig also Thanks Paul D'Oyley -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]