Hi All, How can i store integer number (0 <=x<=15) as hexa decimal number in Perl
Hi All, How can i store integer number (0 <=x<=15) as hexa decimal number in Perl
Perl stores all integers natively. Why would you want to even attempt to change that? Or do you actually mean "How to I obtain the hexidecimal representation of a number"? my $hex = sprintf ('%x', $int); Paul Lalli
2.KILL INT can not wake up $SIG{INT}
Hi list, Anyone has such experience? KILL INT pid cannot wake up $SIG{INT} sub{}. my code is like; $SIG{INT} = sub {#load pm} $SIG{ALRM} = sub {print "Driver $pm is going to sleep... bye.\n"; exit;}; the pm actually has a system call to execute something sub xxx { `perl xxx.pl` } but my $tmp = kill "INT", $pid; ## it returns number of processes, eg: 1 cannot wake up the $SIG{INT} at all after $SIG{ALRM} has been executed. does system call cause the problem? Thanks.
3.pack 'C3U*' not same as pack 'C3(xC)*'
Hi, I have a small card game. The clients are Java-applets and the server is written in C, mostly forwarding data from applet to applet. The message format is: 1 byte: Number of unicode chars (s. below) 2 byte: Player number 3 byte: Event id up to 510 bytes: A Java unicode string Now I'm trying to rewrite my C-server to perl, because that way it's easier to add features (syslog, auth against an SQL-db, etc.) I have problems to understand what would be the best pack-format for my messages. I have read "perldoc -f pack" numerous times and also the many O'Reilly books I have, but the best I've come up with is pack "C3(xC)*", length $ascii_str, $num, $id, unpack "C*", $ascii_str; for the cases, when I need to send an ASCII string (like an IP address string) from the server to the Java-applet and thus have to stuff the upper bytes of that ASCII with zeros (that's why the "x" above). I wonder, why doesn't pack "C3U*" do the same? Here is a demo: # perl -e '$str=pack "C3(xC)*", 4, 0, 14, unpack "C*", "test"; \ print join " ", unpack "C*", $str' 4 0 14 0 116 0 101 0 115 0 116 # perl -e '$str=pack "C3U*", 4, 0, 14, unpack "C*", "test"; \ print join " ", unpack "C*", $str' 4 0 14 116 101 115 116 As you see, the stuffing zeros are missing in the second output. But why? Doesn't "perldoc -f pack" say If you don't want this [UTF8] to happen, you can begin your pattern with "C0" (or anything else) to force Perl not to UTF8 encode your string, and then follow this with a "U*" somewhere in your pattern. Regards Alex PS: Also I wonder, if there are any nicer ways to communicate Java-strings to Perl. "perldoc -f pack" mentions "n/..." for Java-Strings, but doesn't elaborate. Is it "n/U*" ?
4.Why char** dynamic_string_array(int ROWS, int SIZE) doesn't work properly?
Hi,please help... It works fine when I define a 2-D array like char code[ROWS][SIZE]. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why? The compiler i'm using is Dev c++. #include <stdio.h> #include <stdlib.h> #include <string.h> int file_length(FILE *file); void down_string(char *p); char* issubstring(char *str1,char *str2); char** dynamic_string_array(int ROWS, int SIZE); int main(void) { int row,n,i,coursefound=0,ROWS,SIZE,test; FILE *datafile; datafile=fopen("3rdyear.csv", "rb"); ROWS=file_length(datafile); printf("Has %d lines\n",ROWS); char **Code,**Course,**ClassSize,**Time1,**Time2,**Room,c; char search[30]; Code=dynamic_string_array(ROWS,SIZE); Course=dynamic_string_array(ROWS,SIZE); ClassSize=dynamic_string_array(ROWS,SIZE); Time1=dynamic_string_array(ROWS,SIZE); Time2=dynamic_string_array(ROWS,SIZE); Room=dynamic_string_array(ROWS,SIZE); for (row=0; row <ROWS; row++) { test=fscanf(datafile, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]\n", Code[row],Course[row],ClassSize[row], Time1[row],Time2[row],Room[row]); printf("row=%d,scanf converted %d (%s,%s,%s,%s,%s,%s)\n", row, test, Code[row],Course[row],ClassSize[row],Time1[row],Time2[row],Room[row]); } printf("Please enter a name\n>"); scanf("%s",search); for(i=1; i<ROWS; i++) { if(issubstring(Course[i],search)) { coursefound=1; printf("Course %s found!!\nTime 1 is %s\nTime2 is %s\nVenue:%s",Course[i],Time1[i],Time2[i],Room[i]); } } if(coursefound==0) printf("No such Course!.\n"); fclose(datafile); return EXIT_SUCCESS; } void down_string(char *p) //turns uppercase letters in a string to lowercase { int i; for(i=0;p[i]!='\0';i++) { if((p[i]>='A')&&(p[i]<='Z')) p[i]+=32; } } char* issubstring(char *str1,char *str2) //checks if string2 is a substring of string2 { char tmp1[30],tmp2[30]; strcpy(tmp1, str1); strcpy(tmp2, str2); down_string(tmp1); //turn it to lowercase down_string(tmp2); return (strstr(tmp1, tmp2)); } char** dynamic_string_array(int ROWS, int SIZE) { char **array; int i; array=(char**) malloc(ROWS*sizeof(char)); for(i=0;i<ROWS;i++) array[i]=(char *) malloc(SIZE*sizeof(char)); return array; } int file_length(FILE *file) { int lines; char dummy[100]; rewind(file); lines=0; while( fgets(dummy, 100, file) != NULL) lines++; rewind(file); return(lines); }
5.will Hyperlinks work on a CD when created from files stored on Int
relative addressing,(\subdirectory\subdirectory\file.nam) or put them in the same folder (file.nam) mgrady wrote: > How do you create a hyperlink in (ppt / word) that links to another file and > document, when all of the final documents will be stored and accessed from a > CD? > > > >
Users browsing this forum: No registered users and 30 guest