Hi raphael! I believe you meant to CC this to the list, so I'm CCing it (I don't see anything in your reply that needs to be in private).
On Thursday 25 Feb 2010 13:42:07 raphael() wrote: > On Thu, Feb 25, 2010 at 4:50 PM, Shlomi Fish <shlo...@iglu.org.il> wrote: > > Hi Raphael! > > > > On Thursday 25 Feb 2010 12:59:33 raphael() wrote: > >> My BAD :( > >> > >> THERE IS NO FIRST ELEMENT IN A HASH!! > >> > >> PLEASE FORGIVE ME. I AM IN A THICK OF EVERYTHING TODAY. > >> > >> LET ME REPHRASE -- > >> HOW DO I LOOP OVER THE ANONYMOUS HASH WHICH IS INSIDE AN ARRAY? > > > > OK, no need to use all-caps (it's considered akin to shouting in > > > netiquette.). > > > You can use textual *bold* or /italics/ or _underline_ or whatever to > > highlight. > > > > Regarding your question here is an example (tested): > > > > « > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > my @array_of_hashes = > > ( > > > > { > > > > first => "Bart", > > last => "Simpson", > > city => "Springfield", > > > > }, > > { > > > > first => "Sherlock", > > last => "Holmes", > > city => "London", > > > > }, > > { > > > > first => "Socrates", > > last => "None", > > city => "Athens", > > > > }, > > > > ); > > > > foreach my $record (@array_of_hashes) > > { > > > > foreach my $key (keys(%$record)) > > { > > > > my $value = $record->{$key}; > > print "$key ==> $value\n"; > > > > } > > > > } > > » > > > > No shouting :) a ok > Thank you for your prompt replies. You're welcome. > > Your example is very similar to mine. > How would I add an another key to second anon hash (holmes one)? Add the line: <<< profession => "Detective", >>> Somewhere Inside the {...} curly braces lines of the anonymous hash. > > --------- > A quick one? > Is there a GUI Builder for Perl that you would recommend for my 'first' gui > app in perl. Well, first you need to pick up a GUI toolkit: * http://www.shlomifish.org/open-source/portability-libs/#gui * http://perl-begin.org/uses/GUI/ Then you can pick a GUI Builder for that. Gtk+ has glade, and WxWidgets has wxGlade and there are many others. > > --------- > One more -- regex vs substr? which is more efficient? > > next unless ( substr( "$line", 0, 4) eq 'http' ); OR > > next unless ("$line" =~ m/^http/o ); 1. "Benchmark it and see": http://search.cpan.org/perldoc?Benchmark 2. You probably want «$line» instead of «"$line"» in both cases, unless it is the rare case that $line is a blessed object reference with an overloaded stringification operator and not a simple scalar variable that contains a string value. (Though in this context, it may be stringified by Perl anyhow.) 3. In this case I believe the gains from doing it this way or the other will be very minimal and are not worth it. 4. You should probably use "\A" (start-of-string) instead of "^" (start-of- string or start-of-line depending on the flags at the end) inside the regex for clarity. 5. "Premature optimisation is the root of all Evil" (Tony Hoare via Don Knuth). Are you sure that is where your code's bottleneck is? Have you profiled it to determine that most of the time is spent in that line? Is your code too slow to begin with? Or are you optimising prematurely? Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ First stop for Perl beginners - http://perl-begin.org/ Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/