On Tuesday, August 12, 2003, at 03:35 PM, Trina Espinoza wrote:

Hi James,

Hello again.


In the future, I recommend copying the list in replies. That will help you get your problem solved by all the people smarter than me. ;)

Sorry to be back so soon with questions. . .

No problem, that's what we're here for.


I wanted to say thank you for responding to my previous mail.

Sure thing.


The adding brackets to $shot_OTIS{#shot} =[ ]; works great. The issue I am having now is that it returns:
 
 
ARRAY(0x10151310)
ARRAY(0x1015204c)
ARRAY(0x10149b10)
ARRAY(0x10152100)
ARRAY(0x101512b0)
ARRAY(0x1014f094)
ARRAY(0x10150328)
ARRAY(0x10152148)

Ugly, isn't is? Okay, we now have to wash your computer's mouth out with soap. Ready? :D


What I was expecting to receive is my data. I am assuming thay my inability to understand this comes from not really understanding references

I assume that too. References take some getting use to, but they are the key to Perl's complex data structures. Let's see if we can figure this stuff out.


Hashes (and arrays too, while we're on the subject) can only contain scalar values. That's easy enough to understand. You wanted to to put in a list of values though. We need an array for that and I just said that was against the rules. So what we really need is an array disguised as a scalar. That's a pretty good way to think about what an array reference is, I think.

It's a scalar value, that points to an array we have hidden away somewhere in computer land. Since it's a scalar, we can put it in a hash (or another array). With that scalar, we can get to our array, if we ask Perl nicely.

That's the trick though, you forgot to say please... er, I mean, you forgot to ask. Instead, you're printing straight references which, as you can see, come out as a type (handy) and a memory address (not so handy, save that it's a unique identifier). That leaves you two choices, you can open up your box and hunt for the little chip with the right number on the back of it (Kidding: Don't do this!) or you can ask Perl to find it for you. Let's try the easy road... :)

outside of subroutines. How to I fix this so I get data as my values and not array locations? Here is more of my code. I have left out some of the code,
but hopefully this will be enough for you to determine what I am doing.

Let's take a look:


----------------------------------------------------------------------- ----------------
#!/usr/bin/perl -w
#use strict;
 
#my %shots_OTIS =(); #Commented this out b/c I didn't know how to declare it.

Okay, let's uncomment these back in. There's nothing wrong with either line. You can even drop the = (), since an empty hash is what we get by default.


my @sequenceDirs;
my $editDir ="//xena/XX/RTM/Archive";

Hopefully this is where you left some code out, since, @sequenceDirs still loops empty to me.


foreach (@sequenceDirs) {
 my $path= join("/",$editDir, $_);

Or just:


my $path = "$editDir/$_";

Checkout perldoc File::Spec::Functions, if you want a cross platform way to do this (hint: catfile()).

 print "$path\n";
 opendir PATH, $path;
 my @movies = readdir PATH; #if prob w/data, check this.

How about we remove dot files right here, so you don't have to worry about them in the foreach loop below:


my @movies = grep !/^\./, readdir PATH;

 #Movie Parser
 foreach (@movies) {
  if(/^\./) { #Removes dot files
   next;
  } 

You no longer need this if, if you use my trick above.


  unless (/^.*\.mov/) {
   print "BAD FILENAME: file is skipped";
   next;
  } 
  #Parse Data Here
  my @parts = split("_",$_);
  print "FIRST: @parts\n";
  my $shot = $parts[0];
  my $endShot= $parts[1];
  print "SHOT: $shot\n";
  print "ENDFILE: $endShot\n";

You can shorten this chunk of code up a little, if you like. Replace the split() line with:


my($shot, $endShot) = split /_/, $_;

  unless (exists $shots_OTIS{$shot})  {
   #print "putting shot in array";
   $shots_OTIS{$shot} = [];
  } 

As others have said, you can leave this out and take advantage of autovivification.


  push( @{$shots_OTIS{$shot}}, $endShot);
  
  
 }
 
 
 
}
print  %shots_OTIS;
my @info= values %shots_OTIS;
foreach (@info) {

You can drop the @info array, if you want. foreach (values %shots_OTIS) will work fine.


 print "$_\n";

Here's your problem all the way down here! Try:


print "@$_\n"; # de-reference our references

or

print join('YOUR_SEPARATOR_HERE', @$_), "\n";


Well, I hope that helps some more. Good luck, Trina.


James Gray

Reply via email to