Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Hi Shachar, First you can always use Data::Dumper: use Data::Dumper; print Dumper($ref); To make sure that the data is stored correctly. In regard to your question: my $ref; my %hash = %{$ref}; foreach my $ptrelem (keys %hash) { my @array = @{$ptrelem}; foreach my $item (@array) { print

Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Sorry a mistake... foreach my $ptrelem (keys %hash) { Should be foreach my $key (keys %hash) { my $ptritem = %hash-{$key}; On Sat, Oct 24, 2009 at 7:55 PM, Noam Rathaus no...@beyondsecurity.com wrote: Hi Shachar, First you can always use Data::Dumper: use Data::Dumper; print

Re: Perl question: array member of referenced hash

2009-10-24 Thread Dov Grobgeld
Noam beat me to it, but here's perl solution without additional variables: #!/usr/bin/perl %hash = (a=['moo','goo','woo'], foo=3, baz=5); $ref = \%hash; foreach my $elem (@{$ref-{a}}) { print $elem\n; } Regards, Dov 2009/10/24 Shachar Shemesh shac...@shemesh.biz Hi

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Dov Grobgeld wrote: Noam beat me to it, but here's perl solution without additional variables: #!/usr/bin/perl %hash = (a=['moo','goo','woo'], foo=3, baz=5); $ref = \%hash; foreach my $elem (@{$ref-{a}}) Hi Dov, Yes, it works. Now can you, please, explain to me why? What

Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Shachar, { } in Perl are casting when they surround a value And the second set of { } around the 'a' mean variable of Hash 2009/10/24 Shachar Shemesh shac...@shemesh.biz: Dov Grobgeld wrote: Noam beat me to it, but here's perl solution without additional variables: #!/usr/bin/perl %hash

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Noam Rathaus wrote: Shachar, { } in Perl are casting when they surround a value And the second set of { } around the 'a' mean variable of Hash Grumble grumble grumble Okay, I'm sorry for being difficult. I really couldn't find the answer in the Perl documentation. I understand the

Re: Perl question: array member of referenced hash

2009-10-24 Thread Gabor Szabo
2009/10/24 Shachar Shemesh shac...@shemesh.biz: Noam Rathaus wrote: Shachar, { } in Perl are casting when they surround a value And the second set of { } around the 'a' mean variable of Hash Grumble grumble grumble not surprised as this is one of the funky places of Perl 5.

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Gabor Szabo wrote: err, I don't think that casting is the right word to use here. What {} does here is disambiguates the expression. Let me try to summarize what I understood from your excellent explanation: Putting a modifier in front of a reference dereference it to the right type ($ for

Re: Perl question: array member of referenced hash

2009-10-24 Thread Gabor Szabo
On Sat, Oct 24, 2009 at 11:25 PM, Shachar Shemesh shac...@shemesh.biz wrote: Let me try to summarize what I understood from your excellent explanation: if that works for you :-) All that is left is understanding why the round braces around the whole expression. Oh, the syntax of foreach

Re: Perl question

2004-04-10 Thread Gabor Szabo
On Fri, 9 Apr 2004, Shachar Shemesh wrote: Suppose I wanted to write this myself, how would I go about doing it? Is there any way of recursively using a dir or file handle name? Probably you got the anwer from the responses of others already, in any case you can use constructs such as theses

Re: Perl question

2004-04-09 Thread Shachar Shemesh
Shachar Shemesh wrote: if( (($state[2] ~)12) ==4 ) { # A directory - recurse That's 0 of course, or even remove altogether and just leave the 12 part. Same problem remains, however. -- Shachar Shemesh Lingnu OpenSource Consulting http://www.lingnu.com/

Re: Perl question

2004-04-09 Thread Muli Ben-Yehuda
On Fri, Apr 09, 2004 at 10:54:04AM +0300, Shachar Shemesh wrote: 1. I know, I write perl like a C programmer, I can't help it. Feel free to show me how it's done. Not a perl guru by any stretch of the imagination, but behold my google foo! #!/usr/bin/perl @ARGV = qw(.) unless @ARGV; use

Re: Perl question

2004-04-09 Thread Shlomi Fish
On Friday 09 April 2004 10:54, you wrote: Hi, I'm trying to create a perl program that will recurse into subdirectories. I have: sub scandir { local $dirname=shift; You should use my $dirname = shift; instead of local here. It's safer. opendir DIR, $dirname or die Couldn't

Re: Perl question

2004-04-09 Thread Oron Peled
On Friday 09 April 2004 11:27, Muli Ben-Yehuda wrote: 3. What the @$([EMAIL PROTECTED] is the difference between my and local? Which one should I use here? http://prometheus.frii.com/~gnat/yapc/2000-stages/slide21.html I didn't like so much the dumbed down type of explatanion in this

Re: Perl question

2004-04-09 Thread Gabor Szabo
On Fri, 9 Apr 2004, Shachar Shemesh wrote: 1. I know, I write perl like a C programmer, I can't help it. Feel free to show me how it's done. Probably you should use File::Find Try this code as a starter: use File::Find; $dirname = shift @ARGV; find(\myfunc, $dirname); sub myfunc { printf

Re: Perl question

2004-04-09 Thread Shachar Shemesh
Gabor Szabo wrote: On Fri, 9 Apr 2004, Shachar Shemesh wrote: 1. I know, I write perl like a C programmer, I can't help it. Feel free to show me how it's done. Probably you should use File::Find Try this code as a starter: use File::Find; $dirname = shift @ARGV; find(\myfunc, $dirname);

Re: Perl question

2004-04-09 Thread Shachar Shemesh
Ok, thanks everyone. ONYAWIRNWSTG (Oh No, Yet Anohter, Was It Really Neccessary, WebSite from Template Generator) is now ready thanks to your help. Yes, it seems I too rewrote my own tool, despite having other tools to rely on. Nothing was an exact match to what I was looking for. In case

Re: perl question

2002-10-08 Thread Tzafrir Cohen
On Sun, 6 Oct 2002, Arie Folger wrote: This is useful for creating localizable error messages that contain runtime information. On C (and actually, on PHP) gettext is used for this task. Isn't there a ready gettext (or equivalent) module on perl? Perl actually has quite a few

Re: perl question

2002-10-07 Thread herouth
Quoting guy keren [EMAIL PROTECTED]: you can also use 'eval' - if the text contains valid perl code. Even if it doesn't. You can get the text into a string $string1, then do something like: $string2 = \$string3 = \$string1\; eval($string2) and the result will be in $string3. Escape any

Re: perl question

2002-10-07 Thread Shlomi Fish
On Mon, 7 Oct 2002 [EMAIL PROTECTED] wrote: Quoting guy keren [EMAIL PROTECTED]: you can also use 'eval' - if the text contains valid perl code. Even if it doesn't. You can get the text into a string $string1, then do something like: $string2 = \$string3 = \$string1\; eval($string2)