|
Prev: FAQ 4.44 How do I test whether two arrays or hashes are equal?
Next: FAQ 5.3 How do I count the number of lines in a file?
From: J�rgen Exner on 23 Apr 2008 22:09 "Gerry Ford" <gerry(a)nowhere.ford> wrote: [...] >my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next}; [...] >I'm still confused on the whole }; thing. There is no }; thing. Understanding this is your problem. There are 'blocks' that are enclosed in curly braces {.....}. Period. And then there are statements. Individual statements are separated by a ; in Perl, i.e. between any two statements you have to write a ;. In your original progam you had [reformatted to make it more obvious] open(FILE, "<$killrc") and do {SomeVeryLongWhatever} print @filter; What you meant was open(FILE, "<$killrc") and do {SomeVeryLongWhatever}; print @filter; If you want print() to be a new statement, then you have to place a semicolon between the preceeding statement and the print(). If you don't then you will get that syntax error because perl had to assume that you are continuing the preceeding statement. After all, it could have been that you wanted to add 5 to the result of do, something like do {SomeVeryLongWhatever} + 5; which is perfectly legal. The only way for perl to know that a new statement is starting is if you put that semicolon there. >With this version, I've eliminated the the do{}; No, you haven't. See the one line of code I quoted above. > If I put a semicolon after the foreach close curly >brace, I get no change in behavior in the program. ?? That's just a surplus empty statement. Perl doesn't care if you create a dozen or a million. jue
From: Uri Guttman on 23 Apr 2008 23:30 >>>>> "GF" == Gerry Ford <gerry(a)nowhere.ford> writes: GF> "Uri Guttman" <uri(a)stemsystems.com> wrote in message GF> news:x7bq42v97j.fsf(a)mail.sysarch.com... >>>>>>> "GF" == Gerry Ford <gerry(a)nowhere.ford> writes: >> GF> my $killrc = "sample.killrc"; GF> sub read_killrc { GF> return unless open(my $file, "<$killrc") ; GF> return map { GF> /^([^#]+)#?$/ && GF> eval{ qr/$1/} || prompt $@, () GF> } <$file> ; GF> } some formatting/indenting will help there. GF> read_killrc; great! you just tossed away the results of the call. GF> So, how do I adapt this now to take advantage of the return values of map? GF> I no longer have the option of writing GF> print @filter; do you think print only takes an array? what does the above sub return? A LIST generated by the map. so print it! you can print ANY expression or list of expressions. print read_killrc() ; was that so hard? even with the flu you should have gotten that! GF> # perl mats5.pl 2>text50.txt >text51.txt >> why the redirect of stderr? there is no stderr output. and what is in >> the prompt sub? GF> # perl mats7.pl 2>text50.txt >text51.txt GF> This statement is what I call "the goocher." It keeps track of what version GF> I'm running and has a means to redirect stdout and stderr. I should GF> capitalize those. I copy and paste these into the command line. that still makes no sense. the script (or at least the code you have shown) doesn't print to STDERR. GF> What kind of name is Uri? my kind. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: A. Sinan Unur on 24 Apr 2008 00:15 >>>>>> "GF" == Gerry Ford <gerry(a)nowhere.ford> writes: I find this constant changing of posting ids pretty annoying. Please decide if you are Wade Ward or zaxfux or whatever it is and stick with it. In any case, you have been re-added to my killfile under this new identity and I cannot believe I have been fooled into responding to your question. > GF> What kind of name is Uri? What is the point of picking on other people's names when you can't even decide what your own name is? Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://www.rehabitation.com/clpmisc/
From: Jim Cochrane on 24 Apr 2008 01:24 On 2008-04-23, Uri Guttman <uri(a)stemsystems.com> wrote: >>>>>> "JC" == Jim Cochrane <allergic-to-spam(a)no-spam-allowed.org> writes: > > >> do you know which braces need a semicolon after? > > JC> If I remember correctly, line 18 (from your error message) was either > JC> the offending line with the close curly brace missing the ';' or the > JC> line (print ...) below it. So you know where to look because of the > JC> line # in the error message. Of course, now that you know that 'do {}' > JC> blocks need a semicolon after them (right?), you know to look for that > > actually do blocks are just expressions and the statement they might be > in will need a ; (and of course in perl ; is a statement separator and > not a terminator). in this case the do block was the end of the > statement and needed a ; before the print. an if block (or other flow > control block isn't a statement so they don't need ; after them. > > uri > Thanks for the clarification. --
From: Jim Cochrane on 24 Apr 2008 01:29
On 2008-04-24, J�rgen Exner <jurgenex(a)hotmail.com> wrote: > "Gerry Ford" <gerry(a)nowhere.ford> wrote: > [...] >>my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next}; > [...] > >>I'm still confused on the whole }; thing. > > [good explanation deleted] Also, see Uri Guttman's response to my post for further elaboration (and correction to my somewhat misleading statement that you need a semicolon after a do {} block). -- |