file.db VS filedb
when i "use DB_File" the files produced lack a dot in their title, eg. dbmopen %email, email.db, 0666; manipulates a file who's directory entry is actually emaildb MORE IMPORTANTLY, perl will not access a database outside of the same directory as the script -- it pulls a blank hash. without being able to include any functional path in the filenames, i can't even call the script with a soft link...i have to use a shell script to cd first that is ridiculous and i presume a bug that may have been fixed somewhere? perl 5.8.8 on fedora 7 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: file.db VS filedb
you know gunnar i would swear on my mothers grave that i tried using both "" and '' in this and it still would not work, otherwise i really really really would not have cried wolf...but in all honesty it does work now, so there's egg on my face however, my connection of "dbmopen" with "DB_File" is straight out of the 1st Perl Cookbook, but "tie" from the DB_File man doesn't seem much different, nb. they both produce Global symbol "%email" requires explicit package name at /usr/local/bin/AddressBook line 6. even with tie %email, "DB_File", 'email.db'; as long as use warnings/use strict is enabled (otherwise it's fine). To anyone's knowledge is there somewhere/one who has connected these strict warning messages to specific meanings in context? (they would seem very useful if that is the case, otherwise i cannot imagine what "requires explicit package name" could mean beyond the supplied "DB_File") -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
opendir
i am trying to create a perl routine to traverse directories (like a file browser) that will be incorporated into a more specific framework, but for some incomprehensible (to me) reason, opendir will not produce correct information when called in a sub!!! Why (the exact same script works fine -- once, obviously -- without the sub loop)? see attached dirmenu.pl Description: Perl program -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: opendir
hey sorry, cancel that -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: opendir
On 02/09/2008 12:31:33 PM, David Moreno wrote: -> Heh, why? shucks i figured it out. y'all are kooks and i'll let you know when i have a REAL question. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Tk disabling menu entries
no matter where i use: $menu->entryconfigure(#,"disabled); i get: Can't locate object method "entryconfigure" via package "Tk::Menu::Cascade" unless i use it on a non-existent $menu, in which case i get: Can't call method "entryconfigure" on an undefined value Also, if i add a -command in a cascade(), i get no warnings or complaints but perl ignores the command and simply opens the menu. I would like to call a command when a submenu is opened to determine which entries are available; surely this is possible? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries
On 02/12/2008 12:49:30 PM, kens wrote: -> On Feb 12, 9:48 am, [EMAIL PROTECTED] (Mk) wrote: -> > sorry, zentara, but with my perl 5.8.8 this script first produces: -> > -> > Bareword "Mainloop" not allowed while "strict subs" in use at -> > ./Tkmenuentryconfigure.pl line 25 -> > -> > And even after i delete "use strict" i now get: -> > -> > Useless use of a constant in void context at -> ./Tkmenuentryconfigure.pl -> > line 25 -> > -> > I presume it did work for you at some point? -> > -> ... -> -> > On 02/12/2008 07:26:03 AM, zentara wrote: -> -> ... -> -> > -> -> > -> MainLoop; -> > -> __END__ -> > -> -> > -> -> > -> zentara -> > -> -> -> Perl is case sensitive. Note the spelling of MainLoop. -> HTH, Ken yes, i was hoping to be beyond this by now, but there you go. (having thot i cut'n'paste the whole thing when i probably tacked on the last line myself) so now i will have to sit and tackle some concepts (eg. "cget")...but if Larry Wall or whoever is listening [EMAIL PROTECTED]; this issue really really shouldn't be that complicated (w/r/t entryconfigure) all apologies zentara -> -> -> -- -> To unsubscribe, e-mail: [EMAIL PROTECTED] -> For additional commands, e-mail: [EMAIL PROTECTED] -> http://learn.perl.org/ -> -> -> -> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries
Amazingly, what worked in the end was simply adding -state=> 'disabled' into the actual $menu->command, hence avoiding the documented "entryconfigure" method or cget altogether but if anyone has any patience left could you explain: my $state = ($count++ & 1) ? 'normal' : 'disabled'; to me, specifically the "& 1) ? 'x' : 'y'" segment? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries
sorry, zentara, but with my perl 5.8.8 this script first produces: Bareword "Mainloop" not allowed while "strict subs" in use at ./Tkmenuentryconfigure.pl line 25 And even after i delete "use strict" i now get: Useless use of a constant in void context at ./Tkmenuentryconfigure.pl line 25 I presume it did work for you at some point? I also notice from Tk::Menu "BUGS At present it isn't possible to use the option database to specify values for the options to individual entries." I have gotten around this by regenerating the menus with eliminated instead of "shaded" entries, but as always anyone who can successfully explain these mysteries better to me is very welcome to try ;) On 02/12/2008 07:26:03 AM, zentara wrote: -> On Mon, 11 Feb 2008 15:06:27 -0500, [EMAIL PROTECTED] (MK) -> wrote: -> -> > -> >no matter where i use: -> > -> >$menu->entryconfigure(#,"disabled); -> > -> >i get: -> > -> >Can't locate object method "entryconfigure" via package -> >"Tk::Menu::Cascade" -> > -> >unless i use it on a non-existent $menu, in which case i get: -> > -> >Can't call method "entryconfigure" on an undefined value -> > -> >Also, if i add a -command in a cascade(), i get no warnings or -> >complaints but perl ignores the command and simply opens the menu. -> I -> >would like to call a command when a submenu is opened to determine -> >which entries are available; surely this is possible? -> -> Menu's are a complex nested structure and you need to delve into -> it with cget, to get to the right menuitem. -> -> Look at this example: -> #!/usr/bin/perl -> use warnings; -> use strict; -> use Tk; -> -> my $count = 0; -> -> my $mw = tkinit; -> -> my $menubar = $mw->Menu(-type => 'menubar'); -> $mw->configure(-menu => $menubar); -> -> my $menu = $menubar->cascade(-label => '~File'); -> $menu->command(-label => '~New'); -> $menu->command(-label => '~Open'); -> -> $mw->Button( -> -text=> 'Push me and look at the menu', -> -command => sub { -> my $state = ($count++ & 1) ? 'normal' : 'disabled'; -> $menu->cget(-menu)->entryconfigure(2, -state => $state); -> } -> )->pack; -> -> MainLoop; -> __END__ -> -> -> zentara -> -> -> -> -- -> I'm not really a human, but I play one on earth. -> http://zentara.net/japh.html -> -> -- -> To unsubscribe, e-mail: [EMAIL PROTECTED] -> For additional commands, e-mail: [EMAIL PROTECTED] -> http://learn.perl.org/ -> -> -> -> -> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Newbie File Question....
On 02/13/2008 11:34:56 AM, [EMAIL PROTECTED] wrote: -> I've been going over some listings and I found code -> -> like the following: -> -> -> -> "./directory/file.txt" and -> -> "../directory/file.txt" this is not really a perl question, but since perl does respect the reference: "." and ".." are relative directories. They ALSO have a real (absolute) name. "." refers to the directory in question, eg. your present working directory (pwd). So if you cd to /home/mine, "." now refers to /home/mine (that's the real name). ".." refers to the directory above "." in a hierarchy. In /home/mine ".." would refer to /home. You really need to find a simple explanation of the unix filesystem, of which i am sure there are many on the web; otherwise you are going to have have more problems. Also try: www.ss64.com/bash/ which explains shell commands like ls and cd, since those commands do not have their own manual pages. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: processing related elements in an array
On 02/14/2008 09:33:51 AM, [EMAIL PROTECTED] wrote: -> I admit, after making my post and taking a break, I had gotten a -> little ahead of myself when stating this problem. Basically, I had -> reached a point where I was able to get to @arr3, and couldn't figure -> the rest out; the previous stuff I figured out. I felt I needed to -> come up with some background info and perhaps it just made things -> more -> confusing. More significantly, I also didn't know much of the -> correct -> terminology/what things were called officially... -> -> If you're curious to know the background info (I wanted to make it as -> less specific as possible), I have a table in a MySQL database that -> contains a list of tailored information about other tables in that -> same database. Certain technicalities had forced me not to use -> InnoDB's and thus, I cannot use any foreign keys; the information -> within that table of tables is a way for me to automatically make -> those connections between tables. When I mentioned A and C in @arr1, -> A is a record that represents another table in that database, C -> likewise. B is also a record in the table, and there are references -> to A = B and B = C/they link together... -> -> Thus, if you're attempting to come up with a dynamic select query, -> you'll have to come up with some tricky coding to include all the -> tables that are given within the statement. ie, if you specify a -> field from one table, and a field from another, you'll have to -> specify -> something like this: SELECT A.field1, C.field1 FROM A, C; -> i am not the expert but i do have to ask: nick, do you know what a "hash" is? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries, etc.
from zentara: -> Now you may not see the usefulness of the entryconfigure or the cget, -> but what if you had a more complex menu, and needed to dynamically -> grey out items? That is exactly what i did (the cascading menus are a recursive tree, with several hundred+ total entries dynamically generated). I want some entries grayed out when some operation is/has been performed and also to completely disappear (and appear) for other reasons. To do this i simply included all the: -> my $menu = $menubar->cascade(-label => '~File'); ->$menu->command(-label => '~New'); ->$menu->command(-label => '~Open'); inside a subroutine ("scanmenus"), run once initially and then called with: $mw->bind(""=>sub{scanmenus();$menu->Popup;}); A $mw->Button will also work. That way, rather than having to use cget and reconfiguring an existing menu, the menu is generated anew every time it pops up (a menubar would be harder; you will have to dynamically "destroy" widgets). Since every instance is just the same as the original (only different) there is no need for additional entryconfigure code. It also means the initial state is not a preformatted default, and deals with: -> I still havn't figured out how to grey out -> an arbitrary item in a deeply cascaded menu. because you would also then need to track the index numbers of these arbitrary items for "entryconfigure" (even more code). Forget entryconfigure; instead, just include a possible -state=>disabled in the "command", governed by a conditional expression in the menu-generating subroutine: } elsif ( $Ldata !~ /$this1/ ) { $MM{$this1} = $MM{$this}->command(-label=>"$this1",-command=>[\&dosub, "$this1"]); } elsif ( $Ldata =~ /$this1/ ) { $MM{$this1} = $MM{$this}->command(-label=>"$this1",-state=>'disabled'); Note that widget names can be elements of a hash (%MM, the main menu; $this would be a cascade submenu, $this1 an entry). Perl creates the cascaded menu tree (again, hundreds of total entries) instantaneously. You would have to include your own "my's" (i never "use strict" because i am convinced that declaring a variable LOCALLY should be the exception, not the rule, instead of vice versa w/ strict). But it will still be the same thing... thanks, b/t/w for the Ternary operator and the "& 1" test -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries, etc.
On 02/17/2008 12:08:40 PM, zentara wrote: -> Yeah, dynamically generated menus would be the way to go, -> but I would watch out for memory gains everytime you invoke the menu. -> Tk isn't very good about object cleanup. i will remember and look into this. -> Another problem with dynamic menus, is that is may be harder on the -> user. I, for one, get a feel for what-and-where all the menu options -> are. If they change dynamically, it can be an annoyance. hmmm...personally, i don't use any button-bars or docks, or even title-bar buttons with my WM. Just key macros and mouse menus. Atypical, but faster and easier (once you know all the combinations). In fact the menus in the app i did were all filesystem directory entries, and the operation performed on them depends on context (it may be copy, or find, or whatever). So there is no way for me to keep the entries static. It is, in essence, a file browser with much less clicking -- via the cascades you can move into a tree recursively at once, since the entire tree is generated at once. Fast. But remember, no one else has to use it ;) I included a script which does something very similar to your last post, but with popups in my subroutine driven style. Two things i would observe 1) it involves more perl, less tk; 2) it is less than half the size in bytes. Line length limits in email mean i had to attach it, hopefully the unix LF's are ok. -> (i never "use strict" -> because -> >i am convinced that declaring a variable LOCALLY should be the -> >exception, not the rule, instead of vice versa w/ strict). -> -> You will probably change that attitude toward strict later. I think -> in -> Perl6, strict will be on by default, and your code will be tough to -> work -> with. I guess i will have to keep my copy of 5.8.8, haha. Thanx for letting me know, and about comp.lang.perl.tk, i had forgotten newsgroups. new.pl Description: Perl program -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
subroutine simultaneousness
I have a subroutine that begins with a message ("Processing...") and then proceeds to perform several gigs worth of file transfer via system calls. Basically: sub transfer { print "Processing...\n"; foreach $e (@array) { print "file $e\n"; system "cp $e"; #or whatever } print "...done\n"; } Unfortunately, perl completes the entire (minutes long) routine BEFORE it prints anything, so when the whole thing is done, suddenly the "Processing...file X...file Y...file Z...done" appears. Why? and is there a way around this? I would like to know what is happening while it is happening, and not after it is finished. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine simultaneousness
On 02/17/2008 03:48:40 PM, Rob Dixon wrote: MK wrote: > I have a subroutine that begins with a message ("Processing...") and then proceeds to perform several gigs worth of file transfer via system calls. Basically: sub transfer { print "Processing...\n"; foreach $e (@array) { print "file $e\n"; system "cp $e"; #or whatever } print "...done\n"; } Unfortunately, perl completes the entire (minutes long) routine BEFORE it prints anything, so when the whole thing is done, suddenly the "Processing...file X...file Y...file Z...done" appears. Your output is being buffered. Yes. This is clearly the problem, thanks. As for the solution, I'm afraid i still need help. A specific complication may be that there is a write to then a read from a text file list of the files to copy, so actually (with recommended buffering commands and use File::Copy): sub transfer { STDOUT->autoflush(1); print "Processing...\n"; open(FH, ">list.txt"); FH->autoflush(1); print FH "data"; close(FH); open(ALT, "autoflush(1); while () { foreach $e (@array) { chomp $_; ALT->flush(); copy("$_","fileX"); [a tk command like print "...file"] } [a tk command like print "...done"]; } None of this made any difference. None of the FAQ's i found refer to the copy or system "cp" as an issue (neither do they say it is not). Probably i can do this with arrays to avoid the list.txt, but i would prefer the actual log as well anyway. Could this be a tk issue (i have yet to try it as a plain script)? The buffer is flushed only either when it is filled up or when the filehandle is closed (when the program terminates). You could flush the buffer explicitly after each print statement i believe that is ALT->flush(). Is there a possible filehandle for the actual binary in the copy statement that could be set to autoflush, other than STDOUT? The files are not concatenated. but the easiest thing is to enable autoflushing which will do that implicitly. Just add use IO::Handle; STDOUT->autoflush; yep. did that too. There must be a way out of this. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine simultaneousness
okay, this is definitely a Tk or GUI issue, since incorporating a for real "print" (ie. to STDOUT) statement does come out in proper sequence. Does anyone know if there is a filehandle other than STDOUT for tk requests? The simplest version of the problem: use IO::Handle; sub tmptest { STDOUT->autoflush(1); # $FLT is a text area $MW->title("processing..."); my $data = $FLT->get('1.0','end'); @LData = split(/\n/,$data); $FLT->delete('1.0','end'); foreach (@LData) { my $name = basename($_); print "$_\n"; STDOUT->flush(); $FLT->Insert("$name\n"); sleep 1; } $MW->title("...test done"); } So the "print" line comes out in a background terminal one second at a time...but the Insert and other Tk events happen at the end, simultaneously. In fact, this is exactly the same even without IO::Handle and all the buffering commands. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine simultaneousness
PROBLEM SOLVED on comp.lang.perl.tk: $MW->update; # whenever you want the screen updated On 02/18/2008 09:46:51 AM, MK wrote: okay, this is definitely a Tk or GUI issue, since incorporating a for real "print" (ie. to STDOUT) statement does come out in proper sequence. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tk disabling menu entries, etc.
-> Well, I tested your script. It gains appreciable memory at each menu -> invocation. My deep cascading example, stays steady in memory use. sigh. yes, i just observed this myself w/ "top". -> ( And as a side note, this is where using -> strict comes into play. it can force closures of localized -> variables/objects, and hopefully reuse the memory. again, i hope this remains a choice anyway, esp. if the ridiculous menu methods go unchanged (now you have to do it our way! hahahah!) The real finished app is still only a quarter the size of firefox (when it starts...). It's actually to build song lists for an mp3 usb-stick, which has three buttons (play/pause, forward, back), no screen, and plays an UNSORTED vfat directory -- the tracks are played in the order they get copied into the stick, period, meaning you cannot erase and substitute, reorder, etc. without erasing and rewriting the entire (512mb) directory. Strangely, the manufacturers do not even make software for them ("Just start up Explorer and start copying!"; i suppose most people prefer the somewhat more expensive ipod. as a skateboarder, i would rather trash a $20 item). According to my search, only one guy makes anything at all to do this under linux, and boy is it massive once you consider the number of obscure GUI libraries required! So in some sense i am starting to consider this an Important Project. Certainly I've learned a ton about perl and the Tk module actually works way better than i would have imagined. There you go. If i get any more elaborate, tho, i will have to deal with the memory issue, so thanks much for warning me now (I thot i was being so smart here). -> P.S. You may want to look at Perl/Gtk2, which has a much better -> underlying object design, than Tk. It's object cleanup is much -> better, -> and the menuing system is alot clearer. perl/Gtk2 ?!??! egads...eureka...who would have imagined such a thing! Scorch my sleep depro peace & love -- MK -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: GUI Toolkit - which one to learn? (GTK/GTK2/Tk)
just to add my two sense worth i reworked my Tk app to eliminate the memory gains from $widget->destroy (using -- much thanks, i surrender, zentara -- cget->entryconfigure) and it works beautifully and does exactly everything i want, certainly i like it more than anything i've seen attempting to do something similiar but not exactly the point here being that it was my second Tk project after an email rolladex, like perl it seems well playtested, text manipulation is simple and versatile. And if everything on your desktop already boring old Gtk(2), tk has a nice, duplo-retro look... but i haven't looked into anything else, so get your grains of salt. nb. your WINDOW MANAGER may or may not present issues (no problems on fvwm2/linux). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Hash Sorting Problem
On 02/25/2008 04:32:42 AM, Anirban Adhikary wrote: -> Dear List -> -> I need to delete each element after every execution of the foreach -> loop and -> I need to update & sorted the @arr1 after every execution of the -> foreach -> loop. I have tried a lot but not able to do this Pls -> help... You cannot mean what you just said, which is a big reason for it not to work. If you use the elements of an array and then expect redefining the array will continually mean something in a loop this makes no sense. I did not carefully peruse your code but i think what you REALLY want is some form of nested loop: $somecount = 0; $somereason = 10; until ($somecount > 10) { foreach $e (@array) { delete $file{$el}; } $somereason++; NOW REDEFINE @array; } Also you should understand "push" "shift" "unshift" "pop" because either i miss the point (very possible) or your relating of arrays and hashes does. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: scalar / hash problem in HTML::Parser
On 02/25/2008 09:01:27 AM, Tim Bowden wrote: -> Making progress. Needed to understand hash references, and how to -> de-reference them. delete($HASH{$KEY}); if that's what you mean; good luck with the stupid stick (i hope it ain't me) -> -> Tim Bowden -> -> On Mon, 2008-02-25 at 14:54 +0900, Tim Bowden wrote: -> > Hi all, -> > -> > I'm using HTML::Parser to process files containing snippets of html -> > looking like: -> > First optionAnother -> > choicepick me -> > -> > I'm wanting to create a hash of option value, name pairs. Ie, 1 => -> > "First option",2=>"Another choice" and so on. Problem is, I don't -> know -> > how to handle the hash returned in $attr in the start sub: -> > -> > #!/usr/bin/perl -wT -> > use strict; -> > use HTML::Parser; -> > -> > my %choices; -> > my $file = 'test_snippet'; -> > my $parser = HTML::Parser-> new(api_version => 3, -> > start_h => [\&start, "tagname, attr"], -> > ); -> > -> > sub start { -> > my ($tag, $attr) = @_; -> > print "$tag\t$attr\n"; -> > # do something here to read the hash returned in $attr -> > # and add the key value pair to %choices but what? -> > } -> > $parser->parse_file($file) or die "couldn't parse file"; -> > -> > -> > I realise it should be obvious and simple, but I feel like I've -> been hit -> > with the stupid stick for now. Any suggestions? -> > -> > Thanks, -> > Tim Bowden -> > -> > -> -> -> -- -> To unsubscribe, e-mail: [EMAIL PROTECTED] -> For additional commands, e-mail: [EMAIL PROTECTED] -> http://learn.perl.org/ -> -> -> -> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to read from keyboard?
On 02/27/2008 09:04:50 AM, obdulio santana wrote: -> Hi. -> -> I want to read from keyboard some keys [pagedown], -> [Home],[End][PageUp][up][left][down][right]. -> -> how can I do it? -> -> Thanks in advance. -> -> Term::Readkey also works but is poorly documented. Does anyone know how to use the hex values from keysymdef.h (which includes the entire extended keyboard) in a perl statement? So, eg. if ($char eq "0x0057") {etc...} Or where to get values for printf "\U" "\u" that will work? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to read from keyboard?
Okay i have the exact answer for you now. The following script will give you decimal and hexidecimal values for each keypress. The hex value can be used in normal regex and print statements using \x; the example in the script quits using capital Q and (from my keyboard) PgUp (this probably remains the same). Some keys like PgUp and Home give three sets of values per press (except on quit, when you get the wrong two); the one that worked for me was the last one. nb. make sure you exit this cleanly (capital Q or, if it works, PgUp) because the last line is needed to reset the terminal properly. #!/usr/bin/perl # get ASCII values for keypresses use warnings; use Term::ReadKey; ReadMode('cbreak'); print "Press a key.\n"; while (1) { #infinite loop $C = ReadKey(0); last if ($C eq "Q"); last unless defined $C; last if ($C =~ /\x7e/);# eg. \x in regex printf("$C\tDecimal: %d\tHex: %x\n", ord($C), ord($C)); } ReadMode('normal'); # IMPORTANT! Now you should be able to make any key do anything easily. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
On 02/27/2008 02:59:30 AM, vijay krishna wrote: -> Hi All, -> I want to check if a sub routine that I am calling -> returns a value or not. -> This is how my code is -> $str = function(parameter) -> -> sub function -> { -> -> .. -> -> } -> -> the sub routine function in turn uses many other function. Some of -> these functions have a return statement and some do not. -> -> So, when i invoke the sub routine "function" and i pass the returned -> value into $str, I need to check if $str has any value assigned or -> not. -> -> Can you tell me how I could accomplish this? Well the guaranteed way to accomplish this is to just call the function AND THEN assign your variable within that function: # do not "use strict" function(parameter); sub function { # call as many more functions as you want $str=; # do not use "my $str" } A subroutine/function does not require a return statement and using one probably will not help you assign a scalar value. The purpose of return is to exit the subroutine at some arbitrary point and the return value is limited (usually to indicate "success" or "failure"). Again, i believe YOU ARE MISCONCEPTUALIZING with "$str = function(parameter);". -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
On 02/29/2008 11:21:52 AM, Tom Phoenix wrote: -> On Thu, Feb 28, 2008 at 4:28 PM, MK <[EMAIL PROTECTED]> -> wrote: -> -> > # do not "use strict" because i don't. that's all. but wait a minute... -> > The purpose of -> > return is to exit the subroutine at some arbitrary point and the -> return -> > value is limited (usually to indicate "success" or "failure"). -> -> What does "the return value is limited" mean? Can you give a concrete -> example of what you're talking about? Okay, now i apologize for being stupid whilst jumping a gun. By return I meant that "return" called alone simply gives you a zero. But this clearly misses a point of clearer educational value, vis. what we all already believe: return "anything"; is exactly that. However, vijay's question implies this method isn't working for him, and the (unexplained) problems with multiple nested subroutines might be resolved by just using global ("myless") variables defined within the functions. Of course, once that works, the script might be further resolved back into the "$x=function()" style. I seem to believe i have had that experience myself. Maybe...soon... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
On 02/29/2008 06:57:52 PM, Tom Phoenix wrote: -> > I meant that "return" called alone simply gives you a zero. -> -> Without an argument, return gives the sub's caller either undef or an -> empty list, depending upon context. -> What do you do with return that "gives you a zero"? well you are certainly putting me in place, Tom, which is why i really, really shouldn't quack off the top of my head so. I guess when i use return there is always something returned, so I was just presuming (wrongly, as you demonstrate) that otherwise return has a integer value like an exit code. Your diligence is sincerely appreciated. MK @ perl.beginners -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
ps. Tom do you know why are you one of those people who's messages always appear twice in my mailing list? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
On 03/01/2008 07:53:53 AM, Jeff Pang wrote: -> On Sat, Mar 1, 2008 at 8:39 PM, MK <[EMAIL PROTECTED]> -> wrote: -> > ps. Tom do you know why are you one of those people who's messages -> > always appear twice in my mailing list? -> > -> -> Because Tom replied to both you and the list. Maybe so, but get this: I definitely have two identical messages addressed to me (none to the list, which makes it stranger) hmmm...not a perl issue i guess -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Check if a given function returns something
On 03/01/2008 10:42:44 AM, Tom Phoenix wrote: -> Here's another pair for you. Your mail client is probably only -> showing -> the basic email header lines, which would include the "to:" header -> indicating that you're the primary recipient. Get your program to -> show Tom i actually cat & grepped through the raw mbox to make my first observation. And there is no delay, to the second. But after using diff, i would add that the "Return-Path:" is the essential difference, not the "To:" line (which is very definitely the same in any case). This must be some feature of the mailing list, which i am aware there maybe some web checkbox somewhere about this -- but they do not otherwise re-address the "To:" line of other messages. (=why i ask) Probably time for a walk! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable help
On 03/04/2008 03:41:44 PM, yitzle wrote: -> I'd use a RegEx and test to see if the string is made up entirely of -> integers. -> print "The variable containing $p is an interger\n" if ($p =~ -> /^[0-9]+$/); yitzle would seem to have the most foolproof solution. The only problem would be if $p="+1" which i would consider +1 an integer. incidentally /^\d+$/ amounts to the same thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/