Perl - Can't use string ("html") as an ARRAY ref while "strict refs"
The below snippet works fine until I use strict. Then it dies with the following error:
Quote:
Quote:
|
If I understand what I'm looking at (and I'm not sure I do), you want to create an array of files for each extension. Since the module produces an array reference, you can easily put each of those into an array and have an array of arrays. Each array reference in the main array will have a list with all the files found with that extension. This should do what you want:
Code:
#!/usr/bin/perl Code:
Enter path: /home/telemachus/test |
Thanks Telemachos.
That is the jist of what I wanted.... tho I was trying to make the lists / arrays separate. Can anyone tell me why what I was doing fails only when using strict? |
Quote:
See these two links: http://perldoc.perl.org/strict.html http://perldoc.perl.org/perlref.html...lic-references You can actually do this in Perl (use a variable as a variable name), but it's a terrible idea. See here: http://perl.plover.com/varvarname.html |
Quote:
Code:
#!/usr/bin/env perl |
Quote:
Quote:
Quote:
|
My best solution if I must use variables with symbolic references may be this I guess... ?
Quote:
|
Quote:
Quote:
Let me take your example for one more spin. You say that you will use STDIN to gather a list of extensions and then you want to populate arrays containing files ending in those extensions. My first thought is a hash of arrays. What I would do is take the items given on STDIN and make those hash keys. The value of each of those would be an anonymous array reference. That way, I could refer to precisely which extension I wanted, whenever I wanted, because the hash key allows specific lookup. Here's a short implementation, reusing my File::Find code from above. Code:
#!/usr/bin/env perl Code:
telemachus ~ $ perl file_list |
To OP - believe me (after 15+ years of experience with Perl) - you practically never need variables with dynamically created variable names, since you can always write
Code:
my %vars_with_dynamic_names; even more practically never you need to work without Code:
use strict; In simple English - if your code doesn't work with Code:
use strict; |
Quote:
--- rod. |
All times are GMT -5. The time now is 05:44 PM. |