Re: Removing entries from an array
> > (at > > least I think so) locations in the file, a random tip is displayed. Once > > it > > is, it has to be marked as used. Currently, I'm doing this: > > > > # Tip is done; remove it > > $tips[$tip_num] = $tips[$num_tips - 1]; > > undef $tips[$num_tips - 1]; > > --$num_tips; > > > > Am I doing it cleanly? > > Should I use $#tips instead of a separate count variable (as I've done), > > and > > will decrementing $#tips actually reduce the size of the array in memory? > How about a different approach? If you're only using each element once, and you're pulling them randomly, why not scramble the array, and then use each element in turn? If/when you get to the end ( $tips_num == (@tips - 1) ) (or something like that), just reshuffle and start over. Or maybe (now that I look at your code some more), that's mostly what you're doing. I guess the question is: why bother taking the tip out of the array, instead of just going past it and leaving it there? Oh, and I found this somewhere. Pretty handy: # fisher_yates_shuffle( [EMAIL PROTECTED] ) : # generate a random permutation of @array in place sub fisher_yates_shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); @$array[$i,$j] = @$array[$j,$i]; } } Paul Archer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: convertion bash script to perl
Sorry, nope. The thing is that shell scripts are essentially shell commands for control, and external commands for everything else. OTOH, manually rewriting a shell script in Perl is going to give you lots of experience in Perl. 8-) My best advice: take a deep breath and dive in. Paul 5:59am, thyagarajan k wrote: > Hello friends, > > i am quite new to perl and currently i have a > requirement like to re-write the script written in > unix bash shell to perl. I would like to know is > there any convertion tools available so that i can > convert my shell script to perl script. > > rgds > thyag > > __ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com > -- I recenly heard that scientists have isolated the gene that makes scientists want to isolate genes. -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
shared data in a class
The answer to this is probably out there somewhere, but I haven't run across it yet, so a pointer to a webpage/tutorial/FAQ/whatever would be fine... I'm trying to put together an object class (my first OO attempt) for a Curses-like interface to a serial LCD display. I want to have multiple objects that different code can write to (menus, status, etc), and a method to update the display (a la 'refresh' in curses). The problem/question is: how do I have all the different objects in this same class access the object that gets updated? In other words, let's say $main_display is the object that represents what is (or should be) currently on the display, and $menu_display is an object that gets updated with new menu items. When I do $menu_display->refresh, the data in the $menu_display object needs to be transfered to the $main_display object (and comparisons made, and data written to the LCD). I suppose I could have a call like: $main_display->refresh_from_other_object(\$menu_display) (or something like that...I'm still getting used to the syntax), but that seems a waste to have to pass data manually, when the $menu_display object should be able to do it itself. TIA, Paul Archer Never ascribe to malice what can perfectly well be explained by stupidity. -Anonymous -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: shared data in a class
3:28pm, Bob Showalter wrote: > Paul Archer wrote: > > The answer to this is probably out there somewhere, but I haven't run > > across it yet, so a pointer to a webpage/tutorial/FAQ/whatever would > > be fine... > > > > I'm trying to put together an object class (my first OO attempt) for a > > Curses-like interface to a serial LCD display. > > I want to have multiple objects that different code can write to > > (menus, status, etc), and a method to update the display (a la > > 'refresh' in curses). The problem/question is: how do I have all the > > different objects in this same class access the object that gets > > updated? > > Store the display object as class data in the base class for the widgets. > > perldoc perltootc > perldoc perltoot > I didn't know there was a 'perltootc' out there! That's just what I needed. Thanks much, Paul > > > > In other words, let's say $main_display is the object that represents > > what is (or should be) currently on the display, and $menu_display is > > an object that gets updated with new menu items. When I do > > $menu_display->refresh, the > > data in the $menu_display object needs to be transfered to the > > $main_display object (and comparisons made, and data written to the > > LCD). I suppose I could have a call like: > > $main_display->refresh_from_other_object(\$menu_display) > > (or something like that...I'm still getting used to the syntax), but > > that seems a waste to have to pass data manually, when the > > $menu_display object should be able to do it itself. > - WWJD? JWRTFM - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
array or scalar for display?
(As I noted in an earlier post) I'm writing a handler for an LCD display (a BPP-440 from Scott Edwards (www.seetron.com)). The display is 4 lines x 40 characters, and has direct cursor positioning. I'm going to store the data for several virtual screens, but I don't know whether it would be better (in terms of speed and writing/maintaining the code) to use an array with 160 elements (one for each character), or a single scalar with 160 characters. It seems to me that if I use a scalar I can use perl's string manipulation tools, and if I use arrays I can use slices--but I have no idea if one is going to have any significant advantages/disadvantages over the other. Any suggestions? Thanks, Paul Archer - witzelsucht (vit'sel-zoocht) [Ger.] "A mental condition characteristic of frontal lobe lesions and marked by the making of poor jokes and puns and the telling of pointless stories, at which the patient himself is intensely amused." >From Dorland's Illustrated Medical Dictionary, 26th edition. - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Comparing two strings for first difference
I'm working on a bit of code to update a serial LCD display. The display is 4 lines by 40 characters, and each character can be addressed individually. First, the pseudocode I have is: compare each element of the new string and the old string # each string is 160 characters, and represents what is on the # display or what is going on the display (if the characters differ) { (if the state flag is not set) { set it and concatenate the direct-positioning characters to a temp string, along with the new character } else { just concatenate the current element of the new string to the temp string }; } else { (if the state flag is not set) { go to next element } else { (if one of the next three characters has changed) { keep state flag set, add character to temp string # idea here is it's cheaper to just print a character # that hasn't changed than a new set of positioning # characters if another character right after it has changed } else { unset flag } } } If anyone can offer general improvements to that approach, that'd be great--but what I'm really interested in is finding the first element that differs, and maybe the last as well. If there were any easy way to find that, say, the first character that differs is at position 120, and the last character that differs is at position 135, then I only have to loop through 15 characters, not 160. TIA, paul - On the side of the software box, in the "System Requirements" section, it said "Requires Windows 95 or better". So I installed Linux. - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Comparing two strings for first difference
Thanks a lot! This is just what I was looking for in your first example. (The second example won't do me as much good, as I need to consider characters that haven't changed inside of a string of characters that have--but it's still a good reference.) Thanks again, paul 10:11am, Rob Anderson wrote: > > If anyone can offer general improvements to that approach, that'd be > > great--but what I'm really interested in is finding the first element that > > differs, and maybe the last as well. If there were any easy way to find > > that, say, the first character that differs is at position 120, and the > last > > character that differs is at position 135, then I only have to loop > through > > 15 characters, not 160. > > Probably the quickest way to do this in perl is as follows > > > #!/perl -w > use strict; > my $string1 = "The quick brown fox."; > my $string2 = "The Kuick brUwn fox."; > > my $string_xor = ("$string1" ^ "$string2"); > > $string_xor =~ /^(\0*)/; > print "Number of equal bytes at the front of the string = " . length($1) . > "\n"; > $string_xor =~ /(\0*)$/; > print "Number of equal bytes at the end of the string = " . length($1) . > "\n"; > > > the xor op (^) will return a string, every matching byte of which will be > null, every mismatching byte will have some bit (literaly) set. > > so the all first regex does is match the all the null bytes it can find from > the front of the string, the length of the string is equivalent to the > number of identical chars at the front. > The second regex is the same, just working from the end. > > You could extend this and translate all the non-null values to something you > could then search for that value with index. This would give you the > positions of all the bytes that were different... > > my $string_xor = ("$string1" ^ "$string2"); > my $pos = 0; > while ( ($pos = index($string_xor, 'X', $pos)) != -1) { >print "==> $pos\n"; >$pos++; > } > > Hope this helps, > > Rob > > > > > TIA, > > > > paul > > > > > > - > > On the side of the software box, in the "System Requirements" section, > > it said "Requires Windows 95 or better". So I installed Linux. > > - > > > - "Somebody did say Swedish porn, there-- but someone always does..." --Clive Anderson, host of "Whose Line Is It, Anyway", after asking the audience for movie suggestions - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: custom return value from entire script
> Anyone know if it's possible for the return/exit value of a script, in the > event of success, to be something other than 0? > The 'exit' command should work just like it does in the shell: 'exit 9;' for example, *should* give you an exit status of 9 (although I couldn't get it to work for me a minute ago...). > I want to call, from a shell script, a perl script that determines a certain > record ID from a database. When the ID has been obtained, the script would > exit, and the calling shell script would receive the returned value. > Why muck around with exit statuses? Just have the perl script print the value you want, then in your shell script you can do something like: myID=`perl_script_to_return_ids` Or just do it all in Perl. 8-) > The 'return' command doesn't allow this - I've thought of setting an env > variable - not sure how to export it from perl so the environment sees it. > Would like to get plan A to work first though.. Impossible. You can't run a subcommand and have it set a variable for the calling shell. If Peter Parker gets bit by a radioactive spider and gains spidey-powers, he could pass those powers to his kids--but never his parents. Paul - "Welcome to downtown Coolsville--population: us." - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: fast match count of char in string
Here's a quick way: perl -e '$var="abdaatela"; print ((scalar grep /a/,(split /(.)/,$var)),"\n");' grep returns the number of matches in a scalar context, and the split breaks the string up into separate elements. The parens in the split return the item split on (otherwise it would throw away each character it encountered). Paul PS. Wow, it almost looks like I know what I'm talking 'bout, don't it? 8-) Yesterday, Juerg Oehler wrote: > hi, > > how do efficent count char 'a' in string "abdaatela" ? > > i guess there are better solutions than: > > $tmpstr =~ s/[^a]//g ; > $cnt = length ($tmpstr) ; > print ("found <$cnt> a's <$tmpstr>\n"); > > thanx > george > > > > "My parents just came back from a planet where the dominant lifeform had no bilateral symmetry, and all I got was this stupid F-Shirt." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple process controll question
11:29am, Ramprasad A Padmanabhan wrote: > > > do "foo.pl args..." > > > > > > And in foo.pl set some scope defined variable like > > > > > > #foo.pl > > > $dbh=connect() > > > unless($dbh){ > > > $GLOBAL::ERRORSTR="Couldnot connect to database $@"; > > >exit 1 > > > } > > > > > > > > > And in the main program you can check > > > > > > if($GLOBAL::ERRORSTR) { > > > # Hmm something went wrong > > > ... > > > > > > But personally I consider this as dirty work though it works. Let me > > > know If you get a better way > > > > > I don't understand how can perl pass variables across processes. Sort of > > magic? > > > Did you try it. If it works perl is a wizard else I am just wasting my > time > I think it is just that when you do a 'do foo.pl' No new perl instance > is forked. It is just that the perl interpreter instance that was > running your main code now interprets the foo.pl. > Since it shares the same 'process environment' I think maintaining any > variable does not require any harry potter skills > Do is to Perl as source (or '.') is to the shell--i.e. it reads the code in the referenced file into the current program. It's the poor cousin of 'use' and 'require'. Paul PS. Ram, I don't think your .sig file is long enough--where's your bio and list of top 25 movies, man? 8-) > Ram > > > > > NETCORE SOLUTIONS *** Ph: +91 22 5662 8000 Fax: +91 22 5662 8134 > > MailServ: Email, IM, Proxy, Firewall, Anti-Virus, LDAP > Fleximail: Mail Storage, Management and Relaying > http://netcore.co.in > > Emergic Freedom: Linux-based Thin Client-Thick Server Computing > http://www.emergic.com > > BlogStreet: Top Blogs, Neighborhoods, Search and Utilities > http://www.blogstreet.com > > Rajesh Jain's Weblog on Technology: http://www.emergic.org > > > I just saw this headline today (1/3/00) in the Houston Chronicle online: "Death row prisoners launch hunger strike" Is it just me or is this not a problem? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Kinda Perl
Yesterday, [EMAIL PROTECTED] wrote: > I have been writing perl along with some other languages, and I have been > thinking about setting up a server (so that I can play with different > server OS's and settings without messing anything up on our home network). > My parents think that it will cost to much in power. I was just wondering > if anyone knows about how much it is per day to run a computer without a > monitor. > This might help: I live in South Texas (Houston, to be exact), and run a Celeron-300 class machine, two dual-processor Celeron-600 class machines, two monitors, an array of peripherals, and two UPSs (all 24/7 except for the monitors, which are on about 10 hours a day)--and in the summertime heat my electric bill (average 10 cents/Kilowatt-hour) is still around $150 a month. So yes, the machines do eat a bit of electricity, but replace some standard incandescent bulbs with florescent, and it'll balance out. Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl/crontab Question
Yesterday, [EMAIL PROTECTED] wrote: > This may be a bit off topic, but I'll ask it.. > > I have a perl job I want to run out of a cron job, However cron is not > reading my .cshrc file by default. So what I have to do is "wrap" the perl > job in a tcsh shell and then run the shell file out of cron. > > Is there a better way? Or maybe the real question is should I be > "hardcoding" the var's out of my .cshrc file in my perl script? I think > this may be a bad thing to do, but isn't this what I'm doing in the .cshrc > file? > My personal trick if I need a complete environment for a cron job or startup script is to create an 'at' job that runs what I want, then find the file in /var/spool/atjobs (for Linux), and copy it where I need it. (Don't forget to remove the atjob, since you probably don't actually want it to run.) Since 'at' captures the complete environment, the file (script, actually) will have everything you need in it. Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Very slow array searching
In addition to the suggestions already given, you could sort your array, and then look at the middle and cut it in half (potentially several times). I forget the name for this technique, though... For example, you have 1000 elements, sorted. You compare your number to the 500th element. If it's higher, you throw away the first 500 elements. Then you compare your number to the 250th element, decide which half your number belongs in, and throw away the other half. If you just do that twice, you've reduced the amount of data you have to look through by a factor of four. Paul 3:20pm, Ramprasad wrote: > Rafaqat Ali Chaudhry wrote: > > Dear all, > > > > I've a function which searches a given number from an array and returns > > the result. > > > > Function: > > > > 1. sub checkNumber($) > > 2. { > > 3. my ($l_number) = @_; > > 4. my $l_status; > > 5. my @matches= grep { /$l_number/ } @numbers; > > 6. if (@matches) { > > 7. $l_status="TRUE"; > > 8. } > > 9. else { > > 10. $l_status="FALSE"; > > 11. } > > 12. return $l_status; > > 13. } > > > > The Way I call it: > > > > 1. $check=checkNumber($num1); > > > > The array has at least 20K elements. This piece of code is taking up > > almost 100% of the CUP cycles. Would somebody please suggest some > > alternative solution. > > > > Thanks in Advance > > > > Rafaqat Ali Chaudhary > > > You can improve the code largely by just returning immediately as you > get a match > > ( dont use grep when you dont need it ) > > > sub check { > my ($l_number) = @_ > foreach ( @numbers) { >return 'TRUE' if($_ == $l_number); > } > return 'FALSE'; > } > > So every false condition would have gone thru all elements but every > true condition will return immediately > > > Besides if you are doing this check a lot many times in your program It > may be better to create a hash array. Hash arrays are implemented real > good in perl > then you can use > > In the main script put > > my %hash = (); > @[EMAIL PROTECTED](); > > so you can check directly > > if(exists($hash{$l_number})) { > > .. # this is TRUE > > } else { > > # this is FALSE > > } > > > > The Hash method will take more memory but will be much quicker > > > > Thanks > Ram > > > - On the side of the software box, in the "System Requirements" section, it said "Requires Windows 95 or better". So I installed Linux. - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl/crontab Question
> > > I have a perl job I want to run out of a cron job, However cron is not > > > reading my .cshrc file by default. So what I have to do is "wrap" the perl > > > job in a tcsh shell and then run the shell file out of cron. > > > > > > Is there a better way? Or maybe the real question is should I be > > > "hardcoding" the var's out of my .cshrc file in my perl script? I think > > > this may be a bad thing to do, but isn't this what I'm doing in the .cshrc > > > file? > > > > > > > My personal trick if I need a complete environment for a cron job or startup > > script is to create an 'at' job that runs what I want, then find the file in > > /var/spool/atjobs (for Linux), and copy it where I need it. (Don't forget to > > remove the atjob, since you probably don't actually want it to run.) > > > > Since 'at' captures the complete environment, the file (script, actually) > > will have everything you need in it. > > > > Paul > > > This looks like it would do the trick.. However this cron job will be > running on other os' then Linux.. > (Should work on pretty much any OS that has 'at' and 'cron'--you just have to find the directory that 'at' uses. > I ended up just dumping the commands into a sh script and having cron call > it. It's not the way I think it would run best, but It's probally less > work to do it this way in the long run.. > If you need any sort of an environment for a cron job, you just about have to run a shell script--although you *can* feed variables to a program with a little-known syntax: var1=value1 var2=value2 /file/or/script Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Can run through perl, but not alone?
11:28am, KEVIN ZEMBOWER wrote: > Yep, Rob, you're right on the money: > centernet:/usr/local/httpd/htdocs/cacti8/scripts # head -1 webhits.pl > weatherbug.pl|hexdump -c > 000 = = > w e b h i t s . p l < > 010 = = \n # ! / u s r / l o c a l / > 020 b i n / p e r l \r \n \n = = > w > 030 e a t h e r b u g . p l < = = > 040 \n # ! / u s r / l o c a l / b i > 050 n / p e r l \n > 058 This is more of a Unix trick than Perl, but worth mentioning (I guess): An(other) easy way to check for normally unprintable characters is to "send your cat to the vet". cat -vet weatherbug.pl -v show most non-printing characters -e show end-of-line characters -t show tabs as ^I Paul Archer Sun Solaris instructor and all-around geek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: our vs my
Actually, while we're on the subject: can anyone *really* explain the difference between the two, or perhaps more importantly, when someone would want to use 'our' over 'my'? I've read the docs, but they're not sinking in. TIA, Paul 2:53pm, Dan Muey wrote: > Anybody know what version of Perl our was introduced? > > I'm using our in a module and want like to use 5.6.0; or whatever version in that > module so that I can make sure the our's aren't a problem. > > Perhaps it'd be better to use my $var = ''; and then export the variable on request > instead, > that way it will work with 5.005_03. > > Anybody see any problems with using my instead of our for variables used in a module > and exported on request? > > TIA > > Dan > -- Q: What is the definition of a tachyon? A: It's a gluon that's not completely dry. -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Global variables and a forked process
Yesterday, Wiggins d'Anconia wrote: > Yes and no. There are multiple different implementations of threads all > of which have some good and bad points. You will need to look more into > them depending on your version of Perl and how complex the task is that > you wish to accomplish. (There is also a separate mailing list for perl > threading). > Do you know where this mailing list can be found? I didn't see it on the "list of lists" (pardon the pun) at perl.org... Paul Never ascribe to malice what can perfectly well be explained by stupidity. -Anonymous -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
pronunciation guide
Does anyone know of a pronunciation guide for the special variables and such in Perl? I came up empty on Google. I've been learning Perl by reading and doing, but I haven't talked to anyone face-to-face, so I'm not sure, for example, if $_ is spoken "dollar-underscore", or if people typically say something else--like "<=>" is a "spaceship", or "#!" is a "shebang". Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: pronunciation guide
4:53pm, Paul Johnson wrote: > Paul Kraus said: > > > Wow. I find that unusual in my 10 years of computer use/programming ... > > I have always referred to $ and heard it referred to as "string". > > > > Not that it matters but I find that definitely unusual :) > > Do you have a background in BASIC? I think that in the UK at least it is > (was ?) common to refer to the $ in A$, for example, as "string" since > that is what it was, and it obviously had nothing to do with dollars. > > But as far as Perl is concerned it is "dollar", and I am not aware of any > exceptions. > > Now, as to whether $! is dollar-bang, dollar-pling, > dollar-exclamation-mark or anything else is not so easy. > I thought it was a "bang for your buck"... > You might find this link interesting: > > http://www.eeng.brad.ac.uk/help/.faq/.unix/.pronun.html > Good link, thanks. > But people, # is not a pound! ;-) > Of course not, it's an octothorpe. Everyone knows that. Paul PS. What's with the Pauls here? Are Pauls particularly passionate about Perl, or primarily pronunciation? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pronunciation guide
8:58am, Randal L. Schwartz wrote: > >>>>> "Arthaey" == Arthaey Angosii <[EMAIL PROTECTED]> writes: > > Arthaey> I have heard <=> as "spaceship" and <> as the "diamond" operator. > > Larry's daughter Heidi came up with "diamond". And I'm the culprit > responsible for "spaceship". > > -- And we (I, anyway) thank you. I got a good laugh out of that today when I told my class that's what it was called--"no, really, that's it's name..." Paul Archer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
exists and defined--not just for hashes anymore
Just a quick tip, which the docs mention that 'exists' and 'defined' will let you know if a particular element of a hash exists, or is defined, they work on arrays just as well. (I didn't know that, but a student today asked, so I tried it out.) Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
reverse range (10..1)
Is there any (quick and easy) way to get a reverse range, like (10..1), rather than a standard (1..10)? The catch is to *not* use 'reverse'. I'm teaching Sun's perl course this week (DTP-250), and we were talking about working on arrays. The book had an exercise that had the student reverse an array by using pop (or shift, I don't remember). That section is before we talk about 'reverse', and I thought you'd be able to do it like: @array[0 .. $#array] = @array[$#array .. 0] ...but of course, having the range count down doesn't work. Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: reverse range (10..1)
4:09pm, Ramprasad A Padmanabhan wrote: > Paul Archer wrote: > > Is there any (quick and easy) way to get a reverse range, like (10..1), > > rather than a standard (1..10)? The catch is to *not* use 'reverse'. > > I'm teaching Sun's perl course this week (DTP-250), and we were talking > > about working on arrays. The book had an exercise that had the student > > reverse an array by using pop (or shift, I don't remember). That section is > > before we talk about 'reverse', and I thought you'd be able to do it like: > > @array[0 .. $#array] = @array[$#array .. 0] > > ...but of course, having the range count down doesn't work. > > > > Paul > > IMHO this list is not for solving puzzles or doing school homework , It > is for people learning perl who are getting stuck due to pure perl problems > If I wanted a range (10..1) I will use reverse and why not. If you have > a better way tell me so that I can learn it > Actually, the description for this mailing list says "A list for beginning Perl programmers to ask questions in a *friendly atmosphere*." (emphasis added) I don't see anything about "No schoolwork", or "No puzzles"... And the problem is not simply a puzzle, nor is it homework. If you had read my post more carefully, you would see that I am 1) *teaching* the class, and 2) want to be able to show off one concept (the range operator) before we have talked about another concept (the 'reverse' statement). IM"H"O, if you want to be on a list that is "...for people learning perl who are getting stuck due to pure perl problems..." then start one. I, on the other hand, am staying here. Paul -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: reverse range (10..1)
*Vey* cool examples--especially the 'map' in the first one. Thanks! Paul 7:26am, Todd W. wrote: > > "Paul Archer" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Is there any (quick and easy) way to get a reverse range, like (10..1), > > rather than a standard (1..10)? The catch is to *not* use 'reverse'. > > I'm teaching Sun's perl course this week (DTP-250), and we were talking > > about working on arrays. The book had an exercise that had the student > > reverse an array by using pop (or shift, I don't remember). That section > is > > before we talk about 'reverse', and I thought you'd be able to do it like: > > @array[0 .. $#array] = @array[$#array .. 0] > > ...but of course, having the range count down doesn't work. > > > > Paul > > Reverse an array without using reverse(): > > with an array slice and map(): > [EMAIL PROTECTED] trwww]$ perl > @array = ( 1 .. 5 ); > @array = @array[ map abs(), -$#array .. 0 ]; > print( join("\n", @array), "\n" ); > Ctrl-D > 5 > 4 > 3 > 2 > 1 > > using splice(), pop(), and for(): > [EMAIL PROTECTED] trwww]$ perl > @array = ( 1 .. 5 ); > splice( @array, $_, 0, pop @array ) for ( 0 .. $#array ); > print( join("\n", @array), "\n" ); > Ctrl-D > 5 > 4 > 3 > 2 > 1 > > or the C way (but skipping the temporary variable): > [EMAIL PROTECTED] perl]$ perl > @array = ( 1 .. 5 ); > for ( $a = 0, $z = $#array; $a < $z; $a++, $z-- ) { > ( $array[$a], $array[$z] ) = ( $array[$z], $array[$a] ); > # @array[ $a, $z ] = @array[ $z, $a ]; # works too > } > print( join("\n", @array), "\n" ); > Ctrl-D > 5 > 4 > 3 > 2 > 1 > > perl is s cool. > > Todd W. > > > -- "I'll say this about Linux: it's the first time I've seen Unix on the right platform."--Steve Ballmer, president of Microsoft (NB: Microsoft used to own SCO, which did, and still does, produce a Unix for the Intel platform.) -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
character checking
I've got a module that displays to an LCD display (text-based). The module can also echo what is on the LCD to the screen. But I'm having a slight problem in that a couple of the characters going to the LCD (and being echoed to the screen) are unprintable, depending on the terminal type in use. So...does anyone know a way to tell if a particular character will be printable for a particular terminal type (so I can substitute it if I can't)? TIA, Paul Archer Never ascribe to malice what can perfectly well be explained by stupidity. -Anonymous -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]